Executes a SQL SELECT statement.
public virtual bool ExecuteScalar(
void * dstPtr,
size_t dstSize,
ul_column_storage_type dstType,
const char * sql,
...
)
dstPtr A pointer to a variable of the required type to receive the value.
dstSize The size of variable to receive value, if applicable.
dstType The type of value to retrieve; must match variable type.
sql The SELECT statement, optionally containing '?' parameters.
... String (char *) parameter values to substitute.
True if the query is successfully executed and a value is successfully retrieved; otherwise, false is returned when a value is not fetched. Check the SQLCODE to determine why false is returned. The selected value is NULL if no warning or error (SQLE_NOERROR) is indicated.
dstPtr must point to a variable of the correct type, matching the dstType. dstSize is only required for variable-sized values, such as strings and binaries, and is otherwise ignored. The variable list of parameter values must correspond to parameters in the statement, and all values are assumed to be strings (Internally, UltraLite casts the parameter values as required for the statement).
The following types are supported:
#UL_TYPE_BIT/#UL_TYPE_TINY Use variable type ul_byte (8 bit, unsigned).
#UL_TYPE_U_SHORT/#UL_TYPE_S_SHORT Use variable type ul_u_short/ul_s_short (16 bit).
#UL_TYPE_U_LONG/#UL_TYPE_S_LONG Use variable type ul_u_long/ul_s_long (32 bit).
#UL_TYPE_U_BIG/#UL_TYPE_S_BIG Use variable type ul_u_big/ul_s_big (64 bit).
#UL_TYPE_DOUBLE Use variable type ul_double (double).
#UL_TYPE_REAL Use variable type ul_real (float).
#UL_TYPE_BINARY Use variable type ul_binary and specify dstSize (as in GetBinary()).
#UL_TYPE_TIMESTAMP_STRUCT Use variable type DECL_DATETIME.
#UL_TYPE_CHAR Use variable type char [] (a character buffer), and set dstSize to the size of the buffer (as in GetString()).
#UL_TYPE_WCHAR Use variable type ul_wchar [] (a wide character buffer), and set dstSize to the size of the buffer (as in GetString()).
#UL_TYPE_TCHAR Same as UL_TYPE_CHAR or UL_TYPE_WCHAR, depending on which version of the function is called.
For more information about these types, see ul_column_storage_type enumeration.
The following example demonstrates integer fetching:
ul_u_long val; ok = conn->ExecuteScalar( &val, 0, UL_TYPE_U_LONG, "SELECT count(*) FROM t WHERE col LIKE ?", "ABC%" ); |
The following example demonstrates string fetching:
char val[40]; ok = conn->ExecuteScalar( &val, sizeof(val), UL_TYPE_CHAR, "SELECT uuidtostr( newid() )" ); |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |