dbCreateQuery

Purpose

Process an SQL statement and prepare a query. If placeholders is present, these values are bound sequentially to ODBC style parameters.

Format

qid = dbCreateQuery(db_id[, query[, placeholders]])
Parameters:
  • db_id (scalar) – database connection index number.
  • query (string) – optional. database query to construct.
  • placeholders (string or string array) – optional. containing bind value(s).
Returns:

qid (scalar) – query id to be used for result retrieval.

Examples

Example 1

// Create and prepare query
qid = dbCreateQuery("SELECT * FROM GDP
                    WHERE COUNTRY = ?", "USA");
dbQueryExecPrepared(qid);

// Results as a matrix
results = dbQueryFetchAllM(qid);

Example 2

// Create query
qid = dbCreateQuery("INSERT INTO
                    PEOPLE(id, fname, lname) VALUES
                    (NULL, ?, ?);");

// Set the placeholder
dbQueryBindValue(qid, "Joe");

// Set the placeholder
dbQueryBindValue(qid, "Smith");

// Execute query
dbQueryExecPrepared(qid);

Remarks

If the placeholders parameter is passed in, the values are bound sequentially to ODBC style parameters.

See also

dbQueryPrepare()