Class Index [+]

Quicksearch

Sequel::Dataset::ArgumentMapper

Oracle already supports named bind arguments, so use directly.


PostgreSQL specific argument mapper used for mapping the named argument hash to a array with numbered arguments. Only used with the pg driver.


Default implementation of the argument mapper to allow native database support for bind variables and prepared statements (as opposed to the emulated ones used by default).

Attributes

prepared_statement_name[RW]

The name of the prepared statement, if any.

bind_arguments[RW]

The bind arguments to use for running this prepared statement

Public Instance Methods

call(bind_vars={}, &block) click to toggle source

Set the bind arguments based on the hash and call super.

    # File lib/sequel/dataset/prepared_statements.rb, line 22
22:       def call(bind_vars={}, &block)
23:         ds = bind(bind_vars)
24:         ds.prepared_sql
25:         ds.bind_arguments = ds.map_to_prepared_args(ds.opts[:bind_vars])
26:         ds.run(&block)
27:       end
prepared_sql() click to toggle source

Override the given *_sql method based on the type, and cache the result of the sql.

    # File lib/sequel/dataset/prepared_statements.rb, line 31
31:       def prepared_sql
32:         return @prepared_sql if @prepared_sql
33:         @prepared_args ||= []
34:         @prepared_sql = super
35:         @opts[:sql] = @prepared_sql
36:         @prepared_sql
37:       end

Protected Instance Methods

map_to_prepared_args(bind_vars) click to toggle source

Return a hash with the same values as the given hash, but with the keys converted to strings.

     # File lib/sequel/adapters/oracle.rb, line 299
299:         def map_to_prepared_args(bind_vars)
300:           prepared_args.map{|v, t| [bind_vars[v], t]}
301:         end
map_to_prepared_args(hash) click to toggle source

An array of bound variable values for this query, in the correct order.

     # File lib/sequel/adapters/postgres.rb, line 601
601:           def map_to_prepared_args(hash)
602:             prepared_args.map{|k| hash[k.to_sym]}
603:           end

Private Instance Methods

prepared_arg(k) click to toggle source

Oracle uses a : before the name of the argument for named arguments.

     # File lib/sequel/adapters/oracle.rb, line 307
307:         def prepared_arg(k)
308:           y, type = k.to_s.split("__", 2)
309:           prepared_args << [y.to_sym, type]
310:           i = prepared_args.length
311:           LiteralString.new(":#{i}")
312:         end
prepared_arg(k) click to toggle source

PostgreSQL most of the time requires type information for each of arguments to a prepared statement. Handle this by allowing the named argument to have a __* suffix, with the * being the type. In the generated SQL, cast the bound argument to that type to elminate ambiguity (and PostgreSQL from raising an exception).

     # File lib/sequel/adapters/postgres.rb, line 612
612:           def prepared_arg(k)
613:             y, type = k.to_s.split("__")
614:             if i = prepared_args.index(y)
615:               i += 1
616:             else
617:               prepared_args << y
618:               i = prepared_args.length
619:             end
620:             LiteralString.new("#{prepared_arg_placeholder}#{i}#{"::#{type}" if type}")
621:           end
prepared_arg?(k) click to toggle source

Always assume a prepared argument.

     # File lib/sequel/adapters/postgres.rb, line 624
624:           def prepared_arg?(k)
625:            true
626:           end
prepared_arg?(k) click to toggle source

Always assume a prepared argument.

     # File lib/sequel/adapters/oracle.rb, line 315
315:         def prepared_arg?(k)
316:           true
317:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.