sqlite_fetch_single
Fetches and returns the first column of the current row from a result and then advances to the next row.
Syntax
$sqlite_fetch_single ( result [, &binvar; ] )
|
Parameters
result
The result identifier.
binvar
The name of the binary variable to assign binary data to. Optional.
Return Value
The value of the first column of the fetched row if &binvar; isn't specified, otherwise the size of the binary variable on success, $null if there are no more rows, or if there was an error.
Remarks
If &binvar; is specified the behaviour of $sqlite_fetch_single changes slightly. Instead of returning the first column's value, it will assign it to a binvar and return the binvar's size on success.In case the first column is not blob type, its text representation will be stored in the &binvar; as sequential ascii values. If &binvar; isn't set, but the first column is a blob, it will be converted to text.
For more information about handling binary data in mSQLite, see Handling Binary Data
In case of $null is returned it can mean three different things:
1. The returned value from SQLite database is NULL.
2. There are no more rows available.
3. There was an error.
To determine the cause of $null, examine the %sqlite_errno variable after calling $sqlite_fetch_single. The returned value can be one of the following:
1. $SQLITE_OK if there was no error.
2. $SQLITE_NOMOREROWS if there are no more rows available.
3. Some other of the Error Codes if there was an error.
Example
; This code assumes a connection is already established and stored in %db
var %sql = SELECT COUNT(*) FROM contacts var %res = $sqlite_query(%db, %sql) if (%res) { echo -a Number of rows in contacts: $sqlite_fetch_single(%res) sqlite_free %res } else { echo -a Error executing query: %sqlite_errstr } |