Module: ActiveRecord::ConnectionAdapters::SQLServer::JDBCOverrides
- Included in:
- ActiveRecord::ConnectionAdapters::SQLServerAdapter
- Defined in:
- lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb
Instance Method Summary collapse
-
#exec_insert(sql, name, binds, pk = nil, _sequence_name = nil) ⇒ Object
Needed to reapply this since the jdbc abstract versions don’t do the check and end up overriding the sqlserver gem’s version.
-
#execute(sql, name = nil) ⇒ Object
Needed to reapply this since the jdbc abstract versions don’t do the check and end up overriding the sqlserver gem’s version.
-
#execute_procedure(proc_name, *variables, &block) ⇒ Object
TODO Move to java for potential perf boost.
-
#explain(arel, binds = []) ⇒ Object
MSSQL does not return query plans for prepared statements, so we have to unprepare them SQLServer gem handles this by overridding exec_explain but that doesn’t correctly unprepare them for our needs.
- #jdbc_connection_class(_spec) ⇒ Object
-
#quoted_date(value) ⇒ Object
Override Since we aren’t passing dates/times around as strings we need to process them here, just making sure they are a string.
- #reset! ⇒ Object
-
#supports_transaction_isolation? ⇒ Boolean
Have to reset this because the default arjdbc functionality is to return false unless a level is passed in.
Instance Method Details
#exec_insert(sql, name, binds, pk = nil, _sequence_name = nil) ⇒ Object
Needed to reapply this since the jdbc abstract versions don’t do the check and end up overriding the sqlserver gem’s version
11 12 13 14 15 16 17 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 11 def exec_insert(sql, name, binds, pk = nil, _sequence_name = nil) if id_insert_table_name = exec_insert_requires_identity?(sql, pk, binds) with_identity_insert_enabled(id_insert_table_name) { super } else super end end |
#execute(sql, name = nil) ⇒ Object
Needed to reapply this since the jdbc abstract versions don’t do the check and end up overriding the sqlserver gem’s version
22 23 24 25 26 27 28 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 22 def execute(sql, name = nil) if id_insert_table_name = query_requires_identity_insert?(sql) with_identity_insert_enabled(id_insert_table_name) { super } else super end end |
#execute_procedure(proc_name, *variables, &block) ⇒ Object
TODO Move to java for potential perf boost
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 31 def execute_procedure(proc_name, *variables, &block) vars = if variables.any? && variables.first.is_a?(Hash) variables.first.map { |k, v| "@#{k} = #{quote(v)}" } else variables.map { |v| quote(v) } end.join(', ') sql = "EXEC #{proc_name} #{vars}".strip log(sql, 'Execute Procedure') do result = @connection.execute(sql) return [] unless result if result.is_a?(Array) result.map! do |res| process_execute_procedure_result(res, &block) end else result = process_execute_procedure_result(result, &block) end result end end |
#explain(arel, binds = []) ⇒ Object
MSSQL does not return query plans for prepared statements, so we have to unprepare them SQLServer gem handles this by overridding exec_explain but that doesn’t correctly unprepare them for our needs
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 58 def explain(arel, binds = []) arel = ActiveRecord::Base.send(:replace_bind_variables, arel, binds.map(&:value_for_database)) sql = to_sql(arel) result = with_showplan_on { execute(sql, 'EXPLAIN') } if result.is_a?(Array) # We got back multiple result sets but the printer expects them to all be in one main_result = result[0] result.each_with_index do |result_obj, i| next if i == 0 main_result.rows.concat(result_obj.rows) end result = main_result end printer = showplan_printer.new(result) printer.pp end |
#jdbc_connection_class(_spec) ⇒ Object
76 77 78 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 76 def jdbc_connection_class(_spec) ::ActiveRecord::ConnectionAdapters::MSSQLJdbcConnection end |
#quoted_date(value) ⇒ Object
Override Since we aren’t passing dates/times around as strings we need to process them here, just making sure they are a string
83 84 85 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 83 def quoted_date(value) super.to_s end |
#reset! ⇒ Object
88 89 90 91 92 93 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 88 def reset! clear_cache! reset_transaction @connection.rollback # Have to deal with rollbacks differently than the SQLServer gem @connection.configure_connection end |
#supports_transaction_isolation? ⇒ Boolean
Have to reset this because the default arjdbc functionality is to return false unless a level is passed in
96 97 98 |
# File 'lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb', line 96 def supports_transaction_isolation? true end |