Class Index [+]

Quicksearch

Sequel::MySQL::PreparedStatements

This module is used by the mysql and mysql2 adapters to support prepared statements and stored procedures.

Public Instance Methods

execute_prepared_statement(ps_name, opts, &block) click to toggle source

Executes a prepared statement on an available connection. If the prepared statement already exists for the connection and has the same SQL, reuse it, otherwise, prepare the new statement. Because of the usual MySQL stupidity, we are forced to name arguments via separate SET queries. Use @sequel_arg_N (for N starting at 1) for these arguments.

    # File lib/sequel/adapters/shared/mysql_prepared_statements.rb, line 42
42:         def execute_prepared_statement(ps_name, opts, &block)
43:           args = opts[:arguments]
44:           ps = prepared_statement(ps_name)
45:           sql = ps.prepared_sql
46:           synchronize(opts[:server]) do |conn|
47:             unless conn.prepared_statements[ps_name] == sql
48:               conn.prepared_statements[ps_name] = sql
49:               _execute(conn, "PREPARE #{ps_name} FROM #{literal(sql)}", opts)
50:             end
51:             i = 0
52:             _execute(conn, "SET " + args.map {|arg| "@sequel_arg_#{i+=1} = #{literal(arg)}"}.join(", "), opts) unless args.empty?
53:             opts = opts.merge(:log_sql=>" (#{sql})") if ps.log_sql
54:             _execute(conn, "EXECUTE #{ps_name}#{" USING #{(1..i).map{|j| "@sequel_arg_#{j}"}.join(', ')}" unless i == 0}", opts, &block)
55:           end
56:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.