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 125 def _insert_raw(ds) 126 if use_prepared_statements_for?(:insert) 127 _set_prepared_statement_server(model.send(:prepared_insert, @values.keys)).call(@values) 128 else 129 super 130 end 131 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 135 def _insert_select_raw(ds) 136 if use_prepared_statements_for?(:insert_select) 137 _set_prepared_statement_server(model.send(:prepared_insert_select, @values.keys)).call(@values) 138 else 139 super 140 end 141 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 153 def _set_prepared_statement_server(ps) 154 if @server 155 ps.server(@server) 156 else 157 ps 158 end 159 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 144 def _update_without_checking(columns) 145 if use_prepared_statements_for?(:update) 146 _set_prepared_statement_server(model.send(:prepared_update, columns.keys)).call(columns.merge(pk_hash)) 147 else 148 super 149 end 150 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 165 def use_prepared_statements_for?(type) 166 if defined?(super) 167 result = super 168 return result unless result.nil? 169 end 170 171 case type 172 when :insert, :update 173 true 174 when :insert_select 175 # SQLite RETURNING support has a bug that doesn't allow for committing transactions 176 # when a prepared statement with RETURNING has been used on the connection: 177 # 178 # SQLite3::BusyException: cannot commit transaction - SQL statements in progress: COMMIT 179 # 180 # Disabling usage of prepared statements for insert_select on SQLite seems to be the 181 # simplest way to workaround the problem. 182 db.database_type != :sqlite 183 # :nocov: 184 when :delete, :refresh 185 Sequel::Deprecation.deprecate("The :delete and :refresh prepared statement types", "There should be no need to check if these types are supported") 186 false 187 # :nocov: 188 else 189 raise Error, "unsupported type used: #{type.inspect}" 190 end 191 end