Class | Sequel::Postgres::Dataset |
In: |
lib/sequel_core/adapters/postgres.rb
|
Parent: | Sequel::Dataset |
Dataset class for PostgreSQL datasets that use the pg, postgres, or postgres-pr driver.
PREPARED_ARG_PLACEHOLDER | = | '$'.lit.freeze |
Execute the given type of statement with the hash of values.
# File lib/sequel_core/adapters/postgres.rb, line 428 428: def call(type, hash, values=nil, &block) 429: ps = to_prepared_statement(type, values) 430: ps.extend(BindArgumentMethods) 431: ps.call(hash, &block) 432: end
Yield all rows returned by executing the given SQL and converting the types.
# File lib/sequel_core/adapters/postgres.rb, line 311 311: def fetch_rows(sql) 312: cols = [] 313: execute(sql) do |res| 314: res.nfields.times do |fieldnum| 315: cols << [fieldnum, PG_TYPES[res.ftype(fieldnum)], output_identifier(res.fname(fieldnum))] 316: end 317: @columns = cols.map{|c| c.at(2)} 318: res.ntuples.times do |recnum| 319: converted_rec = {} 320: cols.each do |fieldnum, type_proc, fieldsym| 321: value = res.getvalue(recnum, fieldnum) 322: converted_rec[fieldsym] = (value && type_proc) ? type_proc.call(value) : value 323: end 324: yield converted_rec 325: end 326: end 327: end
Literalize strings and blobs using code from the native adapter.
# File lib/sequel_core/adapters/postgres.rb, line 330 330: def literal(v) 331: case v 332: when LiteralString 333: v 334: when SQL::Blob 335: db.synchronize{|c| "'#{c.escape_bytea(v)}'"} 336: when String 337: db.synchronize{|c| "'#{c.escape_string(v)}'"} 338: else 339: super 340: end 341: end
Prepare the given type of statement with the given name, and store it in the database to be called later.
# File lib/sequel_core/adapters/postgres.rb, line 436 436: def prepare(type, name=nil, values=nil) 437: ps = to_prepared_statement(type, values) 438: ps.extend(PreparedStatementMethods) 439: if name 440: ps.prepared_statement_name = name 441: db.prepared_statements[name] = ps 442: end 443: ps 444: end