Difference between revisions of "SQLQuery"
From SCAR Divi Manual
(Created page with "==Definition== <source lang="scar" lines="false"> function SQLOpen(const Path: string; const CreateIfNotFound: Boolean): Integer; </source> ==Availability== SCAR Divi 3.31 > Cur...") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Definition== | ==Definition== | ||
<source lang="scar" lines="false"> | <source lang="scar" lines="false"> | ||
− | + | procedure SQLQuery(const DBIndex: Integer; const Query: string); | |
</source> | </source> | ||
Line 8: | Line 8: | ||
==Description== | ==Description== | ||
− | Allows you to execute a "simple" [ | + | Allows you to execute a "simple" [[SQLite3]] query statement '''Query''' on an open database connection specified by '''DBIndex'''. If you would like to retrieve data from the database, use parameter binding and/or have more control over your database interactions, you should use [[SQLQueryEx]]. |
==Example== | ==Example== |
Latest revision as of 09:59, 10 February 2012
Definition
procedure SQLQuery(const DBIndex: Integer; const Query: string);
Availability
SCAR Divi 3.31 > Current
Description
Allows you to execute a "simple" SQLite3 query statement Query on an open database connection specified by DBIndex. If you would like to retrieve data from the database, use parameter binding and/or have more control over your database interactions, you should use SQLQueryEx.
Example
var DB, Query, InsertID: Integer; begin DB := SQLOpen(WorkspacePath + 'test.db3', True); try // Create a table SQLQuery(DB, 'CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, string TEXT)'); // Insert 2 rows into the table Query := SQLQueryEx(DB, 'INSERT INTO test VALUES(NULL, ?)'); try SQLBindStr(Query, 1, 'Hello Mars!'); SQLQueryStep(Query); SQLQueryReset(Query); SQLBindStr(Query, 1, 'Hello World!'); SQLQueryStep(Query); InsertID := SQLLastID(DB); finally SQLQueryFree(Query); end; // Get the data stored in the last row Query := SQLQueryEx(DB, 'SELECT * FROM test WHERE id = ?'); try SQLBindInt(Query, 1, InsertID); if SQLQueryStep(Query) = SQL_ROW then WriteLn(SQLColumnStr(Query, 1)); finally SQLQueryFree(Query); end; finally SQLFree(DB); end; end.
Output:
Hello World!