module Sequel::Plugins::PreparedStatements::InstanceMethods
Private Instance Methods
_insert_raw(ds)
click to toggle source
Use a prepared statement to insert the values into the model's dataset.
Calls superclass method
# File lib/sequel/plugins/prepared_statements.rb, line 125 def _insert_raw(ds) if use_prepared_statements_for?(:insert) _set_prepared_statement_server(model.send(:prepared_insert, @values.keys)).call(@values) else super end end
_insert_select_raw(ds)
click to toggle source
Use a prepared statement to insert the values into the model's dataset and return the new column values.
Calls superclass method
# File lib/sequel/plugins/prepared_statements.rb, line 135 def _insert_select_raw(ds) if use_prepared_statements_for?(:insert_select) _set_prepared_statement_server(model.send(:prepared_insert_select, @values.keys)).call(@values) else super end end
_set_prepared_statement_server(ps)
click to toggle source
If a server is set for the instance, return a prepared statement that will use that server.
# File lib/sequel/plugins/prepared_statements.rb, line 153 def _set_prepared_statement_server(ps) if @server ps.server(@server) else ps end end
_update_without_checking(columns)
click to toggle source
Use a prepared statement to update this model's columns in the database.
Calls superclass method
# File lib/sequel/plugins/prepared_statements.rb, line 144 def _update_without_checking(columns) if use_prepared_statements_for?(:update) _set_prepared_statement_server(model.send(:prepared_update, columns.keys)).call(columns.merge(pk_hash)) else super end end
use_prepared_statements_for?(type)
click to toggle source
Whether prepared statements should be used for the given type of query (:insert, :insert_select, :update). True by default, can be overridden in other plugins to disallow prepared statements for specific types of queries.
Calls superclass method
# File lib/sequel/plugins/prepared_statements.rb, line 165 def use_prepared_statements_for?(type) if defined?(super) result = super return result unless result.nil? end case type when :insert, :update true when :insert_select # SQLite RETURNING support has a bug that doesn't allow for committing transactions # when a prepared statement with RETURNING has been used on the connection: # # SQLite3::BusyException: cannot commit transaction - SQL statements in progress: COMMIT # # Disabling usage of prepared statements for insert_select on SQLite seems to be the # simplest way to workaround the problem. db.database_type != :sqlite # :nocov: when :delete, :refresh Sequel::Deprecation.deprecate("The :delete and :refresh prepared statement types", "There should be no need to check if these types are supported") false # :nocov: else raise Error, "unsupported type used: #{type.inspect}" end end