# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 163 def primary_keys(table_name) raise ArgumentError unless table_name.present? scope = quoted_scope(table_name) column_names = query_values(<<-SQL.strip_heredoc, "SCHEMA") SELECT COLUMN_NAME FROM SYS.INDEX_COLUMNS WHERE CONSTRAINT = 'PRIMARY KEY' AND SCHEMA_NAME = #{scope[:schema]} AND TABLE_NAME = #{scope[:name]} ORDER BY POSITION SQL column_names.map{|name| name} end
class ActiveRecord::ConnectionAdapters::HanaclientAdapter
Constants
- ADAPTER_NAME
- NATIVE_DATABASE_TYPES
Supports all standard activerecord types and unicode
Public Instance Methods
active?()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 120 def active? result = HA.instance.api.hanaclient_execute_immediate(@connection, "SELECT 1 FROM DUMMY") == 1 end
arel_visitor()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 101 def arel_visitor Arel::Visitors::Hanaclient.new(self) end
clear_cache!()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 143 def clear_cache! @statements.clear end
connect!()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 124 def connect! result = HA.instance.api.hanaclient_connect(@connection, @connection_string) unless result == 1 result, error = HA.instance.api.hanaclient_error(@connection) raise ActiveRecord::StatementInvalid.new(error) end end
disconnect!()
click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 138 def disconnect! super HA.instance.api.hanaclient_disconnect( @connection ) end
native_database_types()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 147 def native_database_types NATIVE_DATABASE_TYPES end
new_column_from_field(table_name, field)
click to toggle source
Creates a new column object given a hanaclient response statement (field)
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 152 def new_column_from_field(table_name, field) name = field[3] default = field[11] sql_type_metadata = fetch_type_metadata(field[6]) nullable = field[10] == "TRUE" table_name = field[1] collation = field[12] Hanaclient::Column.new(name, default, sql_type_metadata, nullable, table_name, nil, collation, comment: nil) end
primary_keys(table_name)
click to toggle source
Returns the primary keys of a given table
reconnect!()
click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 132 def reconnect! super disconnect! connect! end
schema_creation()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 97 def schema_creation Hanaclient::SchemaCreation.new self end
supports_foreign_keys?()
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 116 def supports_foreign_keys? true end
Private Instance Methods
column_definitions(table_name)
click to toggle source
Returns column information for a given table
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 210 def column_definitions(table_name) scope = quoted_scope(table_name) query(<<-end_sql, "SCHEMA") SELECT * FROM SYS.TABLE_COLUMNS WHERE TABLE_NAME = #{scope[:name]} AND SCHEMA_NAME = #{scope[:schema]} ORDER BY POSITION end_sql end
create_table_definition(*args)
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 218 def create_table_definition(*args) Hanaclient::TableDefinition.new(*args) end
exec_and_clear(sql, name = "SQL", binds = [], prepare: false) { |stmt| ... }
click to toggle source
Executes an sql statement and frees the statement
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 232 def exec_and_clear(sql, name = "SQL", binds = [], prepare: false) type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds) do cached = false # Statement caching seems to have issues. Don't use for now # if without_prepared_statement?(binds) stmt = HA.instance.api.hanaclient_prepare(@connection, sql) if stmt.nil? result, errstr = HA.instance.api.hanaclient_error(@connection) raise ActiveRecord::StatementInvalid.new(errstr) end # else # unless @statements.key? sql # @statements[sql] = HA.instance.api.hanaclient_prepare(@connection, sql) # if @statements[sql].nil? # result, errstr = HA.instance.api.hanaclient_error(@connection) # raise ActiveRecord::StatementInvalid.new(errstr) # end # end # stmt = @statements[sql] # cached = true # end num_params = HA.instance.api.hanaclient_num_params(stmt) num_params.times do |i| res, param = HA.instance.api.hanaclient_describe_bind_param(stmt, i) param.set_value(type_casted_binds[i]) HA.instance.api.hanaclient_bind_param(stmt, i, param) end if HA.instance.api.hanaclient_execute(stmt) == 0 result, errstr = HA.instance.api.hanaclient_error(@connection) raise ActiveRecord::StatementInvalid.new(errstr) end ret = yield stmt HA.instance.api.hanaclient_free_stmt(stmt) unless cached ret end end
extract_table_ref_from_insert_sql(sql)
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 222 def extract_table_ref_from_insert_sql(sql) sql[/into\s("[A-Za-z0-9_."\[\]\s]+"|[A-Za-z0-9_."\[\]]+)\s*/im] $1.strip if $1 end
initialize_type_map(m)
click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 181 def initialize_type_map(m) super m.register_type %r(date)i, Type::Date.new m.register_type %r(time)i, Type::Time.new m.register_type %r(seconddate)i, Type::DateTime.new m.register_type %r(timestamp)i, Type::DateTime.new m.register_type %r(bigint)i, Type::Integer.new(limit: 8) m.register_type %r(integer)i, Type::Integer.new(limit: 4) m.register_type %r(smallint)i, Type::Integer.new(limit: 2) m.register_type %r(tinyint)i, Type::UnsignedInteger.new(limit: 1) m.register_type %r(decimal)i, Type::Decimal.new m.register_type %r(real)i, Type::Float.new m.register_type %r(double)i, Type::Float.new m.register_type %r(boolean)i, Type::Boolean.new m.register_type %r(varchar)i, Type::String.new(limit: 5000) m.register_type %r(nvarchar)i, Type::String.new(limit: 5000) m.register_type %r(alphanum)i, Type::String.new(limit: 127) m.register_type %r(varbinary)i, Type::Binary.new(limit: 5000) m.register_type %r(blob)i, Type::Text.new(limit: 2**31 - 1) m.register_type %r(clob)i, Type::Text.new(limit: 2**31 - 1) m.register_type %r(nlob)i, Type::Text.new(limit: 2**31 - 1) end
last_insert_id_result(sequence_name)
click to toggle source
# File lib/active_record/connection_adapters/hanaclient_adapter.rb, line 227 def last_insert_id_result(sequence_name) exec_query("SELECT #{quote_table_name(sequence_name)}.CURRVAL FROM DUMMY", "SQL") end