#include <cpl_odbc.h>
Public Member Functions | |
CPLODBCStatement (CPLODBCSession *) | |
HSTMT | GetStatement () |
void | Clear () |
void | AppendEscaped (const char *) |
void | Append (const char *) |
void | Append (int) |
void | Append (double) |
int | Appendf (const char *,...) |
const char * | GetCommand () |
int | ExecuteSQL (const char *=NULL) |
int | Fetch (int nOrientation=SQL_FETCH_NEXT, int nOffset=0) |
void | ClearColumnData () |
int | GetColCount () |
const char * | GetColName (int) |
short | GetColType (int) |
const char * | GetColTypeName (int) |
short | GetColSize (int) |
short | GetColPrecision (int) |
short | GetColNullable (int) |
int | GetColId (const char *) |
const char * | GetColData (int, const char *=NULL) |
const char * | GetColData (const char *, const char *=NULL) |
int | GetColDataLength (int) |
int | GetColumns (const char *pszTable, const char *pszCatalog=NULL, const char *pszSchema=NULL) |
int | GetPrimaryKeys (const char *pszTable, const char *pszCatalog=NULL, const char *pszSchema=NULL) |
int | GetTables (const char *pszCatalog=NULL, const char *pszSchema=NULL) |
void | DumpResult (FILE *fp, int bShowSchema=FALSE) |
int | CollectResultsInfo () |
Static Public Member Functions | |
static CPLString | GetTypeName (int) |
static SQLSMALLINT | GetTypeMapping (SQLSMALLINT) |
Abstraction for statement, and resultset.
Includes methods for executing an SQL statement, and for accessing the resultset from that statement. Also provides for executing other ODBC requests that produce results sets such as SQLColumns() and SQLTables() requests.
void CPLODBCStatement::Append | ( | double | dfValue | ) |
Append to internal command.
The passed value is formatted and appended to the internal SQL command text.
dfValue | value to append to the command. |
References Append().
void CPLODBCStatement::Append | ( | int | nValue | ) |
Append to internal command.
The passed value is formatted and appended to the internal SQL command text.
nValue | value to append to the command. |
References Append().
void CPLODBCStatement::Append | ( | const char * | pszText | ) |
Append text to internal command.
The passed text is appended to the internal SQL command text.
pszText | text to append. |
Referenced by Append(), AppendEscaped(), Appendf(), and ExecuteSQL().
void CPLODBCStatement::AppendEscaped | ( | const char * | pszText | ) |
Append text to internal command.
The passed text is appended to the internal SQL command text after escaping any special characters so it can be used as a character string in an SQL statement.
pszText | text to append. |
References Append().
int CPLODBCStatement::Appendf | ( | const char * | pszFormat, | |
... | ||||
) |
Append to internal command.
The passed format is used to format other arguments and the result is appended to the internal command text. Long results may not be formatted properly, and should be appended with the direct Append() methods.
pszFormat | printf() style format string. |
References Append().
void CPLODBCStatement::Clear | ( | ) |
Clear internal command text and result set definitions.
Referenced by ExecuteSQL().
void CPLODBCStatement::DumpResult | ( | FILE * | fp, | |
int | bShowSchema = FALSE | |||
) |
Dump resultset to file.
The contents of the current resultset are dumped in a simply formatted form to the provided file. If requested, the schema definition will be written first.
fp | the file to write to. stdout or stderr are acceptable. | |
bShowSchema | TRUE to force writing schema information for the rowset before the rowset data itself. Default is FALSE. |
References Fetch(), GetColCount(), GetColData(), GetColName(), GetColNullable(), GetColPrecision(), GetColSize(), GetColType(), and GetTypeName().
int CPLODBCStatement::ExecuteSQL | ( | const char * | pszStatement = NULL |
) |
Execute an SQL statement.
This method will execute the passed (or stored) SQL statement, and initialize information about the resultset if there is one. If a NULL statement is passed, the internal stored statement that has been previously set via Append() or Appendf() calls will be used.
pszStatement | the SQL statement to execute, or NULL if the internally saved one should be used. |
int CPLODBCStatement::Fetch | ( | int | nOrientation = SQL_FETCH_NEXT , |
|
int | nOffset = 0 | |||
) |
Fetch a new record.
Requests the next row in the current resultset using the SQLFetchScroll() call. Note that many ODBC drivers only support the default forward fetching one record at a time. Only SQL_FETCH_NEXT (the default) should be considered reliable on all drivers.
Currently it isn't clear how to determine whether an error or a normal out of data condition has occured if Fetch() fails.
nOrientation | One of SQL_FETCH_NEXT, SQL_FETCH_LAST, SQL_FETCH_PRIOR, SQL_FETCH_ABSOLUTE, or SQL_FETCH_RELATIVE (default is SQL_FETCH_NEXT). | |
nOffset | the offset (number of records), ignored for some orientations. |
References CPLODBCSession::GetLastError(), and GetTypeMapping().
Referenced by DumpResult().
int CPLODBCStatement::GetColCount | ( | ) |
Fetch the resultset column count.
Referenced by DumpResult().
const char * CPLODBCStatement::GetColData | ( | const char * | pszColName, | |
const char * | pszDefault = NULL | |||
) |
Fetch column data.
Fetches the data contents of the requested column for the currently loaded row. The result is returned as a string regardless of the column type. NULL is returned if an illegal column is given, or if the actual column is "NULL".
pszColName | the name of the column requested. | |
pszDefault | the value to return if the column does not exist, or is NULL. Defaults to NULL. |
References GetColData(), and GetColId().
const char * CPLODBCStatement::GetColData | ( | int | iCol, | |
const char * | pszDefault = NULL | |||
) |
Fetch column data.
Fetches the data contents of the requested column for the currently loaded row. The result is returned as a string regardless of the column type. NULL is returned if an illegal column is given, or if the actual column is "NULL".
iCol | the zero based column to fetch. | |
pszDefault | the value to return if the column does not exist, or is NULL. Defaults to NULL. |
Referenced by DumpResult(), and GetColData().
int CPLODBCStatement::GetColId | ( | const char * | pszColName | ) |
Fetch column index.
Gets the column index corresponding with the passed name. The name comparisons are case insensitive.
pszColName | the name to search for. |
Referenced by GetColData().
const char * CPLODBCStatement::GetColName | ( | int | iCol | ) |
Fetch a column name.
iCol | the zero based column index. |
Referenced by DumpResult().
short CPLODBCStatement::GetColNullable | ( | int | iCol | ) |
Fetch the column nullability.
iCol | the zero based column index. |
Referenced by DumpResult().
short CPLODBCStatement::GetColPrecision | ( | int | iCol | ) |
Fetch the column precision.
iCol | the zero based column index. |
Referenced by DumpResult().
short CPLODBCStatement::GetColSize | ( | int | iCol | ) |
Fetch the column width.
iCol | the zero based column index. |
Referenced by DumpResult().
short CPLODBCStatement::GetColType | ( | int | iCol | ) |
Fetch a column data type.
The return type code is a an ODBC SQL_ code, one of SQL_UNKNOWN_TYPE, SQL_CHAR, SQL_NUMERIC, SQL_DECIMAL, SQL_INTEGER, SQL_SMALLINT, SQL_FLOAT, SQL_REAL, SQL_DOUBLE, SQL_DATETIME, SQL_VARCHAR, SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TYPE_TIMESTAMPT.
iCol | the zero based column index. |
Referenced by DumpResult().
const char * CPLODBCStatement::GetColTypeName | ( | int | iCol | ) |
Fetch a column data type name.
Returns data source-dependent data type name; for example, "CHAR", "VARCHAR", "MONEY", "LONG VARBINAR", or "CHAR ( ) FOR BIT DATA".
iCol | the zero based column index. |
int CPLODBCStatement::GetColumns | ( | const char * | pszTable, | |
const char * | pszCatalog = NULL , |
|||
const char * | pszSchema = NULL | |||
) |
Fetch column definitions for a table.
The SQLColumn() method is used to fetch the definitions for the columns of a table (or other queriable object such as a view). The column definitions are digested and used to populate the CPLODBCStatement column definitions essentially as if a "SELECT * FROM tablename" had been done; however, no resultset will be available.
pszTable | the name of the table to query information on. This should not be empty. | |
pszCatalog | the catalog to find the table in, use NULL (the default) if no catalog is available. | |
pszSchema | the schema to find the table in, use NULL (the default) if no schema is available. |
int CPLODBCStatement::GetPrimaryKeys | ( | const char * | pszTable, | |
const char * | pszCatalog = NULL , |
|||
const char * | pszSchema = NULL | |||
) |
Fetch primary keys for a table.
The SQLPrimaryKeys() function is used to fetch a list of fields forming the primary key. The result is returned as a result set matching the SQLPrimaryKeys() function result set. The 4th column in the result set is the column name of the key, and if the result set contains only one record then that single field will be the complete primary key.
pszTable | the name of the table to query information on. This should not be empty. | |
pszCatalog | the catalog to find the table in, use NULL (the default) if no catalog is available. | |
pszSchema | the schema to find the table in, use NULL (the default) if no schema is available. |
int CPLODBCStatement::GetTables | ( | const char * | pszCatalog = NULL , |
|
const char * | pszSchema = NULL | |||
) |
Fetch tables in database.
The SQLTables() function is used to fetch a list tables in the database. The result is returned as a result set matching the SQLTables() function result set. The 3rd column in the result set is the table name. Only tables of type "TABLE" are returned.
pszCatalog | the catalog to find the table in, use NULL (the default) if no catalog is available. | |
pszSchema | the schema to find the table in, use NULL (the default) if no schema is available. |
SQLSMALLINT CPLODBCStatement::GetTypeMapping | ( | SQLSMALLINT | nTypeCode | ) | [static] |
Get appropriate C data type for SQL column type.
Returns a C data type code, corresponding to the indicated SQL data type code (as returned from CPLODBCStatement::GetColType()).
nTypeCode | the SQL_ code, such as SQL_CHAR. |
Referenced by Fetch().
CPLString CPLODBCStatement::GetTypeName | ( | int | nTypeCode | ) | [static] |
Get name for SQL column type.
Returns a string name for the indicated type code (as returned from CPLODBCStatement::GetColType()).
nTypeCode | the SQL_ code, such as SQL_CHAR. |
Referenced by DumpResult().