2008. 6. 28. 14:38

Connector/ODBC Reference

23.1.6. Connector/ODBC Reference

This section provides reference material for the Connector/ODBC API, showing supported functions and methods, supported MySQL column types and the corresponding native type in Connector/ODBC, and the error codes returned by Connector/ODBC when a fault occurs.

23.1.6.1. Connector/ODBC API Reference

This section summarizes ODBC routines, categorized by functionality.

For the complete ODBC API reference, please refer to the ODBC Programer's Reference at http://msdn.microsoft.com/library/en-us/odbc/htm/odbcabout_this_manual.asp.

An application can call SQLGetInfo function to obtain conformance information about Connector/ODBC. To obtain information about support for a specific function in the driver, an application can call SQLGetFunctions.

Note

For backward compatibility, the Connector/ODBC 3.51 driver supports all deprecated functions.

The following tables list Connector/ODBC API calls grouped by task:

Connecting to a data source:

Function name C/ODBC 3.51 Standard Purpose
SQLAllocHandle Yes ISO 92 Obtains an environment, connection, statement, or descriptor handle.
SQLConnect Yes ISO 92 Connects to a specific driver by data source name, user ID, and password.
SQLDriverConnect Yes ODBC Connects to a specific driver by connection string or requests that the Driver Manager and driver display connection dialog boxes for the user.
SQLAllocEnv Yes Deprecated Obtains an environment handle allocated from driver.
SQLAllocConnect Yes Deprecated Obtains a connection handle

Obtaining information about a driver and data source:

Function name C/ODBC 3.51 Standard Purpose
SQLDataSources No ISO 92 Returns the list of available data sources, handled by the Driver Manager
SQLDrivers No ODBC Returns the list of installed drivers and their attributes, handles by Driver Manager
SQLGetInfo Yes ISO 92 Returns information about a specific driver and data source.
SQLGetFunctions Yes ISO 92 Returns supported driver functions.
SQLGetTypeInfo Yes ISO 92 Returns information about supported data types.

Setting and retrieving driver attributes:

Function name C/ODBC 3.51 Standard Purpose
SQLSetConnectAttr Yes ISO 92 Sets a connection attribute.
SQLGetConnectAttr Yes ISO 92 Returns the value of a connection attribute.
SQLSetConnectOption Yes Deprecated Sets a connection option
SQLGetConnectOption Yes Deprecated Returns the value of a connection option
SQLSetEnvAttr Yes ISO 92 Sets an environment attribute.
SQLGetEnvAttr Yes ISO 92 Returns the value of an environment attribute.
SQLSetStmtAttr Yes ISO 92 Sets a statement attribute.
SQLGetStmtAttr Yes ISO 92 Returns the value of a statement attribute.
SQLSetStmtOption Yes Deprecated Sets a statement option
SQLGetStmtOption Yes Deprecated Returns the value of a statement option

Preparing SQL requests:

Function name C/ODBC 3.51 Standard Purpose
SQLAllocStmt Yes Deprecated Allocates a statement handle
SQLPrepare Yes ISO 92 Prepares an SQL statement for later execution.
SQLBindParameter Yes ODBC Assigns storage for a parameter in an SQL statement.
SQLGetCursorName Yes ISO 92 Returns the cursor name associated with a statement handle.
SQLSetCursorName Yes ISO 92 Specifies a cursor name.
SQLSetScrollOptions Yes ODBC Sets options that control cursor behavior.

Submitting requests:

Function name C/ODBC 3.51 Standard Purpose
SQLExecute Yes ISO 92 Executes a prepared statement.
SQLExecDirect Yes ISO 92 Executes a statement
SQLNativeSql Yes ODBC Returns the text of an SQL statement as translated by the driver.
SQLDescribeParam Yes ODBC Returns the description for a specific parameter in a statement.
SQLNumParams Yes ISO 92 Returns the number of parameters in a statement.
SQLParamData Yes ISO 92 Used in conjunction with SQLPutData to supply parameter data at execution time. (Useful for long data values.)
SQLPutData Yes ISO 92 Sends part or all of a data value for a parameter. (Useful for long data values.)

