# Method Sql.Sql()->query()

Method query

  ``array`(`mapping`(`string`:`string`)) query(`object`|`string` `q`, `mixed` ... `extraargs`)`

Description

  Sends an SQL query synchronously to the underlying SQL-server and returns the results in untyped mode.

Parameter `q`

  Query to send to the SQL-server. This can either be a string with the query, or a previously compiled query (see compile_query()).

Parameter `extraargs`

  This parameter, if specified, can be in two forms:

  1. A mapping containing bindings of variables used in the query. A variable is identified by a colon (:) followed by a name or number. Each index in the mapping corresponds to one such variable, and the value for that index is substituted (quoted) into the query wherever the variable is used.

         res = query("SELECT foo FROM bar WHERE gazonk=:baz",
                     ([":baz":"value"]));

     Binary values (BLOBs) may need to be placed in multisets.

  2. Arguments as you would use in sprintf. They are automatically quoted.

         res = query("select foo from bar where gazonk=%s","value");

Returns

  Returns one of the following on success:

  ``array`(`mapping`(`string`:`string`))` | The result as an array of mappings indexed on the name of the columns. The values are either strings with the display representations or zero for the SQL NULL value.
  ``zero`` | The value `0` (zero) if the query didn't return any result (eg `INSERT` or similar).

Throws

  Throws an exception if the query fails.

See also

  typed_query, big_query, streaming_query