Method: PG::Connection#prepare
- Defined in:
- ext/pg_connection.c
#prepare(stmt_name, sql[, param_types ]) ⇒ PG::Result Also known as: async_prepare
Prepares statement sql with name name to be executed later. Returns a PG::Result instance on success. On failure, it raises a PG::Error.
param_types
is an optional parameter to specify the Oids of the types of the parameters.
If the types are not specified, they will be inferred by PostgreSQL. Instead of specifying type oids, it’s recommended to simply add explicit casts in the query to ensure that the right type is used.
For example: “SELECT $1::int”
PostgreSQL bind parameters are represented as $1, $2, $3, etc., inside the SQL query.
See also corresponding libpq function.
3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 |
# File 'ext/pg_connection.c', line 3394
static VALUE
pgconn_async_prepare(int argc, VALUE *argv, VALUE self)
{
VALUE rb_pgresult = Qnil;
pgconn_discard_results( self );
pgconn_send_prepare( argc, argv, self );
rb_pgresult = pgconn_async_get_last_result( self );
if ( rb_block_given_p() ) {
return rb_ensure( rb_yield, rb_pgresult, pg_result_clear, rb_pgresult );
}
return rb_pgresult;
}
|