Method: Pod4::PgInterface#selectp
- Defined in:
- lib/pod4/pg_interface.rb
#selectp(sql, *vals) ⇒ Object
Run SQL code on the server as per select() but with parameter insertion.
Placeholders in the SQL string should all be %s as per sql_helper methods. Values should be as returned by sql_helper methods.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/pod4/pg_interface.rb', line 242 def selectp(sql, *vals) raise(ArgumentError, "Bad SQL parameter") unless sql.kind_of?(String) client = ensure_connection Pod4.logger.debug(__FILE__){ "select: #{sql} #{vals.inspect}" } rows = [] client.exec_params( *parse_for_params(sql, vals) ) do |query| oids = make_oid_hash(query) query.each do |r| row = cast_row_fudge(r, oids) if block_given? rows << yield(row) else rows << row end end end client.cancel rows rescue => e handle_error(e) end |