Method: PG::Connection#send_query

Defined in:
ext/pg_connection.c

#send_query(sql) ⇒ nil

Sends SQL query request specified by sql to PostgreSQL for asynchronous processing, and immediately returns. On failure, it raises a PG::Error.

For backward compatibility, if you pass more than one parameter to this method, it will call #send_query_params for you. New code should explicitly use #send_query_params if argument placeholders are used.

Returns:

  • (nil)


1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
# File 'ext/pg_connection.c', line 1948

static VALUE
pgconn_send_query(int argc, VALUE *argv, VALUE self)
{
  t_pg_connection *this = pg_get_connection_safe( self );

  /* If called with no or nil parameters, use PQexec for compatibility */
  if ( argc == 1 || (argc >= 2 && argc <= 4 && NIL_P(argv[1]) )) {
    if(gvl_PQsendQuery(this->pgconn, pg_cstr_enc(argv[0], this->enc_idx)) == 0)
      pg_raise_conn_error( rb_eUnableToSend, self, "PQsendQuery %s", PQerrorMessage(this->pgconn));

    pgconn_wait_for_flush( self );
    return Qnil;
  }

  pg_deprecated(2, ("forwarding async_exec to async_exec_params and send_query to send_query_params is deprecated"));

  /* If called with parameters, and optionally result_format,
   * use PQsendQueryParams
   */
  return pgconn_send_query_params( argc, argv, self);
}