Backbone of the prepared statement support. Grafts bind variable support into datasets by hijacking literal and using placeholders. By default, emulates prepared statements and bind variables by taking the hash of bind variables and directly substituting them into the query, which works on all databases, as it is no different from using the dataset without bind variables.
The argument to supply to insert and update, which may use placeholders specified by prepared_args
Sets the prepared_args to the given hash and runs the prepared statement.
# File lib/sequel/dataset/prepared_statements.rb, line 72 def call(bind_vars={}, &block) bind(bind_vars).run(&block) end
Programmer friendly string showing this is a prepared statement, with the prepared SQL it represents (which in general won’t have substituted variables).
# File lib/sequel/dataset/prepared_statements.rb, line 108 def inspect "<#{self.class.name}/PreparedStatement #{prepared_sql.inspect}>" end
Changes the values of symbols if they start with $ and prepared_args is present. If so, they are considered placeholders, and they are substituted using prepared_arg.
# File lib/sequel/dataset/prepared_statements.rb, line 96 def literal_symbol(v) if @opts[:bind_vars] and match = PLACEHOLDER_RE.match(v.to_s) v2 = prepared_arg(match[1].to_sym) v2 ? literal(v2) : v else super end end
Returns the SQL for the prepared statement, depending on the type of the statement and the prepared_modify_values.
# File lib/sequel/dataset/prepared_statements.rb, line 78 def prepared_sql case @prepared_type when :select, :all select_sql when :first clone(:limit=>1).select_sql when :insert insert_sql(*@prepared_modify_values) when :update update_sql(*@prepared_modify_values) when :delete delete_sql end end
Run the method based on the type of prepared statement, with :select running all to get all of the rows, and the other types running the method with the same name as the type.
# File lib/sequel/dataset/prepared_statements.rb, line 117 def run(&block) case @prepared_type when :select, :all all(&block) when :first first when :insert insert(*@prepared_modify_values) when :update update(*@prepared_modify_values) when :delete delete end end
Generated with the Darkfish Rdoc Generator 2.