Retrieving results and information about results:

Function name C/ODBC 3.51 Standard Purpose
SQLRowCount Yes ISO 92 Returns the number of rows affected by an insert, update, or delete request.
SQLNumResultCols Yes ISO 92 Returns the number of columns in the result set.
SQLDescribeCol Yes ISO 92 Describes a column in the result set.
SQLColAttribute Yes ISO 92 Describes attributes of a column in the result set.
SQLColAttributes Yes Deprecated Describes attributes of a column in the result set.
SQLFetch Yes ISO 92 Returns multiple result rows.
SQLFetchScroll Yes ISO 92 Returns scrollable result rows.
SQLExtendedFetch Yes Deprecated Returns scrollable result rows.
SQLSetPos Yes ODBC Positions a cursor within a fetched block of data and allows an application to refresh data in the rowset or to update or delete data in the result set.
SQLBulkOperations Yes ODBC Performs bulk insertions and bulk bookmark operations, including update, delete, and fetch by bookmark.

Retrieving error or diagnostic information:

Function name C/ODBC 3.51 Standard Purpose
SQLError Yes Deprecated Returns additional error or status information
SQLGetDiagField Yes ISO 92 Returns additional diagnostic information (a single field of the diagnostic data structure).
SQLGetDiagRec Yes ISO 92 Returns additional diagnostic information (multiple fields of the diagnostic data structure).

Obtaining information about the data source's system tables (catalog functions) item:

Function name C/ODBC 3.51 Standard Purpose
SQLColumnPrivileges Yes ODBC Returns a list of columns and associated privileges for one or more tables.
SQLColumns Yes X/Open Returns the list of column names in specified tables.
SQLForeignKeys Yes ODBC Returns a list of column names that make up foreign keys, if they exist for a specified table.
SQLPrimaryKeys Yes ODBC Returns the list of column names that make up the primary key for a table.
SQLSpecialColumns Yes X/Open Returns information about the optimal set of columns that uniquely identifies a row in a specified table, or the columns that are automatically updated when any value in the row is updated by a transaction.
SQLStatistics Yes ISO 92 Returns statistics about a single table and the list of indexes associated with the table.
SQLTablePrivileges Yes ODBC Returns a list of tables and the privileges associated with each table.
SQLTables Yes X/Open Returns the list of table names stored in a specific data source.

Performing transactions:

Function name C/ODBC 3.51 Standard Purpose
SQLTransact Yes Deprecated Commits or rolls back a transaction
SQLEndTran Yes ISO 92 Commits or rolls back a transaction.

Terminating a statement:

Function name C/ODBC 3.51 Standard Purpose
SQLFreeStmt Yes ISO 92 Ends statement processing, discards pending results, and, optionally, frees all resources associated with the statement handle.
SQLCloseCursor Yes ISO 92 Closes a cursor that has been opened on a statement handle.
SQLCancel Yes ISO 92 Cancels an SQL statement.

Terminating a connection:

Function name C/ODBC 3.51 Standard Purpose
SQLDisconnect Yes ISO 92 Closes the connection.
SQLFreeHandle Yes ISO 92 Releases an environment, connection, statement, or descriptor handle.
SQLFreeConnect Yes Deprecated Releases connection handle
SQLFreeEnv Yes Deprecated Releases an environment handle

23.1.6.2. Connector/ODBC Data Types

The following table illustrates how driver maps the server data types to default SQL and C data types:

