Difference between revisions of "SQLBindInt"

From SCAR Divi Manual
Jump to: navigation, search
(Created page with "==Definition== <source lang="scar" lines="false"> procedure SQLBindInt(const QueryIndex, ParamIndex: Integer; const Int: Integer); </source> ==Availability== SCAR Divi 3.31 > Cu...")
 
(Description)
Line 8: Line 8:
  
 
==Description==
 
==Description==
Binds an [[integer]] parameter '''Int''' to an [http://www.sqlite.org/ SQLite3] query statement given by '''QueryIndex''' at the parameter index given by '''ParamIndex'''. A parameter is specified in your query by "?" and the index is offset at 1 rather than 0.
+
Binds an [[integer]] parameter '''Int''' to an [[SQLite3]] query statement given by '''QueryIndex''' at the parameter index given by '''ParamIndex'''. A parameter is specified in your query by "?" and the index is offset at 1 rather than 0.
  
 
==Example==
 
==Example==

Revision as of 10:59, 10 February 2012

Definition

procedure SQLBindInt(const QueryIndex, ParamIndex: Integer; const Int: Integer);

Availability

SCAR Divi 3.31 > Current

Description

Binds an integer parameter Int to an SQLite3 query statement given by QueryIndex at the parameter index given by ParamIndex. A parameter is specified in your query by "?" and the index is offset at 1 rather than 0.

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!

See Also