Module: ActiveRecord::ConnectionAdapters::Hanaclient::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::HanaclientAdapter
- Defined in:
- lib/active_record/connection_adapters/hanaclient/database_statements.rb
Instance Method Summary collapse
- #commit_db_transaction ⇒ Object
- #default_sequence_name(table, column) ⇒ Object
-
#empty_insert_statement_value ⇒ Object
This is not supported.
-
#exec_delete(sql, name = nil, binds = []) ⇒ Object
(also: #exec_update)
Executes delete
sqlstatement in the context of this connection usingbindsas the bind substitutes. - #exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil) ⇒ Object
-
#exec_query(sql, name = "SQL", binds = [], prepare: false) ⇒ Object
Executes
sqlstatement in the context of this connection usingbindsas the bind substitutes. - #exec_rollback_db_transaction ⇒ Object
-
#execute(sql, name = nil) ⇒ Object
Executes the SQL statement in the context of this connection and returns the raw result from the connection adapter.
- #insert_fixtures(fixtures, table_name) ⇒ Object
- #insert_fixtures_set(fixture_set, tables_to_delete = []) ⇒ Object
-
#reset_transaction ⇒ Object
:nodoc:.
-
#truncate(table_name, name = nil) ⇒ Object
Executes the truncate statement.
Instance Method Details
#commit_db_transaction ⇒ Object
76 77 78 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 76 def commit_db_transaction() HA.instance.api.hanaclient_commit(@connection) end |
#default_sequence_name(table, column) ⇒ Object
84 85 86 87 88 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 84 def default_sequence_name(table, column) query_value(<<-end_sql, "SCHEMA") SELECT SEQUENCE_NAME FROM SEQUENCES WHERE SEQUENCE_NAME like ('%' || (SELECT column_id from table_columns where table_name = #{quote(table.gsub('"', ''))} AND column_name = #{quote(column.gsub('"', ''))}) || '%') end_sql end |
#empty_insert_statement_value ⇒ Object
This is not supported. Can’t insert an empty column
109 110 111 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 109 def empty_insert_statement_value raise NotImplementedError end |
#exec_delete(sql, name = nil, binds = []) ⇒ Object Also known as: exec_update
Executes delete sql statement in the context of this connection using binds as the bind substitutes. name is logged along with the executed sql statement.
65 66 67 68 69 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 65 def exec_delete(sql, name = nil, binds = []) exec_and_clear(sql, name, binds) do |stmt| HA.instance.api.hanaclient_affected_rows(stmt) end end |
#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 48 def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil) result = exec_query(sql, name, binds) unless sequence_name table_ref = extract_table_ref_from_insert_sql(sql) if table_ref pk = primary_key(table_ref) if pk.nil? pk = suppress_composite_primary_key(pk) sequence_name = default_sequence_name(table_ref, pk) end return result unless sequence_name end last_insert_id_result(sequence_name) end |
#exec_query(sql, name = "SQL", binds = [], prepare: false) ⇒ Object
Executes sql statement in the context of this connection using binds as the bind substitutes. name is logged along with the executed sql statement.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 19 def exec_query(sql, name = "SQL", binds = [], prepare: false) exec_and_clear(sql, name, binds, prepare: prepare) do |stmt| record = [] columns = [] max_cols = HA.instance.api.hanaclient_num_cols(stmt) if( max_cols > 0 ) columns = max_cols.times.collect{ |x| HA.instance.api.hanaclient_get_column_info(stmt, x)[2] } while HA.instance.api.hanaclient_fetch_next(stmt) == 1 result = [] max_cols.times do |cols| result << HA.instance.api.hanaclient_get_column(stmt, cols)[1] end record << result end end ActiveRecord::Result.new(columns, record) end end |
#exec_rollback_db_transaction ⇒ Object
80 81 82 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 80 def exec_rollback_db_transaction() HA.instance.api.hanaclient_rollback(@connection) end |
#execute(sql, name = nil) ⇒ Object
Executes the SQL statement in the context of this connection and returns the raw result from the connection adapter.
7 8 9 10 11 12 13 14 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 7 def execute(sql, name = nil) log(sql, name) do if HA.instance.api.hanaclient_execute_immediate(@connection, sql) == 0 result, errstr = HA.instance.api.hanaclient_error(@connection) raise ActiveRecord::StatementInvalid.new(errstr) end end end |
#insert_fixtures(fixtures, table_name) ⇒ Object
90 91 92 93 94 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 90 def insert_fixtures(fixtures, table_name) fixtures.each do |fixture| insert_fixture(fixture, table_name) end end |
#insert_fixtures_set(fixture_set, tables_to_delete = []) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 96 def insert_fixtures_set(fixture_set, tables_to_delete = []) disable_referential_integrity do transaction(requires_new: true) do tables_to_delete.each { |table| delete "DELETE FROM #{quote_table_name(table)}", "Fixture Delete" } fixture_set.each do |table_name, rows| rows.each { |row| insert_fixture(row, table_name) } end end end end |
#reset_transaction ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 72 def reset_transaction #:nodoc: @transaction_manager = ConnectionAdapters::Hanaclient::TransactionManager.new(self) end |
#truncate(table_name, name = nil) ⇒ Object
Executes the truncate statement.
44 45 46 |
# File 'lib/active_record/connection_adapters/hanaclient/database_statements.rb', line 44 def truncate(table_name, name = nil) exec_query("TRUNCATE TABLE #{quote_table_name(table_name)}", name) end |