1. Data type:
Use the SQLGetTypeInfo function to obtain data type information that is supported by ODBC 3.0. The data type returned by SQLGetTypeInfo is the data type supported by the data source.
Sqlreturn SQLGetTypeInfo ( sqlhstmt statementhandle, sqlsmallint DataType);
Where the datatype type is one of the SQL Data types, see
https://msdn.microsoft.com/en-us/library/ms710150 (v=vs.85). aspx
You also need to understand the correspondence between the SQL data type and the C data type:
C type identifier |
ODBC C typedef |
C type |
Sql_c_char |
SQLCHAR * |
unsigned char * |
SQL_C_SSHORT[J] |
Sqlsmallint |
Short int |
SQL_C_USHORT[J] |
Sqlusmallint |
unsigned short int |
SQL_C_SLONG[J] |
Sqlinteger |
Long int |
SQL_C_ULONG[J] |
Sqluinteger |
unsigned long int |
Sql_c_float |
Sqlreal |
Float |
Sql_c_double |
SqlDouble, Sqlfloat |
Double |
Sql_c_bookmark[i] |
BOOKMARK |
unsigned long int[d] |
Sql_c_varbookmark |
SQLCHAR * |
unsigned char * |
SQL_C_TYPE_DATE[C] |
Sql_date_struct |
struct Tagdate_struct { Sqlsmallint year; Sqlusmallint month; Sqlusmallint Day; } date_struct; A |
SQL_C_TYPE_TIME[C] |
Sql_time_struct |
struct Tagtime_struct { Sqlusmallint hour; Sqlusmallint minute; Sqlusmallint second; } time_struct; A |
SQL_C_TYPE_TIMESTAMP[C] |
Sql_timestamp_struct |
struct Tagtimestamp_struct { Sqlsmallint year; Sqlusmallint month; Sqlusmallint Day; Sqlusmallint hour; Sqlusmallint minute; Sqlusmallint second; Sqluinteger fraction; [b] } timestamp_struct; A |
2. Common interface:
The following function is used to connect to the data source:
(1) Sqlallochandle: Assign an environment, a connection, a statement, or a handle to a descriptor.
(2) SQLConnect: Establish a connection to the driver or data source. A connection handle that accesses a data source contains all the connection information that includes status, transaction declarations, and error information.
(3) SQLDriverConnect: Similar to SQLConnect, used to connect to a driver or data source. But it has more connection information than SQLConnect support data source;
(4) SQLBrowseConnect: Supports an interactive method to retrieve or list the attributes and property values required to connect to a data source.
- Get driver and data source information
The following functions are used to obtain driver and data source information:
(1) Sqldatasources: can be called multiple times to get the name of all data sources used by the application.
(2) Sqldrivers: Returns all installed driver manifests, including descriptions of them and attribute keywords.
(3) SQLGetInfo: Returns meta information for the connected driver and data source.
(4) SQLGetFunctions: Returns information about whether a particular function is supported by the specified driver.
(5) SQLGetTypeInfo: Returns information for the data type supported by the specified data source.
- Set or get driver properties
The following function is used to set or get the driver properties:
(1) SQLSetConnectAttr: Sets the value of the Connection property.
(2) Sqlgetconnectattr: Returns the value of the Connection property.
(3) SQLSetEnvAttr: Sets the ambient property value.
(4) Sqlgetenvattr: Returns the ambient property value.
(5) SQLSetStmtAttr: Sets the statement property value.
(6) Sqlgetstmtattr: Returns the value of the statement property.
- Set or Get Descriptor fields
The following function is used to set or get the Descriptor field:
(1) Sqlgetdescfield: Returns the value of a single descriptor field.
(2) Sqlgetdescrec: Returns the value of multiple fields for the current descriptor record.
(3) Sqlsetdescfield: Sets the value of a single descriptor field.
(4) Sqlsetdescrec: Sets multiple fields for descriptor records.
The following function is used to prepare the SQL statement:
(1) SQLPrepare: Prepare the SQL statement to execute.
(2) SQLBindParameter: A buffer that allocates parameters in an SQL statement.
(3) SQLGetCursorName: Returns the name of the cursor associated with the statement handle.
(4) SQLSetCursorName: Sets the name of the cursor associated with the statement handle.
(5) Sqlsetscrolloptions: Set options for controlling cursor behavior, replaced by SQLGetInfo and SQLSETSTMTATTR interfaces in ODBC 3.0
The following function is used to submit a SQL request:
(1) SQLExecute: Work with SQLPrepare to execute prepared SQL statements.
(2) SQLExecDirect: Executes an SQL statement.
(3) Sqlnativesql: Returns the driver's translation of an SQL statement and does not execute the SQL statement.
(4) SQLDescribeParam: Returns a description of the specified parameter in the SQL statement.
(5) Sqlnumparams: Returns the number of arguments in the SQL statement.
(6) SQLParamData: Used in conjunction with SQLPutData to assign values to parameters at run time.
(7) SQLPutData: Assign values to some or all of the parameters while the SQL statement is running.
- Retrieving result sets and their related information
The following function is used to retrieve the result set and its related information:
(1) SQLRowCount: Returns the number of rows affected by a statement such as INSERT, UPDATE, or delete.
(2) Sqlnumresultcols: Returns the number of columns in the result set.
(3) SQLDescribeCol: Returns the descriptor record for the column in the result set.
(4) SQLColAttribute: Returns the properties of the columns in the result set.
(5) SQLBindCol: Allocates buffers for columns in the result set.
(6) SQLFetch: Retrieves the next row of tuples in the result set.
(7) SQLFetchScroll: Returns the specified result row.
(8) SQLGetData: Returns the value of a column in the current row of the result set.
(9) SQLSetPos: Sets the position of the cursor in the data set that is taken. The data in this recordset can be refreshed, updated, or deleted.
SQLBulkOperations: performs block insertion and block bookmark operations, including updating, deleting, or fetching data based on bookmarks.
(one) SQLMoreResults: Determines whether more result sets can be obtained, and the initialization of the next result set can be performed.
SQLGetDiagField: Returns a field value or a diagnostic data record.
SQLGetDiagRec: Returns multiple field values or a diagnostic data record.
- Get information about a data source system table
The following function is used to obtain information about the data source system table:
(1) Sqlcolumnprivileges: Returns a list of columns for the specified table and related permission information.
(2) SQLColumns: Returns a list of column information for the specified table.
(3) Sqlforeignkeys: Returns a list of foreign key information for the specified table.
(4) Sqlprimarykeys: Returns a list of the primary key information for the specified table.
(5) SQLProcedureColumns: Returns a list of parameter information for the specified stored procedure.
(6) SQLProcedures: Returns a list of stored procedure information for the specified data source.
(7) SQLSpecialColumns: Returns information that uniquely determines the column of a row, or automatically updates each column when a transaction modifies a row.
(8) SQLStatistics: Returns the relevant statistics and index information for a single table.
(9) Sqltableprivileges: Returns the names of the related tables and the associated permission information.
() SQLTables: Returns the table information from the specified data source.
- Terminating statement execution
The following function is used to terminate statement execution:
(1) SQLFreeStmt: Terminates the execution of the statement, closes all related cursors, discards the uncommitted results, and chooses to release the resource associated with the specified statement handle.
(2) SQLCloseCursor: Closes an open cursor, discarding the result without a commit.
(3) SqlCancel: Discards execution of an SQL statement.
(4) SQLEndTran: Commit or roll back the transaction.
The following function handles the task of interrupting the connection:
(1) SQLDisconnect: Closes the specified connection.
(2) Sqlfreehandle: Releases the environment, connection, statement, or descriptor handle.
Reference:
https://msdn.microsoft.com/en-us/library/ms714562 (v=vs.85). aspx
Http://www.cnblogs.com/huzhongzhong/archive/2011/07/12/2104209.html
Introduction to the ODBC API