sqlite_query

mIRC SQLite

sqlite_query
Executes a SQL query and returns data returned by it.
Syntax
$sqlite_query ( conn, query [, bind_value [, ... ] ] ) [ .file ]
/sqlite_query conn query
$sqlite_query ( statement [, bind_value [, ... ] ] )
/sqlite_query statement [ bind_value [ ... ] ]
Parameters
conn
The connection identifier.
query
The query to execute.
statement
A prepared statement to execute.
bind_value
Optional. One or more values to bind to the query.
Properties
file
Optional. If specified the query parameter is treated as a filename instead, and that file will be executed as SQL.
Return Value
A positive, numeric result identifier or 0 on success, or $null if there was an error.
Remarks
To execute a prepared statement first prepare it with $sqlite_prepare.
To learn about prepared statements and binding values, see Prepared Statements.

In case of 0 is returned, it means that $sqlite_query was used to execute a query that doesn't return any data, such as INSERT or UPDATE.
A SELECT query always returns a result identifier on success, even if the query selected no rows. You can use $sqlite_num_rows to determine how many rows were returned.

If $null is returned you can determine the exact reason for the error by checking the value of %sqlite_errstr.
For more information about error handling, see Handling Errors

Note that if you want to bind a text value with more than one word, you must use the identifier form of syntax. If you don't care about the return value, you can use the built-in mIRC command /noop

Starting from mSQLite version 1.2.0 you can bind values even for non-prepared statements, but this only works when calling $sqlite_query as an identifier.

$sqlite_query can execute multiple queries seperated by semicolons. The returned result is the data returned by the last SQL query.
To see guidelines for writing SQL queries with mIRC SQLite, see Writing Queries.
Example
; Selects data from a table and fetches it, assumes that a db connection is already established
var %sql = SELECT col, another FROM table
var %request = $sqlite_query(%db, %sql)
if (%request) {
  echo -a Query executed successfully.
  sqlite_free %request
}
else {
  echo -a Error executing query: %sqlite_errstr
}