Module: ActiveRecord::ConnectionAdapters::SnowflakeOdbc::DatabaseStatements
- Defined in:
- lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
- #bind_params(binds, sql) ⇒ Object
-
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
-
#exec_delete(sql, name, binds) ⇒ Object
Executes delete
sql
statement in the context of this connection usingbinds
as the bind substitutes. -
#exec_rollback_db_transaction ⇒ Object
Rolls back the transaction (and turns on auto-committing).
-
#execute(sql, name = nil, binds = []) ⇒ Object
Executes the SQL statement in the context of this connection.
-
#internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) ⇒ Object
:nodoc:.
- #prepared_binds(binds) ⇒ Object
-
#prepared_statements ⇒ Object
Have to because of create table.
Instance Method Details
#begin_db_transaction ⇒ Object
Begins the transaction (and turns off auto-committing).
28 29 30 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 28 def begin_db_transaction @raw_connection.autocommit = false end |
#bind_params(binds, sql) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 69 def bind_params(binds, sql) prepared_binds = *prepared_binds(binds) prepared_binds.each.with_index(1) do |val, ind| sql = sql.gsub("$#{ind}", "'#{val}'") end sql end |
#commit_db_transaction ⇒ Object
Commits the transaction (and turns on auto-committing).
33 34 35 36 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 33 def commit_db_transaction @raw_connection.commit @raw_connection.autocommit = true end |
#exec_delete(sql, name, binds) ⇒ Object
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.
23 24 25 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 23 def exec_delete(sql, name, binds) execute(sql, name, binds) end |
#exec_rollback_db_transaction ⇒ Object
Rolls back the transaction (and turns on auto-committing). Must be done if the transaction block raises an exception or returns false.
40 41 42 43 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 40 def exec_rollback_db_transaction @raw_connection.rollback @raw_connection.autocommit = true end |
#execute(sql, name = nil, binds = []) ⇒ Object
Executes the SQL statement in the context of this connection. Returns the number of rows affected.
12 13 14 15 16 17 18 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 12 def execute(sql, name = nil, binds = []) log(sql, name, binds) do |notification_payload| rc = @raw_connection.do(sql, *binds.map { |bind| prepare_bind(bind).to_s }) notification_payload[:row_count] = rc rc end end |
#internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) ⇒ Object
:nodoc:
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 45 def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) # :nodoc: log(sql, name, binds) do |notification_payload| if prepare || binds.any? # TODO: refacto stmt = @raw_connection.prepare(sql) binds.each_with_index do |bind, i| if bind.respond_to?("value_for_database") && bind.value.is_a?(Integer) || bind.is_a?(Integer) stmt.param_type(i, ODBC::SQL_INTEGER) end end stmt.execute(*binds.map { |bind| prepare_bind(bind).to_s }) else stmt = @raw_connection.run(sql) end columns = stmt.columns values = stmt.to_a stmt.drop notification_payload[:row_count] = values.count values = values&.map { |row| row&.map { |value| _type_cast_value(value) } } column_names = columns.keys.map { |key| format_case(key) } ActiveRecord::Result.new(column_names, values) end end |
#prepared_binds(binds) ⇒ Object
77 78 79 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 77 def prepared_binds(binds) binds.map(&:value_for_database) end |
#prepared_statements ⇒ Object
Have to because of create table
6 7 8 |
# File 'lib/active_record/connection_adapters/snowflake_odbc/database_statements.rb', line 6 def prepared_statements true end |