Native Value SQL Type C Type
bigint unsigned SQL_BIGINT SQL_C_UBIGINT
bigint SQL_BIGINT SQL_C_SBIGINT
bit SQL_BIT SQL_C_BIT
bit SQL_CHAR SQL_C_CHAR
blob SQL_LONGVARBINARY SQL_C_BINARY
bool SQL_CHAR SQL_C_CHAR
char SQL_CHAR SQL_C_CHAR
date SQL_DATE SQL_C_DATE
datetime SQL_TIMESTAMP SQL_C_TIMESTAMP
decimal SQL_DECIMAL SQL_C_CHAR
double precision SQL_DOUBLE SQL_C_DOUBLE
double SQL_FLOAT SQL_C_DOUBLE
enum SQL_VARCHAR SQL_C_CHAR
float SQL_REAL SQL_C_FLOAT
int unsigned SQL_INTEGER SQL_C_ULONG
int SQL_INTEGER SQL_C_SLONG
integer unsigned SQL_INTEGER SQL_C_ULONG
integer SQL_INTEGER SQL_C_SLONG
long varbinary SQL_LONGVARBINARY SQL_C_BINARY
long varchar SQL_LONGVARCHAR SQL_C_CHAR
longblob SQL_LONGVARBINARY SQL_C_BINARY
longtext SQL_LONGVARCHAR SQL_C_CHAR
mediumblob SQL_LONGVARBINARY SQL_C_BINARY
mediumint unsigned SQL_INTEGER SQL_C_ULONG
mediumint SQL_INTEGER SQL_C_SLONG
mediumtext SQL_LONGVARCHAR SQL_C_CHAR
numeric SQL_NUMERIC SQL_C_CHAR
real SQL_FLOAT SQL_C_DOUBLE
set SQL_VARCHAR SQL_C_CHAR
smallint unsigned SQL_SMALLINT SQL_C_USHORT
smallint SQL_SMALLINT SQL_C_SSHORT
text SQL_LONGVARCHAR SQL_C_CHAR
time SQL_TIME SQL_C_TIME
timestamp SQL_TIMESTAMP SQL_C_TIMESTAMP
tinyblob SQL_LONGVARBINARY SQL_C_BINARY
tinyint unsigned SQL_TINYINT SQL_C_UTINYINT
tinyint SQL_TINYINT SQL_C_STINYINT
tinytext SQL_LONGVARCHAR SQL_C_CHAR
varchar SQL_VARCHAR SQL_C_CHAR
year SQL_SMALLINT SQL_C_SHORT

23.1.6.3. Connector/ODBC Error Codes

The following tables lists the error codes returned by the driver apart from the server errors.

Native Code SQLSTATE 2 SQLSTATE 3 Error Message
500 01000 01000 General warning
501 01004 01004 String data, right truncated
502 01S02 01S02 Option value changed
503 01S03 01S03 No rows updated/deleted
504 01S04 01S04 More than one row updated/deleted
505 01S06 01S06 Attempt to fetch before the result set returned the first row set
506 07001 07002 SQLBindParameter not used for all parameters
507 07005 07005 Prepared statement not a cursor-specification
508 07009 07009 Invalid descriptor index
509 08002 08002 Connection name in use
510 08003 08003 Connection does not exist
511 24000 24000 Invalid cursor state
512 25000 25000 Invalid transaction state
513 25S01 25S01 Transaction state unknown
514 34000 34000 Invalid cursor name
515 S1000 HY000 General driver defined error
516 S1001 HY001 Memory allocation error
517 S1002 HY002 Invalid column number
518 S1003 HY003 Invalid application buffer type
519 S1004 HY004 Invalid SQL data type
520 S1009 HY009 Invalid use of null pointer
521 S1010 HY010 Function sequence error
522 S1011 HY011 Attribute can not be set now
523 S1012 HY012 Invalid transaction operation code
524 S1013 HY013 Memory management error
525 S1015 HY015 No cursor name available
526 S1024 HY024 Invalid attribute value
527 S1090 HY090 Invalid string or buffer length
528 S1091 HY091 Invalid descriptor field identifier
529 S1092 HY092 Invalid attribute/option identifier
530 S1093 HY093 Invalid parameter number
531 S1095 HY095 Function type out of range
532 S1106 HY106 Fetch type out of range
533 S1117 HY117 Row value out of range
534 S1109 HY109 Invalid cursor position
535 S1C00 HYC00 Optional feature not implemented
0 21S01 21S01 Column count does not match value count
0 23000 23000 Integrity constraint violation
0 42000 42000 Syntax error or access violation
0 42S02 42S02 Base table or view not found
0 42S12 42S12 Index not found
0 42S21 42S21 Column already exists
0 42S22 42S22 Column not found
0 08S01 08S01 Communication link failure


출처 : MySQL 5.0 Reference Manaual