{ +-------------------------------------------------------------+ }
{ |                                                             | }
{ |   GM-Software                                               | }
{ |   ===========                                               | }
{ |                                                             | }
{ |   Project: DB Projects                                      | }
{ |                                                             | }
{ |   Description: ODBC call level API.                         | }
{ |                                                             | }
{ |                                                             | }
{ |   Copyright (C) - 1998 - Gerrit Moeller.                    | }
{ |                                                             | }
{ |   Source code dstributed under MIT license.                 | }
{ |                                                             | }
{ |   See: https://www.gm-software.de                           | }
{ |                                                             | }
{ +-------------------------------------------------------------+ }

{$INCLUDE GMCompilerSettings.inc}

//
// 64 Bit changes: https://docs.microsoft.com/de-de/sql/odbc/reference/odbc-64-bit-information?view=sql-server-2017
//

unit GMOdbcAPI;

interface

uses GMStrDef, GMIntf, GMCommon, GMSql;

const

  {$EXTERNALSYM SQL_FALSE}
  SQL_FALSE                                         = 0;
  {$EXTERNALSYM SQL_TRUE}
  SQL_TRUE                                          = 1;

  {$EXTERNALSYM SQL_NULL_DATA}
  SQL_NULL_DATA                                     = -1;
  {$EXTERNALSYM SQL_DATA_AT_EXEC}
  SQL_DATA_AT_EXEC                                  = -2;
  {$EXTERNALSYM SQL_NO_TOTAL}
  SQL_NO_TOTAL                                      = -4;
  {$EXTERNALSYM SQL_IGNORE}
  SQL_IGNORE                                        = -6;
  {$EXTERNALSYM SQL_COLUMN_IGNORE}
  SQL_COLUMN_IGNORE                                 = SQL_IGNORE;


  {$EXTERNALSYM SQL_OV_ODBC2}
  SQL_OV_ODBC2                                      = $00000002;
  {$EXTERNALSYM SQL_OV_ODBC3}
  SQL_OV_ODBC3                                      = $00000003;

  {$EXTERNALSYM SQL_OIC_CORE}
  SQL_OIC_CORE                                      = 1;
  {$EXTERNALSYM SQL_OIC_LEVEL1}
  SQL_OIC_LEVEL1                                    = 2;
  {$EXTERNALSYM SQL_OIC_LEVEL2}
  SQL_OIC_LEVEL2                                    = 3;

  {$EXTERNALSYM SQL_ATTR_ANSI_APP}
  SQL_ATTR_ANSI_APP                                 = 115;
  {$EXTERNALSYM SQL_AA_TRUE}
  SQL_AA_TRUE                                       = 1;
  {$EXTERNALSYM SQL_AA_FALSE}
  SQL_AA_FALSE                                      = 0;

  {$EXTERNALSYM SQL_ATTR_ODBC_VERSION}
  SQL_ATTR_ODBC_VERSION                             = 200;
  {$EXTERNALSYM SQL_ATTR_CONNECTION_POOLING}
  SQL_ATTR_CONNECTION_POOLING                       = 201;
  {$EXTERNALSYM SQL_ATTR_CP_MATCH}
  SQL_ATTR_CP_MATCH                                 = 202;

  {$EXTERNALSYM SQL_SUCCESS}
  SQL_SUCCESS                                       = 0;
  {$EXTERNALSYM SQL_SUCCESS_WITH_INFO}
  SQL_SUCCESS_WITH_INFO                             = 1;
  {$EXTERNALSYM SQL_NO_DATA}
  SQL_NO_DATA                                       = 100;
  {$EXTERNALSYM SQL_ERROR}
  SQL_ERROR                                         = -1;
  {$EXTERNALSYM SQL_INVALID_HANDLE}
  SQL_INVALID_HANDLE                                = -2;

  {$EXTERNALSYM SQL_STILL_EXECUTING}
  SQL_STILL_EXECUTING                               = 2;
  {$EXTERNALSYM SQL_NEED_DATA}
  SQL_NEED_DATA                                     = 99;

  {$EXTERNALSYM SQL_NTS}
  SQL_NTS                                           = -3;
  {$EXTERNALSYM SQL_NTSL}
  SQL_NTSL                                          = $FFFFFFFD;

  {$EXTERNALSYM SQL_MAX_MESSAGE_LENGTH}
  SQL_MAX_MESSAGE_LENGTH                            = 512;

  {$EXTERNALSYM SQL_DATE_LEN}
  SQL_DATE_LEN                                      = 10;
  {$EXTERNALSYM SQL_TIME_LEN}
  SQL_TIME_LEN                                      = 8;
  {$EXTERNALSYM SQL_TIMESTAMP_LEN}
  SQL_TIMESTAMP_LEN                                 = 19;

  {$EXTERNALSYM SQL_HANDLE_ENV}
  SQL_HANDLE_ENV                                    = 1;
  {$EXTERNALSYM SQL_HANDLE_DBC}
  SQL_HANDLE_DBC                                    = 2;
  {$EXTERNALSYM SQL_HANDLE_STMT}
  SQL_HANDLE_STMT                                   = 3;
  {$EXTERNALSYM SQL_HANDLE_DESC}
  SQL_HANDLE_DESC                                   = 4;

  {$EXTERNALSYM SQL_ATTR_OUTPUT_NTS}
  SQL_ATTR_OUTPUT_NTS                               = 10001;
  {$EXTERNALSYM SQL_ATTR_AUTO_IPD}
  SQL_ATTR_AUTO_IPD                                 = 10001;
  {$EXTERNALSYM SQL_ATTR_METADATA_ID}
  SQL_ATTR_METADATA_ID                              = 10014;
  {$EXTERNALSYM SQL_ATTR_APP_ROW_DESC}
  SQL_ATTR_APP_ROW_DESC                             = 10010;
  {$EXTERNALSYM SQL_ATTR_APP_PARAM_DESC}
  SQL_ATTR_APP_PARAM_DESC                           = 10011;
  {$EXTERNALSYM SQL_ATTR_IMP_ROW_DESC}
  SQL_ATTR_IMP_ROW_DESC                             = 10012;
  {$EXTERNALSYM SQL_ATTR_IMP_PARAM_DESC}
  SQL_ATTR_IMP_PARAM_DESC                           = 10013;
  {$EXTERNALSYM SQL_ATTR_CURSOR_SCROLLABLE}
  SQL_ATTR_CURSOR_SCROLLABLE                        = -1;
  {$EXTERNALSYM SQL_ATTR_CURSOR_SENSITIVITY}
  SQL_ATTR_CURSOR_SENSITIVITY                       = -2;

  {$EXTERNALSYM SQL_METADATA_ID_DEFAULT}
  SQL_METADATA_ID_DEFAULT                           = SQL_FALSE;
  {$EXTERNALSYM SQL_OUTPUT_NTS_DEFAULT}
  SQL_OUTPUT_NTS_DEFAULT                            = SQL_TRUE;

  {$EXTERNALSYM SQL_NONSCROLLABLE}
  SQL_NONSCROLLABLE                                 = 0;
  {$EXTERNALSYM SQL_SCROLLABLE}
  SQL_SCROLLABLE                                    = 1;
  {$EXTERNALSYM SQL_SCROLLABLE_DEFAULT}
  SQL_SCROLLABLE_DEFAULT                            = SQL_NONSCROLLABLE;


  {$EXTERNALSYM SQL_DIAG_RETURNCODE}
  SQL_DIAG_RETURNCODE                               = 1;
  {$EXTERNALSYM SQL_DIAG_NUMBER}
  SQL_DIAG_NUMBER                                   = 2;
  {$EXTERNALSYM SQL_DIAG_ROW_COUNT}
  SQL_DIAG_ROW_COUNT                                = 3;
  {$EXTERNALSYM SQL_DIAG_SQLSTATE}
  SQL_DIAG_SQLSTATE                                 = 4;
  {$EXTERNALSYM SQL_DIAG_NATIVE}
  SQL_DIAG_NATIVE                                   = 5;
  {$EXTERNALSYM SQL_DIAG_MESSAGE_TEXT}
  SQL_DIAG_MESSAGE_TEXT                             = 6;
  {$EXTERNALSYM SQL_DIAG_DYNAMIC_FUNCTION}
  SQL_DIAG_DYNAMIC_FUNCTION                         = 7;
  {$EXTERNALSYM SQL_DIAG_CLASS_ORIGIN}
  SQL_DIAG_CLASS_ORIGIN                             = 8;
  {$EXTERNALSYM SQL_DIAG_SUBCLASS_ORIGIN}
  SQL_DIAG_SUBCLASS_ORIGIN                          = 9;
  {$EXTERNALSYM SQL_DIAG_CONNECTION_NAME}
  SQL_DIAG_CONNECTION_NAME                          = 10;
  {$EXTERNALSYM SQL_DIAG_SERVER_NAME}
  SQL_DIAG_SERVER_NAME                              = 11;
  {$EXTERNALSYM SQL_DIAG_DYNAMIC_FUNCTION_CODE}
  SQL_DIAG_DYNAMIC_FUNCTION_CODE                    = 12;
  {$EXTERNALSYM SQL_DIAG_ALTER_TABLE}
  SQL_DIAG_ALTER_TABLE                              = 4;
  {$EXTERNALSYM SQL_DIAG_CREATE_INDEX}
  SQL_DIAG_CREATE_INDEX                             = -1;
  {$EXTERNALSYM SQL_DIAG_CREATE_TABLE}
  SQL_DIAG_CREATE_TABLE                             = 77;
  {$EXTERNALSYM SQL_DIAG_CREATE_VIEW}
  SQL_DIAG_CREATE_VIEW                              = 84;
  {$EXTERNALSYM SQL_DIAG_DELETE_WHERE}
  SQL_DIAG_DELETE_WHERE                             = 19;
  {$EXTERNALSYM SQL_DIAG_DROP_INDEX}
  SQL_DIAG_DROP_INDEX                               = -2;
  {$EXTERNALSYM SQL_DIAG_DROP_TABLE}
  SQL_DIAG_DROP_TABLE                               = 32;
  {$EXTERNALSYM SQL_DIAG_DROP_VIEW}
  SQL_DIAG_DROP_VIEW                                = 36;
  {$EXTERNALSYM SQL_DIAG_DYNAMIC_DELETE_CURSOR}
  SQL_DIAG_DYNAMIC_DELETE_CURSOR                    = 38;
  {$EXTERNALSYM SQL_DIAG_DYNAMIC_UPDATE_CURSOR}
  SQL_DIAG_DYNAMIC_UPDATE_CURSOR                    = 81;
  {$EXTERNALSYM SQL_DIAG_GRANT}
  SQL_DIAG_GRANT                                    = 48;
  {$EXTERNALSYM SQL_DIAG_INSERT}
  SQL_DIAG_INSERT                                   = 50;
  {$EXTERNALSYM SQL_DIAG_REVOKE}
  SQL_DIAG_REVOKE                                   = 59;
  {$EXTERNALSYM SQL_DIAG_SELECT_CURSOR}
  SQL_DIAG_SELECT_CURSOR                            = 85;
  {$EXTERNALSYM SQL_DIAG_UNKNOWN_STATEMENT}
  SQL_DIAG_UNKNOWN_STATEMENT                        = 0;
  {$EXTERNALSYM SQL_DIAG_UPDATE_WHERE}
  SQL_DIAG_UPDATE_WHERE                             = 82;

  {$EXTERNALSYM SQL_INTERVAL_BASE}
  SQL_INTERVAL_BASE                                 = 100;

  {$EXTERNALSYM SQL_CODE_YEAR}
  SQL_CODE_YEAR                                     = 1;
  {$EXTERNALSYM SQL_CODE_MONTH}
  SQL_CODE_MONTH                                    = 2;
  {$EXTERNALSYM SQL_CODE_DAY}
  SQL_CODE_DAY                                      = 3;
  {$EXTERNALSYM SQL_CODE_HOUR}
  SQL_CODE_HOUR                                     = 4;
  {$EXTERNALSYM SQL_CODE_MINUTE}
  SQL_CODE_MINUTE                                   = 5;
  {$EXTERNALSYM SQL_CODE_SECOND}
  SQL_CODE_SECOND                                   = 6;
  {$EXTERNALSYM SQL_CODE_YEAR_TO_MONTH}
  SQL_CODE_YEAR_TO_MONTH                            = 7;
  {$EXTERNALSYM SQL_CODE_DAY_TO_HOUR}
  SQL_CODE_DAY_TO_HOUR                              = 8;
  {$EXTERNALSYM SQL_CODE_DAY_TO_MINUTE}
  SQL_CODE_DAY_TO_MINUTE                            = 9;
  {$EXTERNALSYM SQL_CODE_DAY_TO_SECOND}
  SQL_CODE_DAY_TO_SECOND                            = 10;
  {$EXTERNALSYM SQL_CODE_HOUR_TO_MINUTE}
  SQL_CODE_HOUR_TO_MINUTE                           = 11;
  {$EXTERNALSYM SQL_CODE_HOUR_TO_SECOND}
  SQL_CODE_HOUR_TO_SECOND                           = 12;
  {$EXTERNALSYM SQL_CODE_MINUTE_TO_SECOND}
  SQL_CODE_MINUTE_TO_SECOND                         = 13;

  {$EXTERNALSYM SQL_INTERVAL_YEAR}
  SQL_INTERVAL_YEAR                                 = SQL_INTERVAL_BASE + SQL_CODE_YEAR;
  {$EXTERNALSYM SQL_INTERVAL_MONTH}
  SQL_INTERVAL_MONTH                                = SQL_INTERVAL_BASE + SQL_CODE_MONTH;
  {$EXTERNALSYM SQL_INTERVAL_DAY}
  SQL_INTERVAL_DAY                                  = SQL_INTERVAL_BASE + SQL_CODE_DAY;
  {$EXTERNALSYM SQL_INTERVAL_HOUR}
  SQL_INTERVAL_HOUR                                 = SQL_INTERVAL_BASE + SQL_CODE_HOUR;
  {$EXTERNALSYM SQL_INTERVAL_MINUTE}
  SQL_INTERVAL_MINUTE                               = SQL_INTERVAL_BASE + SQL_CODE_MINUTE;
  {$EXTERNALSYM SQL_INTERVAL_SECOND}
  SQL_INTERVAL_SECOND                               = SQL_INTERVAL_BASE + SQL_CODE_SECOND;
  {$EXTERNALSYM SQL_INTERVAL_YEAR_TO_MONTH}
  SQL_INTERVAL_YEAR_TO_MONTH                        = SQL_INTERVAL_BASE + SQL_CODE_YEAR_TO_MONTH;
  {$EXTERNALSYM SQL_INTERVAL_DAY_TO_HOUR}
  SQL_INTERVAL_DAY_TO_HOUR                          = SQL_INTERVAL_BASE + SQL_CODE_DAY_TO_HOUR;
  {$EXTERNALSYM SQL_INTERVAL_DAY_TO_MINUTE}
  SQL_INTERVAL_DAY_TO_MINUTE                        = SQL_INTERVAL_BASE + SQL_CODE_DAY_TO_MINUTE;
  {$EXTERNALSYM SQL_INTERVAL_DAY_TO_SECOND}
  SQL_INTERVAL_DAY_TO_SECOND                        = SQL_INTERVAL_BASE + SQL_CODE_DAY_TO_SECOND;
  {$EXTERNALSYM SQL_INTERVAL_HOUR_TO_MINUTE}
  SQL_INTERVAL_HOUR_TO_MINUTE                       = SQL_INTERVAL_BASE + SQL_CODE_HOUR_TO_MINUTE;
  {$EXTERNALSYM SQL_INTERVAL_HOUR_TO_SECOND}
  SQL_INTERVAL_HOUR_TO_SECOND                       = SQL_INTERVAL_BASE + SQL_CODE_HOUR_TO_SECOND;
  {$EXTERNALSYM SQL_INTERVAL_MINUTE_TO_SECOND}
  SQL_INTERVAL_MINUTE_TO_SECOND                     = SQL_INTERVAL_BASE + SQL_CODE_MINUTE_TO_SECOND;

  {$EXTERNALSYM SQL_UNKNOWN_TYPE}
  SQL_UNKNOWN_TYPE                                  = 0;
  {$EXTERNALSYM SQL_CHAR}
  SQL_CHAR                                          = 1;
  {$EXTERNALSYM SQL_NUMERIC}
  SQL_NUMERIC                                       = 2;
  {$EXTERNALSYM SQL_DECIMAL}
  SQL_DECIMAL                                       = 3;
  {$EXTERNALSYM SQL_INTEGER}
  SQL_INTEGER                                       = 4;
  {$EXTERNALSYM SQL_SMALLINT}
  SQL_SMALLINT                                      = 5;
  {$EXTERNALSYM SQL_FLOAT}
  SQL_FLOAT                                         = 6;
  {$EXTERNALSYM SQL_REAL}
  SQL_REAL                                          = 7;
  {$EXTERNALSYM SQL_DOUBLE}
  SQL_DOUBLE                                        = 8;
  {$EXTERNALSYM SQL_DATE}
  SQL_DATE                                          = 9;
  {$EXTERNALSYM SQL_INTERVAL}
  SQL_INTERVAL                                      = 10;
  {$EXTERNALSYM SQL_TIME}
  SQL_TIME                                          = 10;
  {$EXTERNALSYM SQL_TIMESTAMP}
  SQL_TIMESTAMP                                     = 11;
  {$EXTERNALSYM SQL_VARCHAR}
  SQL_VARCHAR                                       = 12;
  {$EXTERNALSYM SQL_TYPE_DATE}
  SQL_TYPE_DATE                                     = 91;
  {$EXTERNALSYM SQL_TYPE_TIME}
  SQL_TYPE_TIME                                     = 92;
  {$EXTERNALSYM SQL_TYPE_TIMESTAMP}
  SQL_TYPE_TIMESTAMP                                = 93;
  {$EXTERNALSYM SQL_LONGVARCHAR}
  SQL_LONGVARCHAR                                   = -1;
  {$EXTERNALSYM SQL_BINARY}
  SQL_BINARY                                        = -2;
  {$EXTERNALSYM SQL_VARBINARY}
  SQL_VARBINARY                                     = -3;
  {$EXTERNALSYM SQL_LONGVARBINARY}
  SQL_LONGVARBINARY                                 = -4;
  {$EXTERNALSYM SQL_BIGINT}
  SQL_BIGINT                                        = -5;
  {$EXTERNALSYM SQL_TINYINT}
  SQL_TINYINT                                       = -6;
  {$EXTERNALSYM SQL_BIT}
  SQL_BIT                                           = -7;
  {$EXTERNALSYM SQL_WCHAR}
  SQL_WCHAR                                         = -8;
  {$EXTERNALSYM SQL_WVARCHAR}
  SQL_WVARCHAR                                      = -9;
  {$EXTERNALSYM SQL_WLONGVARCHAR}
  SQL_WLONGVARCHAR                                  = -10;
  {$EXTERNALSYM SQL_GUID}
  SQL_GUID                                          = -11;

  {$EXTERNALSYM SQL_SIGNED_OFFSET}
  SQL_SIGNED_OFFSET                                 = -20;
  {$EXTERNALSYM SQL_UNSIGNED_OFFSET}
  SQL_UNSIGNED_OFFSET                               = -22;

  {$EXTERNALSYM SQL_C_DEFAULT}
  SQL_C_DEFAULT                                     = 99;
  {$EXTERNALSYM SQL_C_CHAR}
  SQL_C_CHAR                                        = SQL_CHAR;
  {$EXTERNALSYM SQL_C_WCHAR}
  SQL_C_WCHAR                                       = SQL_WCHAR;
  {$EXTERNALSYM SQL_C_LONG}
  SQL_C_LONG                                        = SQL_INTEGER;
  {$EXTERNALSYM SQL_C_SHORT}
  SQL_C_SHORT                                       = SQL_SMALLINT;
  {$EXTERNALSYM SQL_C_FLOAT}
  SQL_C_FLOAT                                       = SQL_REAL;
  {$EXTERNALSYM SQL_C_DOUBLE}
  SQL_C_DOUBLE                                      = SQL_DOUBLE;
  {$EXTERNALSYM SQL_C_NUMERIC}
  SQL_C_NUMERIC                                     = SQL_NUMERIC;
  {$EXTERNALSYM SQL_C_DATE}
  SQL_C_DATE                                        = SQL_DATE;
  {$EXTERNALSYM SQL_C_TIME}
  SQL_C_TIME                                        = SQL_TIME;
  {$EXTERNALSYM SQL_C_TIMESTAMP}
  SQL_C_TIMESTAMP                                   = SQL_TIMESTAMP;
  {$EXTERNALSYM SQL_C_TYPE_DATE}
  SQL_C_TYPE_DATE                                   = SQL_TYPE_DATE;
  {$EXTERNALSYM SQL_C_TYPE_TIME}
  SQL_C_TYPE_TIME                                   = SQL_TYPE_TIME;
  {$EXTERNALSYM SQL_C_TYPE_TIMESTAMP}
  SQL_C_TYPE_TIMESTAMP                              = SQL_TYPE_TIMESTAMP;
  {$EXTERNALSYM SQL_C_INTERVAL_YEAR}
  SQL_C_INTERVAL_YEAR                               = SQL_INTERVAL_YEAR;
  {$EXTERNALSYM SQL_C_INTERVAL_MONTH}
  SQL_C_INTERVAL_MONTH                              = SQL_INTERVAL_MONTH;
  {$EXTERNALSYM SQL_C_INTERVAL_DAY}
  SQL_C_INTERVAL_DAY                                = SQL_INTERVAL_DAY;
  {$EXTERNALSYM SQL_C_INTERVAL_HOUR}
  SQL_C_INTERVAL_HOUR                               = SQL_INTERVAL_HOUR;
  {$EXTERNALSYM SQL_C_INTERVAL_MINUTE}
  SQL_C_INTERVAL_MINUTE                             = SQL_INTERVAL_MINUTE;
  {$EXTERNALSYM SQL_C_INTERVAL_SECOND}
  SQL_C_INTERVAL_SECOND                             = SQL_INTERVAL_SECOND;
  {$EXTERNALSYM SQL_C_INTERVAL_YEAR_TO_MONTH}
  SQL_C_INTERVAL_YEAR_TO_MONTH                      = SQL_INTERVAL_YEAR_TO_MONTH;
  {$EXTERNALSYM SQL_C_INTERVAL_DAY_TO_HOUR}
  SQL_C_INTERVAL_DAY_TO_HOUR                        = SQL_INTERVAL_DAY_TO_HOUR;
  {$EXTERNALSYM SQL_C_INTERVAL_DAY_TO_MINUTE}
  SQL_C_INTERVAL_DAY_TO_MINUTE                      = SQL_INTERVAL_DAY_TO_MINUTE;
  {$EXTERNALSYM SQL_C_INTERVAL_DAY_TO_SECOND}
  SQL_C_INTERVAL_DAY_TO_SECOND                      = SQL_INTERVAL_DAY_TO_SECOND;
  {$EXTERNALSYM SQL_C_INTERVAL_HOUR_TO_MINUTE}
  SQL_C_INTERVAL_HOUR_TO_MINUTE                     = SQL_INTERVAL_HOUR_TO_MINUTE;
  {$EXTERNALSYM SQL_C_INTERVAL_HOUR_TO_SECOND}
  SQL_C_INTERVAL_HOUR_TO_SECOND                     = SQL_INTERVAL_HOUR_TO_SECOND;
  {$EXTERNALSYM SQL_C_INTERVAL_MINUTE_TO_SECOND}
  SQL_C_INTERVAL_MINUTE_TO_SECOND                   = SQL_INTERVAL_MINUTE_TO_SECOND;
  {$EXTERNALSYM SQL_C_BINARY}
  SQL_C_BINARY                                      = SQL_BINARY;
  {$EXTERNALSYM SQL_C_BIT}
  SQL_C_BIT                                         = SQL_BIT;
  {$EXTERNALSYM SQL_C_BIGINT}
  SQL_C_BIGINT                                      = SQL_BIGINT;
  {$EXTERNALSYM SQL_C_SBIGINT}
  SQL_C_SBIGINT                                     = SQL_BIGINT + SQL_SIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_UBIGINT}
  SQL_C_UBIGINT                                     = SQL_BIGINT + SQL_UNSIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_TINYINT}
  SQL_C_TINYINT                                     = SQL_TINYINT;
  {$EXTERNALSYM SQL_C_SLONG}
  SQL_C_SLONG                                       = SQL_C_LONG + SQL_SIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_SSHORT}
  SQL_C_SSHORT                                      = SQL_C_SHORT + SQL_SIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_STINYINT}
  SQL_C_STINYINT                                    = SQL_TINYINT + SQL_SIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_ULONG}
  SQL_C_ULONG                                       = SQL_C_LONG + SQL_UNSIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_USHORT}
  SQL_C_USHORT                                      = SQL_C_SHORT + SQL_UNSIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_UTINYINT}
  SQL_C_UTINYINT                                    = SQL_TINYINT + SQL_UNSIGNED_OFFSET;
  {$EXTERNALSYM SQL_C_GUID}
  SQL_C_GUID                                        = SQL_GUID;
  {$EXTERNALSYM SQL_C_VARBOOKMARK}
  SQL_C_VARBOOKMARK                                 = SQL_C_BINARY;


{$IFDEF CPU64}
  {$EXTERNALSYM SQL_C_BOOKMARK}
  SQL_C_BOOKMARK                                    = SQL_C_UBIGINT;
{$ELSE}
  {$EXTERNALSYM SQL_C_BOOKMARK}
  SQL_C_BOOKMARK                                    = SQL_C_ULONG;
{$ENDIF}


  {$EXTERNALSYM SQL_UNSPECIFIED}
  SQL_UNSPECIFIED                                   = 0;
  {$EXTERNALSYM SQL_INSENSITIVE}
  SQL_INSENSITIVE                                   = 1;
  {$EXTERNALSYM SQL_SENSITIVE}
  SQL_SENSITIVE                                     = 2;
  {$EXTERNALSYM SQL_CURSOR_SENSITIVITY_DEFAULT}
  SQL_CURSOR_SENSITIVITY_DEFAULT                    = SQL_UNSPECIFIED;

  {$EXTERNALSYM SQL_ALL_TYPES}
  SQL_ALL_TYPES                                     = 0;

  {$EXTERNALSYM SQL_DEFAULT}
  SQL_DEFAULT                                       = 99;

  {$EXTERNALSYM SQL_ARD_TYPE}
  SQL_ARD_TYPE                                      = -99;

  {$EXTERNALSYM SQL_CODE_DATE}
  SQL_CODE_DATE                                     = 1;
  {$EXTERNALSYM SQL_CODE_TIME}
  SQL_CODE_TIME                                     = 2;
  {$EXTERNALSYM SQL_CODE_TIMESTAMP}
  SQL_CODE_TIMESTAMP                                = 3;

  {$EXTERNALSYM SQL_NO_NULLS}
  SQL_NO_NULLS                                      = 0;
  {$EXTERNALSYM SQL_NULLABLE}
  SQL_NULLABLE                                      = 1;
  {$EXTERNALSYM SQL_NULLABLE_UNKNOWN}
  SQL_NULLABLE_UNKNOWN                              = 2;

  {$EXTERNALSYM SQL_PRED_NONE}
  SQL_PRED_NONE                                     = 0;
  {$EXTERNALSYM SQL_PRED_CHAR}
  SQL_PRED_CHAR                                     = 1;
  {$EXTERNALSYM SQL_PRED_BASIC}
  SQL_PRED_BASIC                                    = 2;

  {$EXTERNALSYM SQL_NAMED}
  SQL_NAMED                                         = 0;
  {$EXTERNALSYM SQL_UNNAMED}
  SQL_UNNAMED                                       = 1;

  {$EXTERNALSYM SQL_DESC_ALLOC_AUTO}
  SQL_DESC_ALLOC_AUTO                               = 1;
  {$EXTERNALSYM SQL_DESC_ALLOC_USER}
  SQL_DESC_ALLOC_USER                               = 2;

  {$EXTERNALSYM SQL_CLOSE}
  SQL_CLOSE                                         = 0;
  {$EXTERNALSYM SQL_DROP}
  SQL_DROP                                          = 1;
  {$EXTERNALSYM SQL_UNBIND}
  SQL_UNBIND                                        = 2;
  {$EXTERNALSYM SQL_RESET_PARAMS}
  SQL_RESET_PARAMS                                  = 3;

  {$EXTERNALSYM SQL_FETCH_NEXT}
  SQL_FETCH_NEXT                                    = 1;
  {$EXTERNALSYM SQL_FETCH_FIRST}
  SQL_FETCH_FIRST                                   = 2;
  {$EXTERNALSYM SQL_FETCH_FIRST_USER}
  SQL_FETCH_FIRST_USER                              = 31;
  {$EXTERNALSYM SQL_FETCH_FIRST_SYSTEM}
  SQL_FETCH_FIRST_SYSTEM                            = 32;

  {$EXTERNALSYM SQL_FETCH_LAST}
  SQL_FETCH_LAST                                    = 3;
  {$EXTERNALSYM SQL_FETCH_PRIOR}
  SQL_FETCH_PRIOR                                   = 4;
  {$EXTERNALSYM SQL_FETCH_ABSOLUTE}
  SQL_FETCH_ABSOLUTE                                = 5;
  {$EXTERNALSYM SQL_FETCH_RELATIVE}
  SQL_FETCH_RELATIVE                                = 6;

  {$EXTERNALSYM SQL_COMMIT}
  SQL_COMMIT                                        = 0;
  {$EXTERNALSYM SQL_ROLLBACK}
  SQL_ROLLBACK                                      = 1;

  {$EXTERNALSYM SQL_NULL_HENV}
  SQL_NULL_HENV                                     = 0;
  {$EXTERNALSYM SQL_NULL_HDBC}
  SQL_NULL_HDBC                                     = 0;
  {$EXTERNALSYM SQL_NULL_HSTMT}
  SQL_NULL_HSTMT                                    = 0;
  {$EXTERNALSYM SQL_NULL_HDESC}
  SQL_NULL_HDESC                                    = 0;

  {$EXTERNALSYM SQL_NULL_HANDLE}
  SQL_NULL_HANDLE                                   = 0;

  {$EXTERNALSYM SQL_SCOPE_CURROW}
  SQL_SCOPE_CURROW                                  = 0;
  {$EXTERNALSYM SQL_SCOPE_TRANSACTION}
  SQL_SCOPE_TRANSACTION                             = 1;
  {$EXTERNALSYM SQL_SCOPE_SESSION}
  SQL_SCOPE_SESSION                                 = 2;

  {$EXTERNALSYM SQL_PC_UNKNOWN}
  SQL_PC_UNKNOWN                                    = 0;
  {$EXTERNALSYM SQL_PC_NOT_PSEUDO}
  SQL_PC_NOT_PSEUDO                                 = 1;
  {$EXTERNALSYM SQL_PC_PSEUDO}
  SQL_PC_PSEUDO                                     = 2;

  {$EXTERNALSYM SQL_ROW_IDENTIFIER}
  SQL_ROW_IDENTIFIER                                = 1;

  {$EXTERNALSYM SQL_INDEX_UNIQUE}
  SQL_INDEX_UNIQUE                                  = 0;
  {$EXTERNALSYM SQL_INDEX_ALL}
  SQL_INDEX_ALL                                     = 1;

  {$EXTERNALSYM SQL_TABLE_STAT}
  SQL_TABLE_STAT                                    = 0;

  {$EXTERNALSYM SQL_INDEX_CLUSTERED}
  SQL_INDEX_CLUSTERED                               = 1;
  {$EXTERNALSYM SQL_INDEX_HASHED}
  SQL_INDEX_HASHED                                  = 2;
  {$EXTERNALSYM SQL_INDEX_OTHER}
  SQL_INDEX_OTHER                                   = 3;

  {$EXTERNALSYM SQL_API_SQLALLOCCONNECT}
  SQL_API_SQLALLOCCONNECT                           = 1;
  {$EXTERNALSYM SQL_API_SQLALLOCENV}
  SQL_API_SQLALLOCENV                               = 2;
  {$EXTERNALSYM SQL_API_SQLALLOCHANDLE}
  SQL_API_SQLALLOCHANDLE                            = 1001;
  {$EXTERNALSYM SQL_API_SQLALLOCSTMT}
  SQL_API_SQLALLOCSTMT                              = 3;
  {$EXTERNALSYM SQL_API_SQLBINDCOL}
  SQL_API_SQLBINDCOL                                = 4;
  {$EXTERNALSYM SQL_API_SQLBINDPARAM}
  SQL_API_SQLBINDPARAM                              = 1002;
  {$EXTERNALSYM SQL_API_SQLCANCEL}
  SQL_API_SQLCANCEL                                 = 5;
  {$EXTERNALSYM SQL_API_SQLCLOSECURSOR}
  SQL_API_SQLCLOSECURSOR                            = 1003;
  {$EXTERNALSYM SQL_API_SQLCOLATTRIBUTE}
  SQL_API_SQLCOLATTRIBUTE                           = 6;
  {$EXTERNALSYM SQL_API_SQLCOLUMNS}
  SQL_API_SQLCOLUMNS                                = 40;
  {$EXTERNALSYM SQL_API_SQLCONNECT}
  SQL_API_SQLCONNECT                                = 7;
  {$EXTERNALSYM SQL_API_SQLCOPYDESC}
  SQL_API_SQLCOPYDESC                               = 1004;
  {$EXTERNALSYM SQL_API_SQLDATASOURCES}
  SQL_API_SQLDATASOURCES                            = 57;
  {$EXTERNALSYM SQL_API_SQLDESCRIBECOL}
  SQL_API_SQLDESCRIBECOL                            = 8;
  {$EXTERNALSYM SQL_API_SQLDISCONNECT}
  SQL_API_SQLDISCONNECT                             = 9;
  {$EXTERNALSYM SQL_API_SQLENDTRAN}
  SQL_API_SQLENDTRAN                                = 1005;
  {$EXTERNALSYM SQL_API_SQLERROR}
  SQL_API_SQLERROR                                  = 10;
  {$EXTERNALSYM SQL_API_SQLEXECDIRECT}
  SQL_API_SQLEXECDIRECT                             = 11;
  {$EXTERNALSYM SQL_API_SQLEXECUTE}
  SQL_API_SQLEXECUTE                                = 12;
  {$EXTERNALSYM SQL_API_SQLFETCH}
  SQL_API_SQLFETCH                                  = 13;
  {$EXTERNALSYM SQL_API_SQLFETCHSCROLL}
  SQL_API_SQLFETCHSCROLL                            = 1021;
  {$EXTERNALSYM SQL_API_SQLFREECONNECT}
  SQL_API_SQLFREECONNECT                            = 14;
  {$EXTERNALSYM SQL_API_SQLFREEENV}
  SQL_API_SQLFREEENV                                = 15;
  {$EXTERNALSYM SQL_API_SQLFREEHANDLE}
  SQL_API_SQLFREEHANDLE                             = 1006;
  {$EXTERNALSYM SQL_API_SQLFREESTMT}
  SQL_API_SQLFREESTMT                               = 16;
  {$EXTERNALSYM SQL_API_SQLGETCONNECTATTR}
  SQL_API_SQLGETCONNECTATTR                         = 1007;
  {$EXTERNALSYM SQL_API_SQLGETCONNECTOPTION}
  SQL_API_SQLGETCONNECTOPTION                       = 42;
  {$EXTERNALSYM SQL_API_SQLGETCURSORNAME}
  SQL_API_SQLGETCURSORNAME                          = 17;
  {$EXTERNALSYM SQL_API_SQLGETDATA}
  SQL_API_SQLGETDATA                                = 43;
  {$EXTERNALSYM SQL_API_SQLGETDESCFIELD}
  SQL_API_SQLGETDESCFIELD                           = 1008;
  {$EXTERNALSYM SQL_API_SQLGETDESCREC}
  SQL_API_SQLGETDESCREC                             = 1009;
  {$EXTERNALSYM SQL_API_SQLGETDIAGFIELD}
  SQL_API_SQLGETDIAGFIELD                           = 1010;
  {$EXTERNALSYM SQL_API_SQLGETDIAGREC}
  SQL_API_SQLGETDIAGREC                             = 1011;
  {$EXTERNALSYM SQL_API_SQLGETENVATTR}
  SQL_API_SQLGETENVATTR                             = 1012;
  {$EXTERNALSYM SQL_API_SQLGETFUNCTIONS}
  SQL_API_SQLGETFUNCTIONS                           = 44;
  {$EXTERNALSYM SQL_API_SQLGETINFO}
  SQL_API_SQLGETINFO                                = 45;
  {$EXTERNALSYM SQL_API_SQLGETSTMTATTR}
  SQL_API_SQLGETSTMTATTR                            = 1014;
  {$EXTERNALSYM SQL_API_SQLGETSTMTOPTION}
  SQL_API_SQLGETSTMTOPTION                          = 46;
  {$EXTERNALSYM SQL_API_SQLGETTYPEINFO}
  SQL_API_SQLGETTYPEINFO                            = 47;
  {$EXTERNALSYM SQL_API_SQLNUMRESULTCOLS}
  SQL_API_SQLNUMRESULTCOLS                          = 18;
  {$EXTERNALSYM SQL_API_SQLPARAMDATA}
  SQL_API_SQLPARAMDATA                              = 48;
  {$EXTERNALSYM SQL_API_SQLPREPARE}
  SQL_API_SQLPREPARE                                = 19;
  {$EXTERNALSYM SQL_API_SQLPUTDATA}
  SQL_API_SQLPUTDATA                                = 49;
  {$EXTERNALSYM SQL_API_SQLROWCOUNT}
  SQL_API_SQLROWCOUNT                               = 20;
  {$EXTERNALSYM SQL_API_SQLSETCONNECTATTR}
  SQL_API_SQLSETCONNECTATTR                         = 1016;
  {$EXTERNALSYM SQL_API_SQLSETCONNECTOPTION}
  SQL_API_SQLSETCONNECTOPTION                       = 50;
  {$EXTERNALSYM SQL_API_SQLSETCURSORNAME}
  SQL_API_SQLSETCURSORNAME                          = 21;
  {$EXTERNALSYM SQL_API_SQLSETDESCFIELD}
  SQL_API_SQLSETDESCFIELD                           = 1017;
  {$EXTERNALSYM SQL_API_SQLSETDESCREC}
  SQL_API_SQLSETDESCREC                             = 1018;
  {$EXTERNALSYM SQL_API_SQLSETENVATTR}
  SQL_API_SQLSETENVATTR                             = 1019;
  {$EXTERNALSYM SQL_API_SQLSETPARAM}
  SQL_API_SQLSETPARAM                               = 22;
  {$EXTERNALSYM SQL_API_SQLSETSTMTATTR}
  SQL_API_SQLSETSTMTATTR                            = 1020;
  {$EXTERNALSYM SQL_API_SQLSETSTMTOPTION}
  SQL_API_SQLSETSTMTOPTION                          = 51;
  {$EXTERNALSYM SQL_API_SQLSPECIALCOLUMNS}
  SQL_API_SQLSPECIALCOLUMNS                         = 52;
  {$EXTERNALSYM SQL_API_SQLSTATISTICS}
  SQL_API_SQLSTATISTICS                             = 53;
  {$EXTERNALSYM SQL_API_SQLTABLES}
  SQL_API_SQLTABLES                                 = 54;
  {$EXTERNALSYM SQL_API_SQLTRANSACT}
  SQL_API_SQLTRANSACT                               = 23;
  {$EXTERNALSYM SQL_API_SQLALLOCHANDLESTD}
  SQL_API_SQLALLOCHANDLESTD                             = 73;
  {$EXTERNALSYM SQL_API_SQLBULKOPERATIONS}
  SQL_API_SQLBULKOPERATIONS                             = 24;
  {$EXTERNALSYM SQL_API_SQLBINDPARAMETER}
  SQL_API_SQLBINDPARAMETER                          = 72;
  {$EXTERNALSYM SQL_API_SQLBROWSECONNECT}
  SQL_API_SQLBROWSECONNECT                          = 55;
  {$EXTERNALSYM SQL_API_SQLCOLATTRIBUTES}
  SQL_API_SQLCOLATTRIBUTES                          = 6;
  {$EXTERNALSYM SQL_API_SQLCOLUMNPRIVILEGES}
  SQL_API_SQLCOLUMNPRIVILEGES                       = 56;
  {$EXTERNALSYM SQL_API_SQLDESCRIBEPARAM}
  SQL_API_SQLDESCRIBEPARAM                          = 58;
  {$EXTERNALSYM SQL_API_SQLDRIVERCONNECT}
  SQL_API_SQLDRIVERCONNECT                              = 41;
  {$EXTERNALSYM SQL_API_SQLDRIVERS}
  SQL_API_SQLDRIVERS                                = 71;
  {$EXTERNALSYM SQL_API_SQLEXTENDEDFETCH}
  SQL_API_SQLEXTENDEDFETCH                          = 59;
  {$EXTERNALSYM SQL_API_SQLFOREIGNKEYS}
  SQL_API_SQLFOREIGNKEYS                            = 60;
  {$EXTERNALSYM SQL_API_SQLMORERESULTS}
  SQL_API_SQLMORERESULTS                            = 61;
  {$EXTERNALSYM SQL_API_SQLNATIVESQL}
  SQL_API_SQLNATIVESQL                              = 62;
  {$EXTERNALSYM SQL_API_SQLNUMPARAMS}
  SQL_API_SQLNUMPARAMS                              = 63;
  {$EXTERNALSYM SQL_API_SQLPARAMOPTIONS}
  SQL_API_SQLPARAMOPTIONS                           = 64;
  {$EXTERNALSYM SQL_API_SQLPRIMARYKEYS}
  SQL_API_SQLPRIMARYKEYS                            = 65;
  {$EXTERNALSYM SQL_API_SQLPROCEDURECOLUMNS}
  SQL_API_SQLPROCEDURECOLUMNS                       = 66;
  {$EXTERNALSYM SQL_API_SQLPROCEDURES}
  SQL_API_SQLPROCEDURES                             = 67;
  {$EXTERNALSYM SQL_API_SQLSETPOS}
  SQL_API_SQLSETPOS                                 = 68;
  {$EXTERNALSYM SQL_API_SQLSETSCROLLOPTIONS}
  SQL_API_SQLSETSCROLLOPTIONS                       = 69;
  {$EXTERNALSYM SQL_API_SQLTABLEPRIVILEGES}
  SQL_API_SQLTABLEPRIVILEGES                        = 70;


  {$EXTERNALSYM SQL_MAX_DRIVER_CONNECTIONS}
  SQL_MAX_DRIVER_CONNECTIONS                        = 0;
  {$EXTERNALSYM SQL_MAXIMUM_DRIVER_CONNECTIONS}
  SQL_MAXIMUM_DRIVER_CONNECTIONS                    = SQL_MAX_DRIVER_CONNECTIONS;
  {$EXTERNALSYM SQL_MAX_CONCURRENT_ACTIVITIES}
  SQL_MAX_CONCURRENT_ACTIVITIES                     = 1;
  {$EXTERNALSYM SQL_MAXIMUM_CONCURRENT_ACTIVITIES}
  SQL_MAXIMUM_CONCURRENT_ACTIVITIES                 = SQL_MAX_CONCURRENT_ACTIVITIES;
  {$EXTERNALSYM SQL_DATA_SOURCE_NAME}
  SQL_DATA_SOURCE_NAME                              = 2;
  {$EXTERNALSYM SQL_FETCH_DIRECTION}
  SQL_FETCH_DIRECTION                               = 8;
  {$EXTERNALSYM SQL_CURSOR_COMMIT_BEHAVIOR}
  SQL_CURSOR_COMMIT_BEHAVIOR                        = 23;
  {$EXTERNALSYM SQL_DATA_SOURCE_READ_ONLY}
  SQL_DATA_SOURCE_READ_ONLY                         = 25;
  {$EXTERNALSYM SQL_DEFAULT_TXN_ISOLATION}
  SQL_DEFAULT_TXN_ISOLATION                         = 26;
  {$EXTERNALSYM SQL_IDENTIFIER_CASE}
  SQL_IDENTIFIER_CASE                               = 28;
  {$EXTERNALSYM SQL_IDENTIFIER_QUOTE_CHAR}
  SQL_IDENTIFIER_QUOTE_CHAR                         = 29;
  {$EXTERNALSYM SQL_MAX_COLUMN_NAME_LEN}
  SQL_MAX_COLUMN_NAME_LEN                           = 30;
  {$EXTERNALSYM SQL_MAXIMUM_COLUMN_NAME_LENGTH}
  SQL_MAXIMUM_COLUMN_NAME_LENGTH                    = SQL_MAX_COLUMN_NAME_LEN;
  {$EXTERNALSYM SQL_MAX_CURSOR_NAME_LEN}
  SQL_MAX_CURSOR_NAME_LEN                           = 31;
  {$EXTERNALSYM SQL_MAXIMUM_CURSOR_NAME_LENGTH}
  SQL_MAXIMUM_CURSOR_NAME_LENGTH                    = SQL_MAX_CURSOR_NAME_LEN;
  {$EXTERNALSYM SQL_MAX_SCHEMA_NAME_LEN}
  SQL_MAX_SCHEMA_NAME_LEN                           = 32;
  {$EXTERNALSYM SQL_MAXIMUM_SCHEMA_NAME_LENGTH}
  SQL_MAXIMUM_SCHEMA_NAME_LENGTH                    = SQL_MAX_SCHEMA_NAME_LEN;
  {$EXTERNALSYM SQL_MAX_CATALOG_NAME_LEN}
  SQL_MAX_CATALOG_NAME_LEN                          = 34;
  {$EXTERNALSYM SQL_MAXIMUM_CATALOG_NAME_LENGTH}
  SQL_MAXIMUM_CATALOG_NAME_LENGTH                   = SQL_MAX_CATALOG_NAME_LEN;
  {$EXTERNALSYM SQL_MAX_TABLE_NAME_LEN}
  SQL_MAX_TABLE_NAME_LEN                            = 35;
  {$EXTERNALSYM SQL_SCROLL_CONCURRENCY}
  SQL_SCROLL_CONCURRENCY                            = 43;
  {$EXTERNALSYM SQL_TXN_CAPABLE}
  SQL_TXN_CAPABLE                                   = 46;
  {$EXTERNALSYM SQL_TRANSACTION_CAPABLE}
  SQL_TRANSACTION_CAPABLE                           = SQL_TXN_CAPABLE;
  {$EXTERNALSYM SQL_USER_NAME}
  SQL_USER_NAME                                     = 47;
  {$EXTERNALSYM SQL_TXN_ISOLATION_OPTION}
  SQL_TXN_ISOLATION_OPTION                          = 72;
  {$EXTERNALSYM SQL_TRANSACTION_ISOLATION_OPTION}
  SQL_TRANSACTION_ISOLATION_OPTION                  = SQL_TXN_ISOLATION_OPTION;
  {$EXTERNALSYM SQL_INTEGRITY}
  SQL_INTEGRITY                                     = 73;
  {$EXTERNALSYM SQL_GETDATA_EXTENSIONS}
  SQL_GETDATA_EXTENSIONS                            = 81;
  {$EXTERNALSYM SQL_NULL_COLLATION}
  SQL_NULL_COLLATION                                = 85;
  {$EXTERNALSYM SQL_ALTER_TABLE}
  SQL_ALTER_TABLE                                   = 86;
  {$EXTERNALSYM SQL_ORDER_BY_COLUMNS_IN_SELECT}
  SQL_ORDER_BY_COLUMNS_IN_SELECT                    = 90;
  {$EXTERNALSYM SQL_SPECIAL_CHARACTERS}
  SQL_SPECIAL_CHARACTERS                            = 94;
  {$EXTERNALSYM SQL_MAX_COLUMNS_IN_GROUP_BY}
  SQL_MAX_COLUMNS_IN_GROUP_BY                       = 97;
  {$EXTERNALSYM SQL_MAXIMUM_COLUMNS_IN_GROUP_BY}
  SQL_MAXIMUM_COLUMNS_IN_GROUP_BY                   = SQL_MAX_COLUMNS_IN_GROUP_BY;
  {$EXTERNALSYM SQL_MAX_COLUMNS_IN_INDEX}
  SQL_MAX_COLUMNS_IN_INDEX                          = 98;
  {$EXTERNALSYM SQL_MAXIMUM_COLUMNS_IN_INDEX}
  SQL_MAXIMUM_COLUMNS_IN_INDEX                      = SQL_MAX_COLUMNS_IN_INDEX;
  {$EXTERNALSYM SQL_MAX_COLUMNS_IN_ORDER_BY}
  SQL_MAX_COLUMNS_IN_ORDER_BY                       = 99;
  {$EXTERNALSYM SQL_MAXIMUM_COLUMNS_IN_ORDER_BY}
  SQL_MAXIMUM_COLUMNS_IN_ORDER_BY                   = SQL_MAX_COLUMNS_IN_ORDER_BY;
  {$EXTERNALSYM SQL_MAX_COLUMNS_IN_SELECT}
  SQL_MAX_COLUMNS_IN_SELECT                         = 100;
  {$EXTERNALSYM SQL_MAXIMUM_COLUMNS_IN_SELECT}
  SQL_MAXIMUM_COLUMNS_IN_SELECT                     = SQL_MAX_COLUMNS_IN_SELECT;
  {$EXTERNALSYM SQL_MAX_COLUMNS_IN_TABLE}
  SQL_MAX_COLUMNS_IN_TABLE                          = 101;
  {$EXTERNALSYM SQL_MAX_INDEX_SIZE}
  SQL_MAX_INDEX_SIZE                                = 102;
  {$EXTERNALSYM SQL_MAXIMUM_INDEX_SIZE}
  SQL_MAXIMUM_INDEX_SIZE                            = SQL_MAX_INDEX_SIZE;
  {$EXTERNALSYM SQL_MAX_ROW_SIZE}
  SQL_MAX_ROW_SIZE                                  = 104;
  {$EXTERNALSYM SQL_MAXIMUM_ROW_SIZE}
  SQL_MAXIMUM_ROW_SIZE                              = SQL_MAX_ROW_SIZE;
  {$EXTERNALSYM SQL_MAX_STATEMENT_LEN}
  SQL_MAX_STATEMENT_LEN                             = 105;
  {$EXTERNALSYM SQL_MAXIMUM_STATEMENT_LENGTH}
  SQL_MAXIMUM_STATEMENT_LENGTH                      = SQL_MAX_STATEMENT_LEN;
  {$EXTERNALSYM SQL_MAX_TABLES_IN_SELECT}
  SQL_MAX_TABLES_IN_SELECT                          = 106;
  {$EXTERNALSYM SQL_MAXIMUM_TABLES_IN_SELECT}
  SQL_MAXIMUM_TABLES_IN_SELECT                      = SQL_MAX_TABLES_IN_SELECT;
  {$EXTERNALSYM SQL_MAX_USER_NAME_LEN}
  SQL_MAX_USER_NAME_LEN                             = 107;
  {$EXTERNALSYM SQL_MAXIMUM_USER_NAME_LENGTH}
  SQL_MAXIMUM_USER_NAME_LENGTH                      = SQL_MAX_USER_NAME_LEN;
  {$EXTERNALSYM SQL_OJ_CAPABILITIES}
  SQL_OJ_CAPABILITIES                               = 115;
  {$EXTERNALSYM SQL_OUTER_JOIN_CAPABILITIES}
  SQL_OUTER_JOIN_CAPABILITIES                       = SQL_OJ_CAPABILITIES;

  {$EXTERNALSYM SQL_XOPEN_CLI_YEAR}
  SQL_XOPEN_CLI_YEAR                                = 10000;
  {$EXTERNALSYM SQL_CURSOR_SENSITIVITY}
  SQL_CURSOR_SENSITIVITY                            = 10001;
  {$EXTERNALSYM SQL_DESCRIBE_PARAMETER}
  SQL_DESCRIBE_PARAMETER                            = 10002;
  {$EXTERNALSYM SQL_CATALOG_NAME}
  SQL_CATALOG_NAME                                  = 10003;
  {$EXTERNALSYM SQL_COLLATION_SEQ}
  SQL_COLLATION_SEQ                                 = 10004;
  {$EXTERNALSYM SQL_MAX_IDENTIFIER_LEN}
  SQL_MAX_IDENTIFIER_LEN                            = 10005;
  {$EXTERNALSYM SQL_MAXIMUM_IDENTIFIER_LENGTH}
  SQL_MAXIMUM_IDENTIFIER_LENGTH                     = SQL_MAX_IDENTIFIER_LEN;

  {$EXTERNALSYM SQL_AT_ADD_COLUMN}
  SQL_AT_ADD_COLUMN                                 = $00000001;
  {$EXTERNALSYM SQL_AT_DROP_COLUMN}
  SQL_AT_DROP_COLUMN                                = $00000002;

  {$EXTERNALSYM SQL_AT_ADD_CONSTRAINT}
  SQL_AT_ADD_CONSTRAINT                             = $00000008;

  {$EXTERNALSYM SQL_AM_NONE}
  SQL_AM_NONE                                       = 0;
  {$EXTERNALSYM SQL_AM_CONNECTION}
  SQL_AM_CONNECTION                                 = 1;
  {$EXTERNALSYM SQL_AM_STATEMENT}
  SQL_AM_STATEMENT                                  = 2;

  {$EXTERNALSYM SQL_CB_DELETE}
  SQL_CB_DELETE                                     = 0;
  {$EXTERNALSYM SQL_CB_CLOSE}
  SQL_CB_CLOSE                                      = 1;
  {$EXTERNALSYM SQL_CB_PRESERVE}
  SQL_CB_PRESERVE                                   = 2;

  {$EXTERNALSYM SQL_FD_FETCH_NEXT}
  SQL_FD_FETCH_NEXT                                 = $00000001;
  {$EXTERNALSYM SQL_FD_FETCH_FIRST}
  SQL_FD_FETCH_FIRST                                = $00000002;
  {$EXTERNALSYM SQL_FD_FETCH_LAST}
  SQL_FD_FETCH_LAST                                 = $00000004;
  {$EXTERNALSYM SQL_FD_FETCH_PRIOR}
  SQL_FD_FETCH_PRIOR                                = $00000008;
  {$EXTERNALSYM SQL_FD_FETCH_ABSOLUTE}
  SQL_FD_FETCH_ABSOLUTE                             = $00000010;
  {$EXTERNALSYM SQL_FD_FETCH_RELATIVE}
  SQL_FD_FETCH_RELATIVE                             = $00000020;

  {$EXTERNALSYM SQL_GD_ANY_COLUMN}
  SQL_GD_ANY_COLUMN                                 = $00000001;
  {$EXTERNALSYM SQL_GD_ANY_ORDER}
  SQL_GD_ANY_ORDER                                  = $00000002;

  {$EXTERNALSYM SQL_IC_UPPER}
  SQL_IC_UPPER                                      = 1;
  {$EXTERNALSYM SQL_IC_LOWER}
  SQL_IC_LOWER                                      = 2;
  {$EXTERNALSYM SQL_IC_SENSITIVE}
  SQL_IC_SENSITIVE                                  = 3;
  {$EXTERNALSYM SQL_IC_MIXED}
  SQL_IC_MIXED                                      = 4;

  {$EXTERNALSYM SQL_OJ_LEFT}
  SQL_OJ_LEFT                                       = $00000001;
  {$EXTERNALSYM SQL_OJ_RIGHT}
  SQL_OJ_RIGHT                                      = $00000002;
  {$EXTERNALSYM SQL_OJ_FULL}
  SQL_OJ_FULL                                       = $00000004;
  {$EXTERNALSYM SQL_OJ_NESTED}
  SQL_OJ_NESTED                                     = $00000008;
  {$EXTERNALSYM SQL_OJ_NOT_ORDERED}
  SQL_OJ_NOT_ORDERED                                = $00000010;
  {$EXTERNALSYM SQL_OJ_INNER}
  SQL_OJ_INNER                                      = $00000020;
  {$EXTERNALSYM SQL_OJ_ALL_COMPARISON_OPS}
  SQL_OJ_ALL_COMPARISON_OPS                         = $00000040;

  {$EXTERNALSYM SQL_SCCO_READ_ONLY}
  SQL_SCCO_READ_ONLY                                = $00000001;
  {$EXTERNALSYM SQL_SCCO_LOCK}
  SQL_SCCO_LOCK                                     = $00000002;
  {$EXTERNALSYM SQL_SCCO_OPT_ROWVER}
  SQL_SCCO_OPT_ROWVER                               = $00000004;
  {$EXTERNALSYM SQL_SCCO_OPT_VALUES}
  SQL_SCCO_OPT_VALUES                               = $00000008;

  {$EXTERNALSYM SQL_TC_NONE}
  SQL_TC_NONE                                       = 0;
  {$EXTERNALSYM SQL_TC_DML}
  SQL_TC_DML                                        = 1;
  {$EXTERNALSYM SQL_TC_ALL}
  SQL_TC_ALL                                        = 2;
  {$EXTERNALSYM SQL_TC_DDL_COMMIT}
  SQL_TC_DDL_COMMIT                                 = 3;
  {$EXTERNALSYM SQL_TC_DDL_IGNORE}
  SQL_TC_DDL_IGNORE                                 = 4;

  {$EXTERNALSYM SQL_TXN_READ_UNCOMMITTED}
  SQL_TXN_READ_UNCOMMITTED                          = $00000001;
  {$EXTERNALSYM SQL_TRANSACTION_READ_UNCOMMITTED}
  SQL_TRANSACTION_READ_UNCOMMITTED                  = SQL_TXN_READ_UNCOMMITTED;
  {$EXTERNALSYM SQL_TXN_READ_COMMITTED}
  SQL_TXN_READ_COMMITTED                            = $00000002;
  {$EXTERNALSYM SQL_TRANSACTION_READ_COMMITTED}
  SQL_TRANSACTION_READ_COMMITTED                    = SQL_TXN_READ_COMMITTED;
  {$EXTERNALSYM SQL_TXN_REPEATABLE_READ}
  SQL_TXN_REPEATABLE_READ                           = $00000004;
  {$EXTERNALSYM SQL_TRANSACTION_REPEATABLE_READ}
  SQL_TRANSACTION_REPEATABLE_READ                   = SQL_TXN_REPEATABLE_READ;
  {$EXTERNALSYM SQL_TXN_SERIALIZABLE}
  SQL_TXN_SERIALIZABLE                              = $00000008;
  {$EXTERNALSYM SQL_TRANSACTION_SERIALIZABLE}
  SQL_TRANSACTION_SERIALIZABLE                      = SQL_TXN_SERIALIZABLE;

  {$EXTERNALSYM SQL_NC_HIGH}
  SQL_NC_HIGH                                       = 0;
  {$EXTERNALSYM SQL_NC_LOW}
  SQL_NC_LOW                                        = 1;

  {$EXTERNALSYM SQL_IS_YEAR}
  SQL_IS_YEAR                                       = 1;
  {$EXTERNALSYM SQL_IS_MONTH}
  SQL_IS_MONTH                                      = 2;
  {$EXTERNALSYM SQL_IS_DAY}
  SQL_IS_DAY                                        = 3;
  {$EXTERNALSYM SQL_IS_HOUR}
  SQL_IS_HOUR                                       = 4;
  {$EXTERNALSYM SQL_IS_MINUTE}
  SQL_IS_MINUTE                                     = 5;
  {$EXTERNALSYM SQL_IS_SECOND}
  SQL_IS_SECOND                                     = 6;
  {$EXTERNALSYM SQL_IS_YEAR_TO_MONTH}
  SQL_IS_YEAR_TO_MONTH                              = 7;
  {$EXTERNALSYM SQL_IS_DAY_TO_HOUR}
  SQL_IS_DAY_TO_HOUR                                = 8;
  {$EXTERNALSYM SQL_IS_DAY_TO_MINUTE}
  SQL_IS_DAY_TO_MINUTE                              = 9;
  {$EXTERNALSYM SQL_IS_DAY_TO_SECOND}
  SQL_IS_DAY_TO_SECOND                              = 10;
  {$EXTERNALSYM SQL_IS_HOUR_TO_MINUTE}
  SQL_IS_HOUR_TO_MINUTE                             = 11;
  {$EXTERNALSYM SQL_IS_HOUR_TO_SECOND}
  SQL_IS_HOUR_TO_SECOND                             = 12;
  {$EXTERNALSYM SQL_IS_MINUTE_TO_SECOND}
  SQL_IS_MINUTE_TO_SECOND                           = 13;

  {$EXTERNALSYM SQL_MAX_NUMERIC_LEN}
  SQL_MAX_NUMERIC_LEN                               = 16;

  {$EXTERNALSYM SQL_IS_POINTER}
  SQL_IS_POINTER                                    = -4;
  {$EXTERNALSYM SQL_IS_UINTEGER}
  SQL_IS_UINTEGER                                   = -5;
  {$EXTERNALSYM SQL_IS_INTEGER}
  SQL_IS_INTEGER                                    = -6;
  {$EXTERNALSYM SQL_IS_USMALLINT}
  SQL_IS_USMALLINT                                  = -7;
  {$EXTERNALSYM SQL_IS_SMALLINT}
  SQL_IS_SMALLINT                                   = -8;

  {$EXTERNALSYM SQL_CP_OFF}
  SQL_CP_OFF                                        = $00000000;
  {$EXTERNALSYM SQL_CP_ONE_PER_DRIVER}
  SQL_CP_ONE_PER_DRIVER                             = $00000001;
  {$EXTERNALSYM SQL_CP_ONE_PER_HENV}
  SQL_CP_ONE_PER_HENV                               = $00000002;
  {$EXTERNALSYM SQL_CP_DEFAULT}
  SQL_CP_DEFAULT                                    = SQL_CP_OFF;

  {$EXTERNALSYM SQL_CP_STRICT_MATCH}
  SQL_CP_STRICT_MATCH                               = $00000000;
  {$EXTERNALSYM SQL_CP_RELAXED_MATCH}
  SQL_CP_RELAXED_MATCH                              = $00000001;
  {$EXTERNALSYM SQL_CP_MATCH_DEFAULT}
  SQL_CP_MATCH_DEFAULT                              = SQL_CP_STRICT_MATCH;

  {$EXTERNALSYM SQL_MODE_READ_WRITE}
  SQL_MODE_READ_WRITE                               = $00000000;
  {$EXTERNALSYM SQL_MODE_READ_ONLY}
  SQL_MODE_READ_ONLY                                = $00000001;
  {$EXTERNALSYM SQL_MODE_DEFAULT}
  SQL_MODE_DEFAULT                                  = SQL_MODE_READ_WRITE;

  {$EXTERNALSYM SQL_ACCESS_MODE}
  SQL_ACCESS_MODE                                   = 101;
  {$EXTERNALSYM SQL_AUTOCOMMIT}
  SQL_AUTOCOMMIT                                    = 102;
  {$EXTERNALSYM SQL_LOGIN_TIMEOUT}
  SQL_LOGIN_TIMEOUT                                 = 103;
  {$EXTERNALSYM SQL_OPT_TRACE}
  SQL_OPT_TRACE                                     = 104;
  {$EXTERNALSYM SQL_OPT_TRACEFILE}
  SQL_OPT_TRACEFILE                                 = 105;
  {$EXTERNALSYM SQL_TRANSLATE_DLL}
  SQL_TRANSLATE_DLL                                 = 106;
  {$EXTERNALSYM SQL_TRANSLATE_OPTION}
  SQL_TRANSLATE_OPTION                              = 107;
  {$EXTERNALSYM SQL_TXN_ISOLATION}
  SQL_TXN_ISOLATION                                 = 108;
  {$EXTERNALSYM SQL_CURRENT_QUALIFIER}
  SQL_CURRENT_QUALIFIER                             = 109;
  {$EXTERNALSYM SQL_ODBC_CURSORS}
  SQL_ODBC_CURSORS                                  = 110;
  {$EXTERNALSYM SQL_QUIET_MODE}
  SQL_QUIET_MODE                                    = 111;
  {$EXTERNALSYM SQL_PACKET_SIZE}
  SQL_PACKET_SIZE                                   = 112;

  {$EXTERNALSYM SQL_ATTR_ACCESS_MODE}
  SQL_ATTR_ACCESS_MODE                              = SQL_ACCESS_MODE;
  {$EXTERNALSYM SQL_ATTR_AUTOCOMMIT}
  SQL_ATTR_AUTOCOMMIT                               = SQL_AUTOCOMMIT;
  {$EXTERNALSYM SQL_ATTR_CONNECTION_TIMEOUT}
  SQL_ATTR_CONNECTION_TIMEOUT                       = 113;
  {$EXTERNALSYM SQL_ATTR_CURRENT_CATALOG}
  SQL_ATTR_CURRENT_CATALOG                          = SQL_CURRENT_QUALIFIER;
  {$EXTERNALSYM SQL_ATTR_DISCONNECT_BEHAVIOR}
  SQL_ATTR_DISCONNECT_BEHAVIOR                      = 114;
  {$EXTERNALSYM SQL_ATTR_ENLIST_IN_DTC}
  SQL_ATTR_ENLIST_IN_DTC                            = 1207;
  {$EXTERNALSYM SQL_ATTR_ENLIST_IN_XA}
  SQL_ATTR_ENLIST_IN_XA                             = 1208;
  {$EXTERNALSYM SQL_ATTR_LOGIN_TIMEOUT}
  SQL_ATTR_LOGIN_TIMEOUT                            = SQL_LOGIN_TIMEOUT;
  {$EXTERNALSYM SQL_ATTR_ODBC_CURSORS}
  SQL_ATTR_ODBC_CURSORS                             = SQL_ODBC_CURSORS;
  {$EXTERNALSYM SQL_ATTR_PACKET_SIZE}
  SQL_ATTR_PACKET_SIZE                              = SQL_PACKET_SIZE;
  {$EXTERNALSYM SQL_ATTR_QUIET_MODE}
  SQL_ATTR_QUIET_MODE                               = SQL_QUIET_MODE;
  {$EXTERNALSYM SQL_ATTR_TRACE}
  SQL_ATTR_TRACE                                    = SQL_OPT_TRACE;
  {$EXTERNALSYM SQL_ATTR_TRACEFILE}
  SQL_ATTR_TRACEFILE                                = SQL_OPT_TRACEFILE;
  {$EXTERNALSYM SQL_ATTR_TRANSLATE_LIB}
  SQL_ATTR_TRANSLATE_LIB                            = SQL_TRANSLATE_DLL;
  {$EXTERNALSYM SQL_ATTR_TRANSLATE_OPTION}
  SQL_ATTR_TRANSLATE_OPTION                         = SQL_TRANSLATE_OPTION;
  {$EXTERNALSYM SQL_ATTR_TXN_ISOLATION}
  SQL_ATTR_TXN_ISOLATION                            = SQL_TXN_ISOLATION;

  {$EXTERNALSYM SQL_ASYNC_ENABLE_OFF}
  SQL_ASYNC_ENABLE_OFF                              = $00000000;
  {$EXTERNALSYM SQL_ASYNC_ENABLE_ON}
  SQL_ASYNC_ENABLE_ON                               = $00000001;
  {$EXTERNALSYM SQL_ASYNC_ENABLE_DEFAULT}
  SQL_ASYNC_ENABLE_DEFAULT                          = SQL_ASYNC_ENABLE_OFF;

  {$EXTERNALSYM SQL_QUERY_TIMEOUT}
  SQL_QUERY_TIMEOUT                                 = 0;
  {$EXTERNALSYM SQL_MAX_ROWS}
  SQL_MAX_ROWS                                      = 1;
  {$EXTERNALSYM SQL_NOSCAN}
  SQL_NOSCAN                                        = 2;
  {$EXTERNALSYM SQL_MAX_LENGTH}
  SQL_MAX_LENGTH                                    = 3;
  {$EXTERNALSYM SQL_ASYNC_ENABLE}
  SQL_ASYNC_ENABLE                                  = 4;
  {$EXTERNALSYM SQL_BIND_TYPE}
  SQL_BIND_TYPE                                     = 5;
  {$EXTERNALSYM SQL_CURSOR_TYPE}
  SQL_CURSOR_TYPE                                   = 6;
  {$EXTERNALSYM SQL_CONCURRENCY}
  SQL_CONCURRENCY                                   = 7;
  {$EXTERNALSYM SQL_KEYSET_SIZE}
  SQL_KEYSET_SIZE                                   = 8;
  {$EXTERNALSYM SQL_ROWSET_SIZE}
  SQL_ROWSET_SIZE                                   = 9;
  {$EXTERNALSYM SQL_SIMULATE_CURSOR}
  SQL_SIMULATE_CURSOR                               = 10;
  {$EXTERNALSYM SQL_RETRIEVE_DATA}
  SQL_RETRIEVE_DATA                                 = 11;
  {$EXTERNALSYM SQL_USE_BOOKMARKS}
  SQL_USE_BOOKMARKS                                 = 12;
  {$EXTERNALSYM SQL_GET_BOOKMARK}
  SQL_GET_BOOKMARK                                  = 13;
  {$EXTERNALSYM SQL_ROW_NUMBER}
  SQL_ROW_NUMBER                                    = 14;

  {$EXTERNALSYM SQL_ATTR_ASYNC_ENABLE}
  SQL_ATTR_ASYNC_ENABLE                             = 4;
  {$EXTERNALSYM SQL_ATTR_CONCURRENCY}
  SQL_ATTR_CONCURRENCY                              = SQL_CONCURRENCY;
  {$EXTERNALSYM SQL_ATTR_CURSOR_TYPE}
  SQL_ATTR_CURSOR_TYPE                              = SQL_CURSOR_TYPE;
  {$EXTERNALSYM SQL_ATTR_ENABLE_AUTO_IPD}
  SQL_ATTR_ENABLE_AUTO_IPD                          = 15;
  {$EXTERNALSYM SQL_ATTR_FETCH_BOOKMARK_PTR}
  SQL_ATTR_FETCH_BOOKMARK_PTR                       = 16;
  {$EXTERNALSYM SQL_ATTR_KEYSET_SIZE}
  SQL_ATTR_KEYSET_SIZE                              = SQL_KEYSET_SIZE;
  {$EXTERNALSYM SQL_ATTR_MAX_LENGTH}
  SQL_ATTR_MAX_LENGTH                               = SQL_MAX_LENGTH;
  {$EXTERNALSYM SQL_ATTR_MAX_ROWS}
  SQL_ATTR_MAX_ROWS                                 = SQL_MAX_ROWS;
  {$EXTERNALSYM SQL_ATTR_NOSCAN}
  SQL_ATTR_NOSCAN                                   = SQL_NOSCAN;
  {$EXTERNALSYM SQL_ATTR_PARAM_BIND_OFFSET_PTR}
  SQL_ATTR_PARAM_BIND_OFFSET_PTR                    = 17;
  {$EXTERNALSYM SQL_ATTR_PARAM_BIND_TYPE}
  SQL_ATTR_PARAM_BIND_TYPE                          = 18;
  {$EXTERNALSYM SQL_ATTR_PARAM_OPERATION_PTR}
  SQL_ATTR_PARAM_OPERATION_PTR                      = 19;
  {$EXTERNALSYM SQL_ATTR_PARAM_STATUS_PTR}
  SQL_ATTR_PARAM_STATUS_PTR                         = 20;
  {$EXTERNALSYM SQL_ATTR_PARAMS_PROCESSED_PTR}
  SQL_ATTR_PARAMS_PROCESSED_PTR                     = 21;
  {$EXTERNALSYM SQL_ATTR_PARAMSET_SIZE}
  SQL_ATTR_PARAMSET_SIZE                            = 22;
  {$EXTERNALSYM SQL_ATTR_QUERY_TIMEOUT}
  SQL_ATTR_QUERY_TIMEOUT                            = SQL_QUERY_TIMEOUT;
  {$EXTERNALSYM SQL_ATTR_RETRIEVE_DATA}
  SQL_ATTR_RETRIEVE_DATA                            = SQL_RETRIEVE_DATA;
  {$EXTERNALSYM SQL_ATTR_ROW_BIND_OFFSET_PTR}
  SQL_ATTR_ROW_BIND_OFFSET_PTR                      = 23;
  {$EXTERNALSYM SQL_ATTR_ROW_BIND_TYPE}
  SQL_ATTR_ROW_BIND_TYPE                            = SQL_BIND_TYPE;
  {$EXTERNALSYM SQL_ATTR_ROW_NUMBER}
  SQL_ATTR_ROW_NUMBER                               = SQL_ROW_NUMBER;
  {$EXTERNALSYM SQL_ATTR_ROW_OPERATION_PTR}
  SQL_ATTR_ROW_OPERATION_PTR                        = 24;
  {$EXTERNALSYM SQL_ATTR_ROW_STATUS_PTR}
  SQL_ATTR_ROW_STATUS_PTR                           = 25;
  {$EXTERNALSYM SQL_ATTR_ROWS_FETCHED_PTR}
  SQL_ATTR_ROWS_FETCHED_PTR                         = 26;
  {$EXTERNALSYM SQL_ATTR_ROW_ARRAY_SIZE}
  SQL_ATTR_ROW_ARRAY_SIZE                           = 27;
  {$EXTERNALSYM SQL_ATTR_SIMULATE_CURSOR}
  SQL_ATTR_SIMULATE_CURSOR                          = SQL_SIMULATE_CURSOR;
  {$EXTERNALSYM SQL_ATTR_USE_BOOKMARKS}
  SQL_ATTR_USE_BOOKMARKS                            = SQL_USE_BOOKMARKS;

  SQL_ATTR_GM_POSITIONAL_INSERT                     = 11000;
//  SQL_ATTR_GM_ALLOCATED_MEMORY                      = 11001;


  {$EXTERNALSYM SQL_AUTOCOMMIT_OFF}
  SQL_AUTOCOMMIT_OFF                                = $00000000;
  {$EXTERNALSYM SQL_AUTOCOMMIT_ON}
  SQL_AUTOCOMMIT_ON                                 = $00000001;
  {$EXTERNALSYM SQL_AUTOCOMMIT_DEFAULT}
  SQL_AUTOCOMMIT_DEFAULT                            = SQL_AUTOCOMMIT_ON;

  {$EXTERNALSYM SQL_CUR_USE_IF_NEEDED}
  SQL_CUR_USE_IF_NEEDED                             = $00000000;
  {$EXTERNALSYM SQL_CUR_USE_ODBC}
  SQL_CUR_USE_ODBC                                  = $00000001;
  {$EXTERNALSYM SQL_CUR_USE_DRIVER}
  SQL_CUR_USE_DRIVER                                = $00000002;
  {$EXTERNALSYM SQL_CUR_DEFAULT}
  SQL_CUR_DEFAULT                                   = SQL_CUR_USE_DRIVER;

  {$EXTERNALSYM SQL_COPT_SS_BASE}
  SQL_COPT_SS_BASE                                  = 1200;
  {$EXTERNALSYM SQL_ATTR_CONNECTION_DEAD}
  SQL_ATTR_CONNECTION_DEAD                          = SQL_COPT_SS_BASE + 9;

  {$EXTERNALSYM SQL_REMOTE_PWD}
  SQL_REMOTE_PWD                                    = SQL_COPT_SS_BASE + 1;
  {$EXTERNALSYM SQL_USE_PROCEDURE_FOR_PREPARE}

  SQL_USE_PROCEDURE_FOR_PREPARE                     = SQL_COPT_SS_BASE + 2;
  {$EXTERNALSYM SQL_INTEGRATED_SECURITY}
  SQL_INTEGRATED_SECURITY                           = SQL_COPT_SS_BASE + 3;
  {$EXTERNALSYM SQL_PRESERVE_CURSORS}
  SQL_PRESERVE_CURSORS                              = SQL_COPT_SS_BASE + 4;
  {$EXTERNALSYM SQL_COPT_SS_USER_DATA}
  SQL_COPT_SS_USER_DATA                             = SQL_COPT_SS_BASE + 5;
  {$EXTERNALSYM SQL_COPT_SS_ANSI_OEM}
  SQL_COPT_SS_ANSI_OEM                              = SQL_COPT_SS_BASE + 6;
  {$EXTERNALSYM SQL_COPT_SS_CONNECTION_DEAD}
  SQL_COPT_SS_CONNECTION_DEAD                       = SQL_COPT_SS_BASE + 9;
  {$EXTERNALSYM SQL_COPT_SS_FALLBACK_CONNECT}
  SQL_COPT_SS_FALLBACK_CONNECT                      = SQL_COPT_SS_BASE + 10;
  {$EXTERNALSYM SQL_COPT_SS_PERF_DATA}
  SQL_COPT_SS_PERF_DATA                             = SQL_COPT_SS_BASE + 11;
  {$EXTERNALSYM SQL_COPT_SS_PERF_DATA_LOG}
  SQL_COPT_SS_PERF_DATA_LOG                         = SQL_COPT_SS_BASE + 12;
  {$EXTERNALSYM SQL_COPT_SS_PERF_QUERY_INTERVAL}
  SQL_COPT_SS_PERF_QUERY_INTERVAL                   = SQL_COPT_SS_BASE + 13;
  {$EXTERNALSYM SQL_COPT_SS_PERF_QUERY_LOG}
  SQL_COPT_SS_PERF_QUERY_LOG                        = SQL_COPT_SS_BASE + 14;
  {$EXTERNALSYM SQL_COPT_SS_PERF_QUERY}
  SQL_COPT_SS_PERF_QUERY                            = SQL_COPT_SS_BASE + 15;
  {$EXTERNALSYM SQL_COPT_SS_PERF_DATA_LOG_NOW}
  SQL_COPT_SS_PERF_DATA_LOG_NOW                     = SQL_COPT_SS_BASE + 16;
  {$EXTERNALSYM SQL_COPT_SS_PERF_QUERY_AUTO_LOG}
  SQL_COPT_SS_PERF_QUERY_AUTO_LOG                   = SQL_COPT_SS_BASE + 17;
  {$EXTERNALSYM SQL_COPT_SS_PERF_DATA_AUTO_LOG}
  SQL_COPT_SS_PERF_DATA_AUTO_LOG                    = SQL_COPT_SS_BASE + 18;

  {$EXTERNALSYM SQL_CD_TRUE}
  SQL_CD_TRUE                                       = $00000001;
  {$EXTERNALSYM SQL_CD_FALSE}
  SQL_CD_FALSE                                      = $00000000;

  {$EXTERNALSYM SQL_OPT_TRACE_OFF}
  SQL_OPT_TRACE_OFF                                 = $00000000;
  {$EXTERNALSYM SQL_OPT_TRACE_ON}
  SQL_OPT_TRACE_ON                                  = $00000001;
  {$EXTERNALSYM SQL_OPT_TRACE_DEFAULT}
  SQL_OPT_TRACE_DEFAULT                             = SQL_OPT_TRACE_OFF;
  {$EXTERNALSYM SQL_OPT_TRACE_FILE_DEFAULT}
  SQL_OPT_TRACE_FILE_DEFAULT                        = '\SQL.LOG';

  {$EXTERNALSYM SQL_MAX_DSN_LENGTH}
  SQL_MAX_DSN_LENGTH                                = 32;
  {$EXTERNALSYM SQL_MAX_OPTION_STRING_LENGTH}
  SQL_MAX_OPTION_STRING_LENGTH                      = 256;

  {$EXTERNALSYM SQL_CONCUR_READ_ONLY}
  SQL_CONCUR_READ_ONLY                              = 1;
  {$EXTERNALSYM SQL_CONCUR_LOCK}
  SQL_CONCUR_LOCK                                   = 2;
  {$EXTERNALSYM SQL_CONCUR_ROWVER}
  SQL_CONCUR_ROWVER                                 = 3;
  {$EXTERNALSYM SQL_CONCUR_VALUES}
  SQL_CONCUR_VALUES                                 = 4;
  {$EXTERNALSYM SQL_CONCUR_DEFAULT}
  SQL_CONCUR_DEFAULT                                = SQL_CONCUR_READ_ONLY;

  {$EXTERNALSYM SQL_CURSOR_FORWARD_ONLY}
  SQL_CURSOR_FORWARD_ONLY                           = $00000000;
  {$EXTERNALSYM SQL_CURSOR_KEYSET_DRIVEN}
  SQL_CURSOR_KEYSET_DRIVEN                          = $00000001;
  {$EXTERNALSYM SQL_CURSOR_DYNAMIC}
  SQL_CURSOR_DYNAMIC                                = $00000002;
  {$EXTERNALSYM SQL_CURSOR_STATIC}
  SQL_CURSOR_STATIC                                 = $00000003;
  {$EXTERNALSYM SQL_CURSOR_TYPE_DEFAULT}
  SQL_CURSOR_TYPE_DEFAULT                           = SQL_CURSOR_FORWARD_ONLY;

  {$EXTERNALSYM SQL_NOSCAN_OFF}
  SQL_NOSCAN_OFF                                    = $00000000;
  {$EXTERNALSYM SQL_NOSCAN_ON}
  SQL_NOSCAN_ON                                     = $00000001;
  {$EXTERNALSYM SQL_NOSCAN_DEFAULT}
  SQL_NOSCAN_DEFAULT                                = SQL_NOSCAN_OFF;

  {$EXTERNALSYM SQL_COLUMN_COUNT}
  SQL_COLUMN_COUNT                                  = 0;
  {$EXTERNALSYM SQL_COLUMN_NAME}
  SQL_COLUMN_NAME                                   = 1;
  {$EXTERNALSYM SQL_COLUMN_TYPE}
  SQL_COLUMN_TYPE                                   = 2;
  {$EXTERNALSYM SQL_COLUMN_LENGTH}
  SQL_COLUMN_LENGTH                                 = 3;
  {$EXTERNALSYM SQL_COLUMN_PRECISION}
  SQL_COLUMN_PRECISION                              = 4;
  {$EXTERNALSYM SQL_COLUMN_SCALE}
  SQL_COLUMN_SCALE                                  = 5;
  {$EXTERNALSYM SQL_COLUMN_DISPLAY_SIZE}
  SQL_COLUMN_DISPLAY_SIZE                           = 6;
  {$EXTERNALSYM SQL_COLUMN_NULLABLE}
  SQL_COLUMN_NULLABLE                               = 7;
  {$EXTERNALSYM SQL_COLUMN_UNSIGNED}
  SQL_COLUMN_UNSIGNED                               = 8;
  {$EXTERNALSYM SQL_COLUMN_MONEY}
  SQL_COLUMN_MONEY                                  = 9;
  {$EXTERNALSYM SQL_COLUMN_UPDATABLE}
  SQL_COLUMN_UPDATABLE                              = 10;
  {$EXTERNALSYM SQL_COLUMN_AUTO_INCREMENT}
  SQL_COLUMN_AUTO_INCREMENT                         = 11;
  {$EXTERNALSYM SQL_COLUMN_CASE_SENSITIVE}
  SQL_COLUMN_CASE_SENSITIVE                         = 12;
  {$EXTERNALSYM SQL_COLUMN_SEARCHABLE}
  SQL_COLUMN_SEARCHABLE                             = 13;
  {$EXTERNALSYM SQL_COLUMN_TYPE_NAME}
  SQL_COLUMN_TYPE_NAME                              = 14;
  {$EXTERNALSYM SQL_COLUMN_TABLE_NAME}
  SQL_COLUMN_TABLE_NAME                             = 15;
  {$EXTERNALSYM SQL_COLUMN_OWNER_NAME}
  SQL_COLUMN_OWNER_NAME                             = 16;
  {$EXTERNALSYM SQL_COLUMN_QUALIFIER_NAME}
  SQL_COLUMN_QUALIFIER_NAME                         = 17;
  {$EXTERNALSYM SQL_COLUMN_LABEL}
  SQL_COLUMN_LABEL                                  = 18;

  {$EXTERNALSYM SQL_ATTR_READONLY}
  SQL_ATTR_READONLY                                 = 0;
  {$EXTERNALSYM SQL_ATTR_WRITE}
  SQL_ATTR_WRITE                                    = 1;
  {$EXTERNALSYM SQL_ATTR_READWRITE_UNKNOWN}
  SQL_ATTR_READWRITE_UNKNOWN                        = 2;

  {$EXTERNALSYM SQL_UNSEARCHABLE}
  SQL_UNSEARCHABLE                                  = 0;
  {$EXTERNALSYM SQL_LIKE_ONLY}
  SQL_LIKE_ONLY                                     = 1;
  {$EXTERNALSYM SQL_ALL_EXCEPT_LIKE}
  SQL_ALL_EXCEPT_LIKE                               = 2;
  {$EXTERNALSYM SQL_SEARCHABLE}
  SQL_SEARCHABLE                                    = 3;
  {$EXTERNALSYM SQL_PRED_SEARCHABLE}
  SQL_PRED_SEARCHABLE                               = SQL_SEARCHABLE;

  {$EXTERNALSYM SQL_POSITION}
  SQL_POSITION                                      = 0;
  {$EXTERNALSYM SQL_REFRESH}
  SQL_REFRESH                                       = 1;
  {$EXTERNALSYM SQL_UPDATE}
  SQL_UPDATE                                        = 2;
  {$EXTERNALSYM SQL_DELETE}
  SQL_DELETE                                        = 3;
  {$EXTERNALSYM SQL_ADD}
  SQL_ADD                                           = 4;


  {$EXTERNALSYM SQL_LOCK_NO_CHANGE}
  SQL_LOCK_NO_CHANGE                                = 0;
  {$EXTERNALSYM SQL_LOCK_EXCLUSIVE}
  SQL_LOCK_EXCLUSIVE                                = 1;
  {$EXTERNALSYM SQL_LOCK_UNLOCK}
  SQL_LOCK_UNLOCK                                   = 2;

  {$EXTERNALSYM SQL_UB_OFF}
  SQL_UB_OFF                                        = $00000000;
  {$EXTERNALSYM SQL_UB_ON}
  SQL_UB_ON                                         = $00000001;
  {$EXTERNALSYM SQL_UB_FIXED}
  SQL_UB_FIXED                                      = SQL_UB_ON;
  {$EXTERNALSYM SQL_UB_VARIABLE}
  SQL_UB_VARIABLE                                   = $00000002;
  {$EXTERNALSYM SQL_UB_DEFAULT}
  SQL_UB_DEFAULT                                    = SQL_UB_OFF;

  {$EXTERNALSYM SQL_ROW_SUCCESS}
  SQL_ROW_SUCCESS                                   = 0;
  {$EXTERNALSYM SQL_ROW_DELETED}
  SQL_ROW_DELETED                                   = 1;
  {$EXTERNALSYM SQL_ROW_UPDATED}
  SQL_ROW_UPDATED                                   = 2;
  {$EXTERNALSYM SQL_ROW_NOROW}
  SQL_ROW_NOROW                                     = 3;
  {$EXTERNALSYM SQL_ROW_ADDED}
  SQL_ROW_ADDED                                     = 4;
  {$EXTERNALSYM SQL_ROW_ERROR}
  SQL_ROW_ERROR                                     = 5;
  {$EXTERNALSYM SQL_ROW_SUCCESS_WITH_INFO}
  SQL_ROW_SUCCESS_WITH_INFO                         = 6;

  {$EXTERNALSYM SQL_ROW_PROCEED}
  SQL_ROW_PROCEED                                   = 0;
  {$EXTERNALSYM SQL_ROW_IGNORE}
  SQL_ROW_IGNORE                                    = 1;

  {$EXTERNALSYM SQL_ALL_WILDCARD}
  SQL_ALL_WILDCARD                                  = '%';
  {$EXTERNALSYM SQL_ALL_CATALOGS}
  SQL_ALL_CATALOGS                                  = SQL_ALL_WILDCARD;
  {$EXTERNALSYM SQL_ALL_SCHEMAS}
  SQL_ALL_SCHEMAS                                   = SQL_ALL_WILDCARD;
  {$EXTERNALSYM SQL_ALL_TABLE_TYPES}
  SQL_ALL_TABLE_TYPES                               = SQL_ALL_WILDCARD;

  {$EXTERNALSYM SQL_QUICK}
  SQL_QUICK                                         = 0;
  {$EXTERNALSYM SQL_ENSURE}
  SQL_ENSURE                                        = 1;

  {$EXTERNALSYM SQL_SC_NON_UNIQUE}
  SQL_SC_NON_UNIQUE                                 = 0;
  {$EXTERNALSYM SQL_SC_TRY_UNIQUE}
  SQL_SC_TRY_UNIQUE                                 = 1;
  {$EXTERNALSYM SQL_SC_UNIQUE}
  SQL_SC_UNIQUE                                     = 2;
  {$EXTERNALSYM SQL_SC_DEFAULT}
  SQL_SC_DEFAULT                                    = SQL_SC_NON_UNIQUE;

  {$EXTERNALSYM SQL_RD_OFF}
  SQL_RD_OFF                                        = 0;
  {$EXTERNALSYM SQL_RD_ON}
  SQL_RD_ON                                         = 1;
  {$EXTERNALSYM SQL_RD_DEFAULT}
  SQL_RD_DEFAULT                                    = SQL_RD_ON;

  {$EXTERNALSYM SQL_DIAG_CURSOR_ROW_COUNT}
  SQL_DIAG_CURSOR_ROW_COUNT                         = -1249;
  {$EXTERNALSYM SQL_DIAG_ROW_NUMBER}
  SQL_DIAG_ROW_NUMBER                               = -1248;
  {$EXTERNALSYM SQL_DIAG_COLUMN_NUMBER}
  SQL_DIAG_COLUMN_NUMBER                            = -1247;


  {$EXTERNALSYM SQL_DEFAULT_ROW_ARRAY_SIZE}
  SQL_DEFAULT_ROW_ARRAY_SIZE                        = 1;
  {$EXTERNALSYM SQL_DEFAULT_LOGIN_TIMEOUT}
  SQL_DEFAULT_LOGIN_TIMEOUT                         = 30;
  {$EXTERNALSYM SQL_DEFAULT_STATEMENT_TIMEOUT}
  SQL_DEFAULT_STATEMENT_TIMEOUT                     = 0;
  {$EXTERNALSYM SQL_DEFAULT_TIMEOUT}
  SQL_DEFAULT_TIMEOUT                               = 0;
  {$EXTERNALSYM SQL_DEFAULT_TRANSLATE_OPTIONS}
  SQL_DEFAULT_TRANSLATE_OPTIONS                     = 0;
  {$EXTERNALSYM SQL_DEFAULT_MAX_DATA_SIZE}
  SQL_DEFAULT_MAX_DATA_SIZE                         = 0;
  {$EXTERNALSYM SQL_DEFAULT_KEYSET_SIZE}
  SQL_DEFAULT_KEYSET_SIZE                           = 0;
  {$EXTERNALSYM SQL_DEFAULT_MAX_RECORDS}
  SQL_DEFAULT_MAX_RECORDS                           = 0;

  {$EXTERNALSYM ODBC_ADD_DSN}
  ODBC_ADD_DSN                                      = 1; // Add data source
  {$EXTERNALSYM ODBC_CONFIG_DSN}
  ODBC_CONFIG_DSN                                   = 2; // Configure (edit) data source
  {$EXTERNALSYM ODBC_REMOVE_DSN}
  ODBC_REMOVE_DSN                                   = 3; // Remove data source

  {$EXTERNALSYM ODBC_ADD_SYS_DSN}
  ODBC_ADD_SYS_DSN                                  = 4; // add a system DSN
  {$EXTERNALSYM ODBC_CONFIG_SYS_DSN}
  ODBC_CONFIG_SYS_DSN                               = 5; // Configure a system DSN
  {$EXTERNALSYM ODBC_REMOVE_SYS_DSN}
  ODBC_REMOVE_SYS_DSN                               = 6; // remove a system DSN
  {$EXTERNALSYM ODBC_REMOVE_DEFAULT_DSN}
  ODBC_REMOVE_DEFAULT_DSN                           = 7; // remove the default DSN

  {$EXTERNALSYM ODBC_INSTALL_INQUIRY}
  ODBC_INSTALL_INQUIRY                              = 1;
  {$EXTERNALSYM ODBC_INSTALL_COMPLETE}
  ODBC_INSTALL_COMPLETE                             = 2;

  {$EXTERNALSYM ODBC_INSTALL_DRIVER}
  ODBC_INSTALL_DRIVER                               = 1;
  {$EXTERNALSYM ODBC_REMOVE_DRIVER}
  ODBC_REMOVE_DRIVER                                = 2;
  {$EXTERNALSYM ODBC_CONFIG_DRIVER}
  ODBC_CONFIG_DRIVER                                = 3;
  {$EXTERNALSYM ODBC_CONFIG_DRIVER_MAX}
  ODBC_CONFIG_DRIVER_MAX                            = 100;

  {$EXTERNALSYM ODBC_BOTH_DSN}
  ODBC_BOTH_DSN                                     = 0;
  {$EXTERNALSYM ODBC_USER_DSN}
  ODBC_USER_DSN                                     = 1;
  {$EXTERNALSYM ODBC_SYSTEM_DSN}
  ODBC_SYSTEM_DSN                                   = 2;

  {$EXTERNALSYM ODBC_ERROR_GENERAL_ERR}
  ODBC_ERROR_GENERAL_ERR                            = 1;
  {$EXTERNALSYM ODBC_ERROR_INVALID_BUFF_LEN}
  ODBC_ERROR_INVALID_BUFF_LEN                       = 2;
  {$EXTERNALSYM ODBC_ERROR_INVALID_HWND}
  ODBC_ERROR_INVALID_HWND                           = 3;
  {$EXTERNALSYM ODBC_ERROR_INVALID_STR}
  ODBC_ERROR_INVALID_STR                            = 4;
  {$EXTERNALSYM ODBC_ERROR_INVALID_REQUEST_TYPE}
  ODBC_ERROR_INVALID_REQUEST_TYPE                   = 5;
  {$EXTERNALSYM ODBC_ERROR_COMPONENT_NOT_FOUND}
  ODBC_ERROR_COMPONENT_NOT_FOUND                    = 6;
  {$EXTERNALSYM ODBC_ERROR_INVALID_NAME}
  ODBC_ERROR_INVALID_NAME                           = 7;
  {$EXTERNALSYM ODBC_ERROR_INVALID_KEYWORD_VALUE}
  ODBC_ERROR_INVALID_KEYWORD_VALUE                  = 8;
  {$EXTERNALSYM ODBC_ERROR_INVALID_DSN}
  ODBC_ERROR_INVALID_DSN                            = 9;
  {$EXTERNALSYM ODBC_ERROR_INVALID_INF}
  ODBC_ERROR_INVALID_INF                            = 10;
  {$EXTERNALSYM ODBC_ERROR_REQUEST_FAILED}
  ODBC_ERROR_REQUEST_FAILED                         = 11;
  {$EXTERNALSYM ODBC_ERROR_INVALID_PATH}
  ODBC_ERROR_INVALID_PATH                           = 12;
  {$EXTERNALSYM ODBC_ERROR_LOAD_LIB_FAILED}
  ODBC_ERROR_LOAD_LIB_FAILED                        = 13;
  {$EXTERNALSYM ODBC_ERROR_INVALID_PARAM_SEQUENCE}
  ODBC_ERROR_INVALID_PARAM_SEQUENCE                 = 14;
  {$EXTERNALSYM ODBC_ERROR_INVALID_LOG_FILE}
  ODBC_ERROR_INVALID_LOG_FILE                       = 15;
  {$EXTERNALSYM ODBC_ERROR_USER_CANCELED}
  ODBC_ERROR_USER_CANCELED                          = 16;
  {$EXTERNALSYM ODBC_ERROR_USAGE_UPDATE_FAILED}
  ODBC_ERROR_USAGE_UPDATE_FAILED                    = 17;
  {$EXTERNALSYM ODBC_ERROR_CREATE_DSN_FAILED}
  ODBC_ERROR_CREATE_DSN_FAILED                      = 18;
  {$EXTERNALSYM ODBC_ERROR_WRITING_SYSINFO_FAILED}
  ODBC_ERROR_WRITING_SYSINFO_FAILED                 = 19;
  {$EXTERNALSYM ODBC_ERROR_REMOVE_DSN_FAILED}
  ODBC_ERROR_REMOVE_DSN_FAILED                      = 20;
  {$EXTERNALSYM ODBC_ERROR_OUT_OF_MEM}
  ODBC_ERROR_OUT_OF_MEM                             = 21;
  {$EXTERNALSYM ODBC_ERROR_OUTPUT_STRING_TRUNCATED}
  ODBC_ERROR_OUTPUT_STRING_TRUNCATED                = 22;

  {$EXTERNALSYM SQL_ACTIVE_CONNECTIONS}
  SQL_ACTIVE_CONNECTIONS                            = 0;
  {$EXTERNALSYM SQL_ACTIVE_STATEMENTS}
  SQL_ACTIVE_STATEMENTS                             = 1;
  {$EXTERNALSYM SQL_DRIVER_HDBC}
  SQL_DRIVER_HDBC                                   = 3;
  {$EXTERNALSYM SQL_DRIVER_HENV}
  SQL_DRIVER_HENV                                   = 4;
  {$EXTERNALSYM SQL_DRIVER_HSTMT}
  SQL_DRIVER_HSTMT                                  = 5;
  {$EXTERNALSYM SQL_DRIVER_NAME}
  SQL_DRIVER_NAME                                   = 6;
  {$EXTERNALSYM SQL_DRIVER_VER}
  SQL_DRIVER_VER                                    = 7;
  {$EXTERNALSYM SQL_ODBC_API_CONFORMANCE}
  SQL_ODBC_API_CONFORMANCE                          = 9;
  {$EXTERNALSYM SQL_ODBC_VER}
  SQL_ODBC_VER                                      = 10;
  {$EXTERNALSYM SQL_ROW_UPDATES}
  SQL_ROW_UPDATES                                   = 11;
  {$EXTERNALSYM SQL_ODBC_SAG_CLI_CONFORMANCE}
  SQL_ODBC_SAG_CLI_CONFORMANCE                      = 12;
  {$EXTERNALSYM SQL_SERVER_NAME}
  SQL_SERVER_NAME                                   = 13;
  {$EXTERNALSYM SQL_SEARCH_PATTERN_ESCAPE}
  SQL_SEARCH_PATTERN_ESCAPE                         = 14;
  {$EXTERNALSYM SQL_ODBC_SQL_CONFORMANCE}
  SQL_ODBC_SQL_CONFORMANCE                          = 15;
  {$EXTERNALSYM SQL_DATABASE_NAME}
  SQL_DATABASE_NAME                                 = 16;
  {$EXTERNALSYM SQL_DBMS_NAME}
  SQL_DBMS_NAME                                     = 17;
  {$EXTERNALSYM SQL_DBMS_VER}
  SQL_DBMS_VER                                      = 18;
  {$EXTERNALSYM SQL_ACCESSIBLE_TABLES}
  SQL_ACCESSIBLE_TABLES                             = 19;
  {$EXTERNALSYM SQL_ACCESSIBLE_PROCEDURES}
  SQL_ACCESSIBLE_PROCEDURES                         = 20;
  {$EXTERNALSYM SQL_PROCEDURES}
  SQL_PROCEDURES                                    = 21;
  {$EXTERNALSYM SQL_CONCAT_NULL_BEHAVIOR}
  SQL_CONCAT_NULL_BEHAVIOR                          = 22;
  {$EXTERNALSYM SQL_CURSOR_ROLLBACK_BEHAVIOR}
  SQL_CURSOR_ROLLBACK_BEHAVIOR                      = 24;
  {$EXTERNALSYM SQL_EXPRESSIONS_IN_ORDERBY}
  SQL_EXPRESSIONS_IN_ORDERBY                        = 27;
  {$EXTERNALSYM SQL_MAX_OWNER_NAME_LEN}
  SQL_MAX_OWNER_NAME_LEN                            = 32;
  {$EXTERNALSYM SQL_MAX_PROCEDURE_NAME_LEN}
  SQL_MAX_PROCEDURE_NAME_LEN                        = 33;
  {$EXTERNALSYM SQL_MAX_QUALIFIER_NAME_LEN}
  SQL_MAX_QUALIFIER_NAME_LEN                        = 34;
  {$EXTERNALSYM SQL_MULT_RESULT_SETS}
  SQL_MULT_RESULT_SETS                              = 36;
  {$EXTERNALSYM SQL_MULTIPLE_ACTIVE_TXN}
  SQL_MULTIPLE_ACTIVE_TXN                           = 37;
  {$EXTERNALSYM SQL_OUTER_JOINS}
  SQL_OUTER_JOINS                                   = 38;
  {$EXTERNALSYM SQL_OWNER_TERM}
  SQL_OWNER_TERM                                    = 39;
  {$EXTERNALSYM SQL_PROCEDURE_TERM}
  SQL_PROCEDURE_TERM                                = 40;
  {$EXTERNALSYM SQL_QUALIFIER_NAME_SEPARATOR}
  SQL_QUALIFIER_NAME_SEPARATOR                      = 41;
  {$EXTERNALSYM SQL_QUALIFIER_TERM}
  SQL_QUALIFIER_TERM                                = 42;
  {$EXTERNALSYM SQL_SCROLL_OPTIONS}
  SQL_SCROLL_OPTIONS                                = 44;
  {$EXTERNALSYM SQL_TABLE_TERM}
  SQL_TABLE_TERM                                    = 45;
  {$EXTERNALSYM SQL_CONVERT_FUNCTIONS}
  SQL_CONVERT_FUNCTIONS                             = 48;
  {$EXTERNALSYM SQL_NUMERIC_FUNCTIONS}
  SQL_NUMERIC_FUNCTIONS                             = 49;
  {$EXTERNALSYM SQL_STRING_FUNCTIONS}
  SQL_STRING_FUNCTIONS                              = 50;
  {$EXTERNALSYM SQL_SYSTEM_FUNCTIONS}
  SQL_SYSTEM_FUNCTIONS                              = 51;
  {$EXTERNALSYM SQL_TIMEDATE_FUNCTIONS}
  SQL_TIMEDATE_FUNCTIONS                            = 52;
  {$EXTERNALSYM SQL_CONVERT_BIGINT}
  SQL_CONVERT_BIGINT                                = 53;
  {$EXTERNALSYM SQL_CONVERT_BINARY}
  SQL_CONVERT_BINARY                                = 54;
  {$EXTERNALSYM SQL_CONVERT_BIT}
  SQL_CONVERT_BIT                                   = 55;
  {$EXTERNALSYM SQL_CONVERT_CHAR}
  SQL_CONVERT_CHAR                                  = 56;
  {$EXTERNALSYM SQL_CONVERT_DATE}
  SQL_CONVERT_DATE                                  = 57;
  {$EXTERNALSYM SQL_CONVERT_DECIMAL}
  SQL_CONVERT_DECIMAL                               = 58;
  {$EXTERNALSYM SQL_CONVERT_DOUBLE}
  SQL_CONVERT_DOUBLE                                = 59;
  {$EXTERNALSYM SQL_CONVERT_FLOAT}
  SQL_CONVERT_FLOAT                                 = 60;
  {$EXTERNALSYM SQL_CONVERT_INTEGERT}
  SQL_CONVERT_INTEGERT                              = 61;
  {$EXTERNALSYM SQL_CONVERT_LONGVARCHAR}
  SQL_CONVERT_LONGVARCHAR                           = 62;
  {$EXTERNALSYM SQL_CONVERT_NUMERIC}
  SQL_CONVERT_NUMERIC                               = 63;
  {$EXTERNALSYM SQL_CONVERT_REAL}
  SQL_CONVERT_REAL                                  = 64;
  {$EXTERNALSYM SQL_CONVERT_SMALLINT}
  SQL_CONVERT_SMALLINT                              = 65;
  {$EXTERNALSYM SQL_CONVERT_TIME}
  SQL_CONVERT_TIME                                  = 66;
  {$EXTERNALSYM SQL_CONVERT_TIMESTAMP}
  SQL_CONVERT_TIMESTAMP                             = 67;
  {$EXTERNALSYM SQL_CONVERT_TINYINT}
  SQL_CONVERT_TINYINT                               = 68;
  {$EXTERNALSYM SQL_CONVERT_VARBINARY}
  SQL_CONVERT_VARBINARY                             = 69;
  {$EXTERNALSYM SQL_CONVERT_VARCHAR}
  SQL_CONVERT_VARCHAR                               = 70;
  {$EXTERNALSYM SQL_CONVERT_LONGVARBINARY}
  SQL_CONVERT_LONGVARBINARY                         = 71;
  {$EXTERNALSYM SQL_ODBC_SQL_OPT_IEF}
  SQL_ODBC_SQL_OPT_IEF                              = 73;
  {$EXTERNALSYM SQL_CORRELATION_NAME}
  SQL_CORRELATION_NAME                              = 74;
  {$EXTERNALSYM SQL_NON_NULLABLE_COLUMNS}
  SQL_NON_NULLABLE_COLUMNS                          = 75;
  {$EXTERNALSYM SQL_DRIVER_HLIB}
  SQL_DRIVER_HLIB                                   = 76;
  {$EXTERNALSYM SQL_DRIVER_ODBC_VER}
  SQL_DRIVER_ODBC_VER                               = 77;
  {$EXTERNALSYM SQL_LOCK_TYPES}
  SQL_LOCK_TYPES                                    = 78;
  {$EXTERNALSYM SQL_POS_OPERATIONS}
  SQL_POS_OPERATIONS                                = 79;
  {$EXTERNALSYM SQL_POSITIONED_STATEMENTS}
  SQL_POSITIONED_STATEMENTS                         = 80;
  {$EXTERNALSYM SQL_BOOKMARK_PERSISTENCE}
  SQL_BOOKMARK_PERSISTENCE                          = 82;
  {$EXTERNALSYM SQL_STATIC_SENSITIVITY}
  SQL_STATIC_SENSITIVITY                            = 83;
  {$EXTERNALSYM SQL_FILE_USAGE}
  SQL_FILE_USAGE                                    = 84;
  {$EXTERNALSYM SQL_COLUMN_ALIAS}
  SQL_COLUMN_ALIAS                                  = 87;
  {$EXTERNALSYM SQL_GROUP_BY}
  SQL_GROUP_BY                                      = 88;
  {$EXTERNALSYM SQL_KEYWORDS}
  SQL_KEYWORDS                                      = 89;
  {$EXTERNALSYM SQL_OWNER_USAGE}
  SQL_OWNER_USAGE                                   = 91;
  {$EXTERNALSYM SQL_QUALIFIER_USAGE}
  SQL_QUALIFIER_USAGE                               = 92;
  {$EXTERNALSYM SQL_QUOTED_IDENTIFIER_CASE}
  SQL_QUOTED_IDENTIFIER_CASE                        = 93;
  {$EXTERNALSYM SQL_SUBQUERIES}
  SQL_SUBQUERIES                                    = 95;
  {$EXTERNALSYM SQL_UNION}
  SQL_UNION                                         = 96;
  {$EXTERNALSYM SQL_MAX_ROW_SIZE_INCLUDES_LONG}
  SQL_MAX_ROW_SIZE_INCLUDES_LONG                    = 103;
  {$EXTERNALSYM SQL_MAX_CHAR_LITERAL_LEN}
  SQL_MAX_CHAR_LITERAL_LEN                          = 108;
  {$EXTERNALSYM SQL_TIMEDATE_ADD_INTERVALS}
  SQL_TIMEDATE_ADD_INTERVALS                        = 109;
  {$EXTERNALSYM SQL_TIMEDATE_DIFF_INTERVALS}
  SQL_TIMEDATE_DIFF_INTERVALS                       = 110;
  {$EXTERNALSYM SQL_NEED_LONG_DATA_LEN}
  SQL_NEED_LONG_DATA_LEN                            = 111;
  {$EXTERNALSYM SQL_MAX_BINARY_LITERAL_LEN}
  SQL_MAX_BINARY_LITERAL_LEN                        = 112;
  {$EXTERNALSYM SQL_LIKE_ESCAPE_CLAUSE}
  SQL_LIKE_ESCAPE_CLAUSE                            = 113;
  {$EXTERNALSYM SQL_QUALIFIER_LOCATION}
  SQL_QUALIFIER_LOCATION                            = 114;

  {$EXTERNALSYM SQL_ACTIVE_ENVIRONMENTS}
  SQL_ACTIVE_ENVIRONMENTS                           = 116;
  {$EXTERNALSYM SQL_ALTER_DOMAIN}
  SQL_ALTER_DOMAIN                                  = 117;
  {$EXTERNALSYM SQL_SQL_CONFORMANCE}
  SQL_SQL_CONFORMANCE                               = 118;
  {$EXTERNALSYM SQL_DATETIME_LITERALS}
  SQL_DATETIME_LITERALS                             = 119;
  {$EXTERNALSYM SQL_ASYNC_MODE}
  SQL_ASYNC_MODE                                    = 10021;
  {$EXTERNALSYM SQL_BATCH_ROW_COUNT}
  SQL_BATCH_ROW_COUNT                               = 120;
  {$EXTERNALSYM SQL_BATCH_SUPPORT}
  SQL_BATCH_SUPPORT                                 = 121;
  {$EXTERNALSYM SQL_CATALOG_LOCATION}
  SQL_CATALOG_LOCATION                              = SQL_QUALIFIER_LOCATION;
  {$EXTERNALSYM SQL_CATALOG_NAME_SEPARATOR}
  SQL_CATALOG_NAME_SEPARATOR                        = SQL_QUALIFIER_NAME_SEPARATOR;
  {$EXTERNALSYM SQL_CATALOG_TERM}
  SQL_CATALOG_TERM                                  = SQL_QUALIFIER_TERM;
  {$EXTERNALSYM SQL_CATALOG_USAGE}
  SQL_CATALOG_USAGE                                 = SQL_QUALIFIER_USAGE;
  {$EXTERNALSYM SQL_CONVERT_WCHAR}
  SQL_CONVERT_WCHAR                                 = 122;
  {$EXTERNALSYM SQL_CONVERT_INTERVAL_DAY_TIME}
  SQL_CONVERT_INTERVAL_DAY_TIME                     = 123;
  {$EXTERNALSYM SQL_CONVERT_INTERVAL_YEAR_MONTH}
  SQL_CONVERT_INTERVAL_YEAR_MONTH                   = 124;
  {$EXTERNALSYM SQL_CONVERT_WLONGVARCHAR}
  SQL_CONVERT_WLONGVARCHAR                          = 125;
  {$EXTERNALSYM SQL_CONVERT_WVARCHAR}
  SQL_CONVERT_WVARCHAR                              = 126;
  {$EXTERNALSYM SQL_CREATE_ASSERTION}
  SQL_CREATE_ASSERTION                              = 127;
  {$EXTERNALSYM SQL_CREATE_CHARACTER_SET}
  SQL_CREATE_CHARACTER_SET                          = 128;
  {$EXTERNALSYM SQL_CREATE_COLLATION}
  SQL_CREATE_COLLATION                              = 129;
  {$EXTERNALSYM SQL_CREATE_DOMAIN}
  SQL_CREATE_DOMAIN                                 = 130;
  {$EXTERNALSYM SQL_CREATE_SCHEMA}
  SQL_CREATE_SCHEMA                                 = 131;
  {$EXTERNALSYM SQL_CREATE_TABLE}
  SQL_CREATE_TABLE                                  = 132;
  {$EXTERNALSYM SQL_CREATE_TRANSLATION}
  SQL_CREATE_TRANSLATION                            = 133;
  {$EXTERNALSYM SQL_CREATE_VIEW}
  SQL_CREATE_VIEW                                   = 134;
  {$EXTERNALSYM SQL_DRIVER_HDESC}
  SQL_DRIVER_HDESC                                  = 135;
  {$EXTERNALSYM SQL_DROP_ASSERTION}
  SQL_DROP_ASSERTION                                = 136;
  {$EXTERNALSYM SQL_DROP_CHARACTER_SET}
  SQL_DROP_CHARACTER_SET                            = 137;
  {$EXTERNALSYM SQL_DROP_COLLATION}
  SQL_DROP_COLLATION                                = 138;
  {$EXTERNALSYM SQL_DROP_DOMAIN}
  SQL_DROP_DOMAIN                                   = 139;
  {$EXTERNALSYM SQL_DROP_SCHEMA}
  SQL_DROP_SCHEMA                                   = 140;
  {$EXTERNALSYM SQL_DROP_TABLE}
  SQL_DROP_TABLE                                    = 141;
  {$EXTERNALSYM SQL_DROP_TRANSLATION}
  SQL_DROP_TRANSLATION                              = 142;
  {$EXTERNALSYM SQL_DROP_VIEW}
  SQL_DROP_VIEW                                     = 143;
  {$EXTERNALSYM SQL_DYNAMIC_CURSOR_ATTRIBUTES1}
  SQL_DYNAMIC_CURSOR_ATTRIBUTES1                    = 144;
  {$EXTERNALSYM SQL_DYNAMIC_CURSOR_ATTRIBUTES2}
  SQL_DYNAMIC_CURSOR_ATTRIBUTES2                    = 145;
  {$EXTERNALSYM SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1}
  SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1               = 146;
  {$EXTERNALSYM SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2}
  SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2               = 147;
  {$EXTERNALSYM SQL_INDEX_KEYWORDS}
  SQL_INDEX_KEYWORDS                                = 148;
  {$EXTERNALSYM SQL_INFO_SCHEMA_VIEWS}
  SQL_INFO_SCHEMA_VIEWS                             = 149;
  {$EXTERNALSYM SQL_KEYSET_CURSOR_ATTRIBUTES1}
  SQL_KEYSET_CURSOR_ATTRIBUTES1                     = 150;
  {$EXTERNALSYM SQL_KEYSET_CURSOR_ATTRIBUTES2}
  SQL_KEYSET_CURSOR_ATTRIBUTES2                     = 151;
  {$EXTERNALSYM SQL_MAX_ASYNC_CONCURRENT_STATEMENTS}
  SQL_MAX_ASYNC_CONCURRENT_STATEMENTS               = 10022;
  {$EXTERNALSYM SQL_ODBC_INTERFACE_CONFORMANCE}
  SQL_ODBC_INTERFACE_CONFORMANCE                    = 152;
  {$EXTERNALSYM SQL_PARAM_ARRAY_ROW_COUNTS}
  SQL_PARAM_ARRAY_ROW_COUNTS                        = 153;
  {$EXTERNALSYM SQL_PARAM_ARRAY_SELECTS}
  SQL_PARAM_ARRAY_SELECTS                           = 154;
  {$EXTERNALSYM SQL_SCHEMA_TERM}
  SQL_SCHEMA_TERM                                   = SQL_OWNER_TERM;
  {$EXTERNALSYM SQL_SCHEMA_USAGE}
  SQL_SCHEMA_USAGE                                  = SQL_OWNER_USAGE;
  {$EXTERNALSYM SQL_SQL92_DATETIME_FUNCTIONS}
  SQL_SQL92_DATETIME_FUNCTIONS                      = 155;
  {$EXTERNALSYM SQL_SQL92_FOREIGN_KEY_DELETE_RULE}
  SQL_SQL92_FOREIGN_KEY_DELETE_RULE                 = 156;
  {$EXTERNALSYM SQL_SQL92_FOREIGN_KEY_UPDATE_RULE}
  SQL_SQL92_FOREIGN_KEY_UPDATE_RULE                 = 157;
  {$EXTERNALSYM SQL_SQL92_GRANT}
  SQL_SQL92_GRANT                                   = 158;
  {$EXTERNALSYM SQL_SQL92_NUMERIC_VALUE_FUNCTIONS}
  SQL_SQL92_NUMERIC_VALUE_FUNCTIONS                 = 159;
  {$EXTERNALSYM SQL_SQL92_PREDICATES}
  SQL_SQL92_PREDICATES                              = 160;
  {$EXTERNALSYM SQL_SQL92_RELATIONAL_JOIN_OPERATORS}
  SQL_SQL92_RELATIONAL_JOIN_OPERATORS               = 161;
  {$EXTERNALSYM SQL_SQL92_REVOKE}
  SQL_SQL92_REVOKE                                  = 162;
  {$EXTERNALSYM SQL_SQL92_ROW_VALUE_CONSTRUCTOR}
  SQL_SQL92_ROW_VALUE_CONSTRUCTOR                   = 163;
  {$EXTERNALSYM SQL_SQL92_STRING_FUNCTIONS}
  SQL_SQL92_STRING_FUNCTIONS                        = 164;
  {$EXTERNALSYM SQL_SQL92_VALUE_EXPRESSIONS}
  SQL_SQL92_VALUE_EXPRESSIONS                       = 165;
  {$EXTERNALSYM SQL_STANDARD_CLI_CONFORMANCE}
  SQL_STANDARD_CLI_CONFORMANCE                      = 166;
  {$EXTERNALSYM SQL_STATIC_CURSOR_ATTRIBUTES1}
  SQL_STATIC_CURSOR_ATTRIBUTES1                     = 167;
  {$EXTERNALSYM SQL_STATIC_CURSOR_ATTRIBUTES2}
  SQL_STATIC_CURSOR_ATTRIBUTES2                     = 168;
  {$EXTERNALSYM SQL_AGGREGATE_FUNCTIONS}
  SQL_AGGREGATE_FUNCTIONS                           = 169;
  {$EXTERNALSYM SQL_DDL_INDEX}
  SQL_DDL_INDEX                                     = 170;
  {$EXTERNALSYM SQL_DM_VER}
  SQL_DM_VER                                        = 171;
  {$EXTERNALSYM SQL_INSERT_STATEMENT}
  SQL_INSERT_STATEMENT                              = 172;
  {$EXTERNALSYM SQL_UNION_STATEMENT}
  SQL_UNION_STATEMENT                               = SQL_UNION;

  {$EXTERNALSYM SQL_API_ALL_FUNCTIONS}
  SQL_API_ALL_FUNCTIONS                             = 0;
  {$EXTERNALSYM SQL_API_ALL_FUNCTIONS_SIZE}
  SQL_API_ALL_FUNCTIONS_SIZE                        = 100;
  {$EXTERNALSYM SQL_API_ODBC3_ALL_FUNCTIONS}
  SQL_API_ODBC3_ALL_FUNCTIONS                       = 999;
  {$EXTERNALSYM SQL_API_ODBC3_ALL_FUNCTIONS_SIZE}
  SQL_API_ODBC3_ALL_FUNCTIONS_SIZE                  = 250;


  {$EXTERNALSYM SQL_AT_ADD_COLUMN_SINGLE}
  SQL_AT_ADD_COLUMN_SINGLE                          = $00000020;
  {$EXTERNALSYM SQL_AT_ADD_COLUMN_DEFAULT}
  SQL_AT_ADD_COLUMN_DEFAULT                         = $00000040;
  {$EXTERNALSYM SQL_AT_ADD_COLUMN_COLLATION}
  SQL_AT_ADD_COLUMN_COLLATION                       = $00000080;
  {$EXTERNALSYM SQL_AT_SET_COLUMN_DEFAULT}
  SQL_AT_SET_COLUMN_DEFAULT                         = $00000100;
  {$EXTERNALSYM SQL_AT_DROP_COLUMN_DEFAULT}
  SQL_AT_DROP_COLUMN_DEFAULT                        = $00000200;
  {$EXTERNALSYM SQL_AT_DROP_COLUMN_CASCADE}
  SQL_AT_DROP_COLUMN_CASCADE                        = $00000400;
  {$EXTERNALSYM SQL_AT_DROP_COLUMN_RESTRICT}
  SQL_AT_DROP_COLUMN_RESTRICT                       = $00000800;
  {$EXTERNALSYM SQL_AT_ADD_TABLE_CONSTRAINT}
  SQL_AT_ADD_TABLE_CONSTRAINT                       = $00001000;
  {$EXTERNALSYM SQL_AT_DROP_TABLE_CONSTRAINT_CASCADE}
  SQL_AT_DROP_TABLE_CONSTRAINT_CASCADE              = $00002000;
  {$EXTERNALSYM SQL_AT_DROP_TABLE_CONSTRAINT_RESTRICT}
  SQL_AT_DROP_TABLE_CONSTRAINT_RESTRICT             = $00004000;
  {$EXTERNALSYM SQL_AT_CONSTRAINT_NAME_DEFINITION}
  SQL_AT_CONSTRAINT_NAME_DEFINITION                 = $00008000;
  {$EXTERNALSYM SQL_AT_CONSTRAINT_INITIALLY_DEFERRED}
  SQL_AT_CONSTRAINT_INITIALLY_DEFERRED              = $00010000;
  {$EXTERNALSYM SQL_AT_CONSTRAINT_INITIALLY_IMMEDIATE}
  SQL_AT_CONSTRAINT_INITIALLY_IMMEDIATE             = $00020000;
  {$EXTERNALSYM SQL_AT_CONSTRAINT_DEFERRABLE}
  SQL_AT_CONSTRAINT_DEFERRABLE                      = $00040000;
  {$EXTERNALSYM SQL_AT_CONSTRAINT_NON_DEFERRABLE}
  SQL_AT_CONSTRAINT_NON_DEFERRABLE                  = $00080000;

  {$EXTERNALSYM SQL_CVT_CHAR}
  SQL_CVT_CHAR                                      = $00000001;
  {$EXTERNALSYM SQL_CVT_NUMERIC}
  SQL_CVT_NUMERIC                                   = $00000002;
  {$EXTERNALSYM SQL_CVT_DECIMAL}
  SQL_CVT_DECIMAL                                   = $00000004;
  {$EXTERNALSYM SQL_CVT_INTEGER}
  SQL_CVT_INTEGER                                   = $00000008;
  {$EXTERNALSYM SQL_CVT_SMALLINT}
  SQL_CVT_SMALLINT                                  = $00000010;
  {$EXTERNALSYM SQL_CVT_FLOAT}
  SQL_CVT_FLOAT                                     = $00000020;
  {$EXTERNALSYM SQL_CVT_REAL}
  SQL_CVT_REAL                                      = $00000040;
  {$EXTERNALSYM SQL_CVT_DOUBLE}
  SQL_CVT_DOUBLE                                    = $00000080;
  {$EXTERNALSYM SQL_CVT_VARCHAR}
  SQL_CVT_VARCHAR                                   = $00000100;
  {$EXTERNALSYM SQL_CVT_LONGVARCHAR}
  SQL_CVT_LONGVARCHAR                               = $00000200;
  {$EXTERNALSYM SQL_CVT_BINARY}
  SQL_CVT_BINARY                                    = $00000400;
  {$EXTERNALSYM SQL_CVT_VARBINARY}
  SQL_CVT_VARBINARY                                 = $00000800;
  {$EXTERNALSYM SQL_CVT_BIT}
  SQL_CVT_BIT                                       = $00001000;
  {$EXTERNALSYM SQL_CVT_TINYINT}
  SQL_CVT_TINYINT                                   = $00002000;
  {$EXTERNALSYM SQL_CVT_BIGINT}
  SQL_CVT_BIGINT                                    = $00004000;
  {$EXTERNALSYM SQL_CVT_DATE}
  SQL_CVT_DATE                                      = $00008000;
  {$EXTERNALSYM SQL_CVT_TIME}
  SQL_CVT_TIME                                      = $00010000;
  {$EXTERNALSYM SQL_CVT_TIMESTAMP}
  SQL_CVT_TIMESTAMP                                 = $00020000;
  {$EXTERNALSYM SQL_CVT_LONGVARBINARY}
  SQL_CVT_LONGVARBINARY                             = $00040000;
  {$EXTERNALSYM SQL_CVT_INTERVAL_YEAR_MONTH}
  SQL_CVT_INTERVAL_YEAR_MONTH                       = $00080000;
  {$EXTERNALSYM SQL_CVT_INTERVAL_DAY_TIME}
  SQL_CVT_INTERVAL_DAY_TIME                         = $00100000;
  {$EXTERNALSYM SQL_CVT_WCHAR}
  SQL_CVT_WCHAR                                     = $00200000;
  {$EXTERNALSYM SQL_CVT_WLONGVARCHAR}
  SQL_CVT_WLONGVARCHAR                              = $00400000;
  {$EXTERNALSYM SQL_CVT_WVARCHAR}
  SQL_CVT_WVARCHAR                                  = $00800000;

  {$EXTERNALSYM SQL_DESC_ARRAY_SIZE}
  SQL_DESC_ARRAY_SIZE                               = 20;
  {$EXTERNALSYM SQL_DESC_ARRAY_STATUS_PTR}
  SQL_DESC_ARRAY_STATUS_PTR                         = 21;
  {$EXTERNALSYM SQL_DESC_AUTO_UNIQUE_VALUE}
  SQL_DESC_AUTO_UNIQUE_VALUE                        = SQL_COLUMN_AUTO_INCREMENT;
  {$EXTERNALSYM SQL_DESC_BASE_COLUMN_NAME}
  SQL_DESC_BASE_COLUMN_NAME                         = 22;
  {$EXTERNALSYM SQL_DESC_BASE_TABLE_NAME}
  SQL_DESC_BASE_TABLE_NAME                          = 23;
  {$EXTERNALSYM SQL_DESC_BIND_OFFSET_PTR}
  SQL_DESC_BIND_OFFSET_PTR                          = 24;
  {$EXTERNALSYM SQL_DESC_BIND_TYPE}
  SQL_DESC_BIND_TYPE                                = 25;
  {$EXTERNALSYM SQL_DESC_CASE_SENSITIVE}
  SQL_DESC_CASE_SENSITIVE                           = SQL_COLUMN_CASE_SENSITIVE;
  {$EXTERNALSYM SQL_DESC_CATALOG_NAME}
  SQL_DESC_CATALOG_NAME                             = SQL_COLUMN_QUALIFIER_NAME;
  {$EXTERNALSYM SQL_DESC_CONCISE_TYPE}
  SQL_DESC_CONCISE_TYPE                             = SQL_COLUMN_TYPE;
  {$EXTERNALSYM SQL_DESC_DATETIME_INTERVAL_PRECISION}
  SQL_DESC_DATETIME_INTERVAL_PRECISION              = 26;
  {$EXTERNALSYM SQL_DESC_DISPLAY_SIZE}
  SQL_DESC_DISPLAY_SIZE                             = SQL_COLUMN_DISPLAY_SIZE;
  {$EXTERNALSYM SQL_DESC_FIXED_PREC_SCALE}
  SQL_DESC_FIXED_PREC_SCALE                         = SQL_COLUMN_MONEY;
  {$EXTERNALSYM SQL_DESC_LABEL}
  SQL_DESC_LABEL                                    = SQL_COLUMN_LABEL;
  {$EXTERNALSYM SQL_DESC_LITERAL_PREFIX}
  SQL_DESC_LITERAL_PREFIX                           = 27;
  {$EXTERNALSYM SQL_DESC_LITERAL_SUFFIX}
  SQL_DESC_LITERAL_SUFFIX                           = 28;
  {$EXTERNALSYM SQL_DESC_LOCAL_TYPE_NAME}
  SQL_DESC_LOCAL_TYPE_NAME                          = 29;
  {$EXTERNALSYM SQL_DESC_MAXIMUM_SCALE}
  SQL_DESC_MAXIMUM_SCALE                            = 30;
  {$EXTERNALSYM SQL_DESC_MINIMUM_SCALE}
  SQL_DESC_MINIMUM_SCALE                            = 31;
  {$EXTERNALSYM SQL_DESC_NUM_PREC_RADIX}
  SQL_DESC_NUM_PREC_RADIX                           = 32;
  {$EXTERNALSYM SQL_DESC_PARAMETER_TYPE}
  SQL_DESC_PARAMETER_TYPE                           = 33;
  {$EXTERNALSYM SQL_DESC_ROWS_PROCESSED_PTR}
  SQL_DESC_ROWS_PROCESSED_PTR                       = 34;
  {$EXTERNALSYM SQL_DESC_SCHEMA_NAME}
  SQL_DESC_SCHEMA_NAME                              = SQL_COLUMN_OWNER_NAME;
  {$EXTERNALSYM SQL_DESC_SEARCHABLE}
  SQL_DESC_SEARCHABLE                               = SQL_COLUMN_SEARCHABLE;
  {$EXTERNALSYM SQL_DESC_TYPE_NAME}
  SQL_DESC_TYPE_NAME                                = SQL_COLUMN_TYPE_NAME;
  {$EXTERNALSYM SQL_DESC_TABLE_NAME}
  SQL_DESC_TABLE_NAME                               = SQL_COLUMN_TABLE_NAME;
  {$EXTERNALSYM SQL_DESC_UNSIGNED}
  SQL_DESC_UNSIGNED                                 = SQL_COLUMN_UNSIGNED;
  {$EXTERNALSYM SQL_DESC_UPDATABLE}
  SQL_DESC_UPDATABLE                                = SQL_COLUMN_UPDATABLE;

  {$EXTERNALSYM SQL_DESC_COUNT}
  SQL_DESC_COUNT                                    = 1001;
  {$EXTERNALSYM SQL_DESC_TYPE}
  SQL_DESC_TYPE                                     = 1002;
  {$EXTERNALSYM SQL_DESC_LENGTH}
  SQL_DESC_LENGTH                                   = 1003;
  {$EXTERNALSYM SQL_DESC_OCTET_LENGTH_PTR}
  SQL_DESC_OCTET_LENGTH_PTR                         = 1004;
  {$EXTERNALSYM SQL_DESC_PRECISION}
  SQL_DESC_PRECISION                                = 1005;
  {$EXTERNALSYM SQL_DESC_SCALE}
  SQL_DESC_SCALE                                    = 1006;
  {$EXTERNALSYM SQL_DESC_DATETIME_INTERVAL_CODE}
  SQL_DESC_DATETIME_INTERVAL_CODE                   = 1007;
  {$EXTERNALSYM SQL_DESC_NULLABLE}
  SQL_DESC_NULLABLE                                 = 1008;
  {$EXTERNALSYM SQL_DESC_INDICATOR_PTR}
  SQL_DESC_INDICATOR_PTR                            = 1009;
  {$EXTERNALSYM SQL_DESC_DATA_PTR}
  SQL_DESC_DATA_PTR                                 = 1010;
  {$EXTERNALSYM SQL_DESC_NAME}
  SQL_DESC_NAME                                     = 1011;
  {$EXTERNALSYM SQL_DESC_UNNAMED}
  SQL_DESC_UNNAMED                                  = 1012;
  {$EXTERNALSYM SQL_DESC_OCTET_LENGTH}
  SQL_DESC_OCTET_LENGTH                             = 1013;
  {$EXTERNALSYM SQL_DESC_ALLOC_TYPE}
  SQL_DESC_ALLOC_TYPE                               = 1099;

  {$EXTERNALSYM SQL_PT_UNKNOWN}
  SQL_PT_UNKNOWN                                    = 0;
  {$EXTERNALSYM SQL_PT_PROCEDURE}
  SQL_PT_PROCEDURE                                  = 1;
  {$EXTERNALSYM SQL_PT_FUNCTION}
  SQL_PT_FUNCTION                                   = 2;

  {$EXTERNALSYM SQL_BIND_BY_COLUMN}
  SQL_BIND_BY_COLUMN                                = 0;
  {$EXTERNALSYM SQL_BIND_TYPE_DEFAULT}
  SQL_BIND_TYPE_DEFAULT                             = SQL_BIND_BY_COLUMN;

  {$EXTERNALSYM SQL_DRIVER_NOPROMPT}
  SQL_DRIVER_NOPROMPT                               = 0;
  {$EXTERNALSYM SQL_DRIVER_COMPLETE}
  SQL_DRIVER_COMPLETE                               = 1;
  {$EXTERNALSYM SQL_DRIVER_PROMPT}
  SQL_DRIVER_PROMPT                                 = 2;
  {$EXTERNALSYM SQL_DRIVER_COMPLETE_REQUIRED}
  SQL_DRIVER_COMPLETE_REQUIRED                      = 3;

  // supported SQLFetchScroll FetchOrientation's
  SQL_CA1_NEXT                                      = $00000001;
  SQL_CA1_ABSOLUTE                                  = $00000002;
  SQL_CA1_RELATIVE                                  = $00000004;
  SQL_CA1_BOOKMARK                                  = $00000008;

  // supported SQLSetPos LockType's
  SQL_CA1_LOCK_NO_CHANGE                            = $00000040;
  SQL_CA1_LOCK_EXCLUSIVE                            = $00000080;
  SQL_CA1_LOCK_UNLOCK                               = $00000100;

  // supported SQLSetPos Operations
  SQL_CA1_POS_POSITION                              = $00000200;
  SQL_CA1_POS_UPDATE                                = $00000400;
  SQL_CA1_POS_DELETE                                = $00000800;
  SQL_CA1_POS_REFRESH                               = $00001000;

  // positioned updates and deletes
  SQL_CA1_POSITIONED_UPDATE                         = $00002000;
  SQL_CA1_POSITIONED_DELETE                         = $00004000;
  SQL_CA1_SELECT_FOR_UPDATE                         = $00008000;

  // supported SQLBulkOperations operations
  SQL_CA1_BULK_ADD                                  = $00010000;
  SQL_CA1_BULK_UPDATE_BY_BOOKMARK                   = $00020000;
  SQL_CA1_BULK_DELETE_BY_BOOKMARK                   = $00040000;
  SQL_CA1_BULK_FETCH_BY_BOOKMARK                    = $00080000;

  // supported values for SQL_ATTR_SCROLL_CONCURRENCY
  SQL_CA2_READ_ONLY_CONCURRENCY                     = $00000001;
  SQL_CA2_LOCK_CONCURRENCY                          = $00000002;
  SQL_CA2_OPT_ROWVER_CONCURRENCY                    = $00000004;
  SQL_CA2_OPT_VALUES_CONCURRENCY                    = $00000008;

  // sensitivity of the cursor to its own inserts, deletes, and updates
  SQL_CA2_SENSITIVITY_ADDITIONS                     = $00000010;
  SQL_CA2_SENSITIVITY_DELETIONS                     = $00000020;
  SQL_CA2_SENSITIVITY_UPDATES                       = $00000040;

  // semantics of SQL_ATTR_MAX_ROWS
  SQL_CA2_MAX_ROWS_SELECT                           = $00000080;
  SQL_CA2_MAX_ROWS_INSERT                           = $00000100;
  SQL_CA2_MAX_ROWS_DELETE                           = $00000200;
  SQL_CA2_MAX_ROWS_UPDATE                           = $00000400;
  SQL_CA2_MAX_ROWS_CATALOG                          = $00000800;
  SQL_CA2_MAX_ROWS_AFFECTS_ALL                      = SQL_CA2_MAX_ROWS_SELECT or SQL_CA2_MAX_ROWS_INSERT or SQL_CA2_MAX_ROWS_DELETE or SQL_CA2_MAX_ROWS_UPDATE or SQL_CA2_MAX_ROWS_CATALOG;

  // semantics of SQL_DIAG_CURSOR_ROW_COUNT
  SQL_CA2_CRC_EXACT                                 = $00001000;
  SQL_CA2_CRC_APPROXIMATE                           = $00002000;

  // the kinds of positioned statements that can be simulated
  SQL_CA2_SIMULATE_NON_UNIQUE                       = $00004000;
  SQL_CA2_SIMULATE_TRY_UNIQUE                       = $00008000;
  SQL_CA2_SIMULATE_UNIQUE                           = $00010000;

  // SQL_ODBC_API_CONFORMANCE values
  SQL_OAC_NONE                                      = $0000;
  SQL_OAC_LEVEL1                                    = $0001;
  SQL_OAC_LEVEL2                                    = $0002;

  // SQL_ODBC_SAG_CLI_CONFORMANCE values
  SQL_OSCC_NOT_COMPLIANT                            = $0000;
  SQL_OSCC_COMPLIANT                                = $0001;

  // SQL_ODBC_SQL_CONFORMANCE values
  SQL_OSC_MINIMUM                                   = $0000;
  SQL_OSC_CORE                                      = $0001;
  SQL_OSC_EXTENDED                                  = $0002;


  // SQL_CONCAT_NULL_BEHAVIOR values
  SQL_CB_NULL                                       = $0000;
  SQL_CB_NON_NULL                                   = $0001;

  // SQL_SCROLL_OPTIONS masks
  SQL_SO_FORWARD_ONLY                               = $00000001;
  SQL_SO_KEYSET_DRIVEN                              = $00000002;
  SQL_SO_DYNAMIC                                    = $00000004;
  SQL_SO_MIXED                                      = $00000008;
  SQL_SO_STATIC                                     = $00000010;

  // SQL_FETCH_DIRECTION masks
  // SQL_FETCH_RESUME is no longer supported
  SQL_FD_FETCH_RESUME                               = $00000040;
  SQL_FD_FETCH_BOOKMARK                             = $00000080;

  // SQL_TXN_ISOLATION_OPTION masks
  // SQL_TXN_VERSIONING is no longer supported
  SQL_TXN_VERSIONING                                = $00000010;

  // SQL_CORRELATION_NAME values
  SQL_CN_NONE                                       = $0000;
  SQL_CN_DIFFERENT                                  = $0001;
  SQL_CN_ANY                                        = $0002;

  // SQL_NON_NULLABLE_COLUMNS values
  SQL_NNC_NULL                                      = $0000;
  SQL_NNC_NON_NULL                                  = $0001;

  // SQL_NULL_COLLATION values
  SQL_NC_START                                      = $0002;
  SQL_NC_END                                        = $0004;

  // SQL_FILE_USAGE values
  SQL_FILE_NOT_SUPPORTED                            = $0000;
  SQL_FILE_TABLE                                    = $0001;
  SQL_FILE_QUALIFIER                                = $0002;
  SQL_FILE_CATALOG                                  = SQL_FILE_QUALIFIER;

  // SQL_GETDATA_EXTENSIONS values
  SQL_GD_BLOCK                                      = $00000004;
  SQL_GD_BOUND                                      = $00000008;

  // SQL_POSITIONED_STATEMENTS masks
  SQL_PS_POSITIONED_DELETE                          = $00000001;
  SQL_PS_POSITIONED_UPDATE                          = $00000002;
  SQL_PS_SELECT_FOR_UPDATE                          = $00000004;

  // SQL_GROUP_BY values
  SQL_GB_NOT_SUPPORTED                              = $0000;
  SQL_GB_GROUP_BY_EQUALS_SELECT                     = $0001;
  SQL_GB_GROUP_BY_CONTAINS_SELECT                   = $0002;
  SQL_GB_NO_RELATION                                = $0003;
  SQL_GB_COLLATE                                    = $0004;

  // SQL_OWNER_USAGE masks
  SQL_OU_DML_STATEMENTS                             = $00000001;
  SQL_OU_PROCEDURE_INVOCATION                       = $00000002;
  SQL_OU_TABLE_DEFINITION                           = $00000004;
  SQL_OU_INDEX_DEFINITION                           = $00000008;
  SQL_OU_PRIVILEGE_DEFINITION                       = $00000010;

  // SQL_SCHEMA_USAGE masks
  SQL_SU_DML_STATEMENTS                             = SQL_OU_DML_STATEMENTS;
  SQL_SU_PROCEDURE_INVOCATION                       = SQL_OU_PROCEDURE_INVOCATION;
  SQL_SU_TABLE_DEFINITION                           = SQL_OU_TABLE_DEFINITION;
  SQL_SU_INDEX_DEFINITION                           = SQL_OU_INDEX_DEFINITION;
  SQL_SU_PRIVILEGE_DEFINITION                       = SQL_OU_PRIVILEGE_DEFINITION;

  // SQL_QUALIFIER_USAGE masks
  SQL_QU_DML_STATEMENTS                             = $00000001;
  SQL_QU_PROCEDURE_INVOCATION                       = $00000002;
  SQL_QU_TABLE_DEFINITION                           = $00000004;
  SQL_QU_INDEX_DEFINITION                           = $00000008;
  SQL_QU_PRIVILEGE_DEFINITION                       = $00000010;

  // SQL_CATALOG_USAGE masks
  SQL_CU_DML_STATEMENTS                             = SQL_QU_DML_STATEMENTS;
  SQL_CU_PROCEDURE_INVOCATION                       = SQL_QU_PROCEDURE_INVOCATION;
  SQL_CU_TABLE_DEFINITION                           = SQL_QU_TABLE_DEFINITION;
  SQL_CU_INDEX_DEFINITION                           = SQL_QU_INDEX_DEFINITION;
  SQL_CU_PRIVILEGE_DEFINITION                       = SQL_QU_PRIVILEGE_DEFINITION;

  // SQL_SUBQUERIES masks
  SQL_SQ_COMPARISON                                 = $00000001;
  SQL_SQ_EXISTS                                     = $00000002;
  SQL_SQ_IN                                         = $00000004;
  SQL_SQ_QUANTIFIED                                 = $00000008;
  SQL_SQ_CORRELATED_SUBQUERIES                      = $00000010;

  // SQL_UNION masks
  SQL_U_UNION                                       = $00000001;
  SQL_U_UNION_ALL                                   = $00000002;

  // SQL_BOOKMARK_PERSISTENCE values
  SQL_BP_CLOSE                                      = $00000001;
  SQL_BP_DELETE                                     = $00000002;
  SQL_BP_DROP                                       = $00000004;
  SQL_BP_TRANSACTION                                = $00000008;
  SQL_BP_UPDATE                                     = $00000010;
  SQL_BP_OTHER_HSTMT                                = $00000020;
  SQL_BP_SCROLL                                     = $00000040;

  // SQL_STATIC_SENSITIVITY values
  SQL_SS_ADDITIONS                                  = $00000001;
  SQL_SS_DELETIONS                                  = $00000002;
  SQL_SS_UPDATES                                    = $00000004;

  // SQL_VIEW values
  SQL_CV_CREATE_VIEW                                = $00000001;
  SQL_CV_CHECK_OPTION                               = $00000002;
  SQL_CV_CASCADED                                   = $00000004;
  SQL_CV_LOCAL                                      = $00000008;

  // SQL_LOCK_TYPES masks
  SQL_LCK_NO_CHANGE                                 = $00000001;
  SQL_LCK_EXCLUSIVE                                 = $00000002;
  SQL_LCK_UNLOCK                                    = $00000004;

  // SQL_POS_OPERATIONS masks
  SQL_POS_POSITION                                  = $00000001;
  SQL_POS_REFRESH                                   = $00000002;
  SQL_POS_UPDATE                                    = $00000004;
  SQL_POS_DELETE                                    = $00000008;
  SQL_POS_ADD                                       = $00000010;

  // SQL_QUALIFIER_LOCATION values
  SQL_QL_START                                      = $0001;
  SQL_QL_END                                        = $0002;


  // Column types and scopes in SQLSpecialColumns.
  {$EXTERNALSYM SQL_BEST_ROWID}
  SQL_BEST_ROWID                                    = 1;
  {$EXTERNALSYM SQL_ROWVER}
  SQL_ROWVER                                        = 2;


  // Here start return values for ODBC 3.0 SQLGetInfo 
  // SQL_AGGREGATE_FUNCTIONS bitmasks
  SQL_AF_AVG                                        = $00000001;
  SQL_AF_COUNT                                      = $00000002;
  SQL_AF_MAX                                        = $00000004;
  SQL_AF_MIN                                        = $00000008;
  SQL_AF_SUM                                        = $00000010;
  SQL_AF_DISTINCT                                   = $00000020;
  SQL_AF_ALL                                        = SQL_AF_AVG or SQL_AF_COUNT or SQL_AF_MAX or SQL_AF_MIN or SQL_AF_SUM or SQL_AF_DISTINCT;

  SQL_DATA_LEN_AT_EXEC_OFFSET                       = -100;



type

  SQLCHAR = TGMChar;
  SQLPCHAR = PGMChar;
  SQLSCHAR = {$IFDEF UNICODE}SmallInt{$ELSE}Byte{$ENDIF};
  SQLDATE = TGMChar;
  SQLDECIMAL = TGMChar;
  SQLDOUBLE = double;
  SQLFLOAT = double;
  SQLINTEGER = LongInt;
  SQLPINTEGER = ^SQLINTEGER;
  SQLUINTEGER = LongWord;
  SQLPUINTEGER = ^SQLUINTEGER;
  SQLNUMERIC = TGMChar;
  SQLPOINTER = Pointer;
  SQLPPOINTER = ^SQLPOINTER;
  SQLREAL = single;
  SQLSMALLINT = Smallint;
  SQLPSMALLINT = ^SQLSMALLINT;
  SQLUSMALLINT = Word;
  SQLPUSMALLINT = ^SQLUSMALLINT;
  SQLTIME = TGMChar;
  SQLTIMESTAMP = TGMChar;
  SQLVARCHAR = TGMChar;

  SQLRETURN = SQLSMALLINT;

  SQLHANDLE = THandle;
  SQLPHANDLE = ^SQLHANDLE;

  SQLHENV = SQLHANDLE;
  SQLHDBC = SQLHANDLE;
  SQLHSTMT = SQLHANDLE;
  SQLHDESC = SQLHANDLE;

  RETCODE = SmallInt;

  {$IFDEF CPU64}
  SQLLEN = Int64;
  SQLULEN = QWord;
  SQLSETPOSIROW = SQLULEN;
  {$ELSE}
  SQLLEN = LongInt;
  SQLULEN = LongWord;
  SQLSETPOSIROW = SQLUSMALLINT;
  {$ENDIF}
  PSQLLEN = ^SQLLEN;
  PSQLULEN = ^SQLULEN;

  SQLHWND = type THandle;

  PSQL_DATE_STRUCT = ^SQL_DATE_STRUCT;
  SQL_DATE_STRUCT = packed record
   year: SQLSMALLINT;
   month: SQLUSMALLINT;
   day: SQLUSMALLINT;
  end;

  PSQL_TIME_STRUCT = ^SQL_TIME_STRUCT;
  SQL_TIME_STRUCT = packed record
   hour: SQLUSMALLINT;
   minute: SQLUSMALLINT;
   second: SQLUSMALLINT;
  end;

  PSQL_TIMESTAMP_STRUCT = ^SQL_TIMESTAMP_STRUCT;
  SQL_TIMESTAMP_STRUCT = packed record
   year: SQLSMALLINT;
   month: SQLUSMALLINT;
   day: SQLUSMALLINT;
   hour: SQLUSMALLINT;
   minute: SQLUSMALLINT;
   second: SQLUSMALLINT;
   fraction: SQLUINTEGER;
  end;

  PSQL_YEAR_MONTH_STRUCT = ^SQL_YEAR_MONTH_STRUCT;
  SQL_YEAR_MONTH_STRUCT = packed record
   year: SQLUINTEGER;
   month: SQLUINTEGER;
  end;

  PSQL_DAY_SECOND_STRUCT = ^SQL_DAY_SECOND_STRUCT;
  SQL_DAY_SECOND_STRUCT = packed record
   day: SQLUINTEGER;
   hour: SQLUINTEGER;
   minute: SQLUINTEGER;
   second: SQLUINTEGER;
   fraction: SQLUINTEGER;
  end;

  SQLINTERVAL = LongInt;

  PSQL_INTERVAL_STRUCT = ^SQL_INTERVAL_STRUCT;
  SQL_INTERVAL_STRUCT = packed record
   interval_type: SQLINTERVAL;
   interval_sign: SQLSMALLINT;
   case LongInt of
    0: (year_month: SQL_YEAR_MONTH_STRUCT);
    1: (day_second: SQL_DAY_SECOND_STRUCT);
  end;

  ODBCINT64 = Int64;
  SQLBIGINT = Int64;
  SQLUBIGINT = Int64;

  PSQL_NUMERIC_STRUCT = ^SQL_NUMERIC_STRUCT;
  SQL_NUMERIC_STRUCT = packed record
   precision: SQLCHAR;
   scale: SQLSCHAR;
   sign: SQLCHAR;       { 1 if positive, 0 if negative }
   val: array [0..SQL_MAX_NUMERIC_LEN-1] of SQLCHAR;
  end;


  PSQLErrorDesc = ^TSQLErrorDesc;
  TSQLErrorDesc = record
    ReturnCode: SQLRETURN;
    Code: TGMString;
    Origin: TGMString;
    SubClassOrigin: TGMString;
    Msg: TGMString;
    Connection: TGMString;
    Server: TGMString;
    NativeCode: SQLINTEGER;
  end;



  BOOKMARK = SQLULEN;
  SQLWCHAR = WideChar;

  SQLGUID = TGUID;

  TOdbcVersion = (odbc2x, odbc3x);
  TOdbcConnectionPooling = (cpOff, cpOnePoolPerDriver, cpOnePoolPerEnvironment);
  TOdbcConnectionPoolSelectStrategy = (ssExactMatch, ssRelaxedMatch);
  TCursorOrigin = (coUseODBCCursorsIfNeeded, coUseODBCCursors, coUseDriverCursors);
  TTransactionIsolation = (tiReadUncommitted, tiReadCommitted, tiRepeatableRead, tiSerializable);
  TTransactionIsolations = set of TTransactionIsolation;
  TUpdateStrategy = (usReadOnly, usMinimalLock, usCompareRecordVersionBeforeWrite, usCompareValuesBeforeWrite, usUseDriverDefault);
  TCursorSensitivity = (csUnspecified, csInsensitive, csReflectChanges, csUseDriverDefault);
  TDSNKind = (dsnUser, dsnSystem);
  TPositionedUpdateSimulation = (pusAllowNonUniqueUpdate, pusTryUniqueUpdate, pusGuaranteeUniqueUpdate, pusUseDriverDefault);

  TRowStatusArray = array [0..High(Word)] of SQLSMALLINT;
  PRowStatusArray = ^TRowStatusArray;



const

  { -------------------------------------------- }
  { ---- Const not defined by ODBC Standard ---- }
  { -------------------------------------------- }

  cInvalidHandleType = -1;
  cOdbcBookmarkColPos = 0;
  cOdbcInvalidHandle = SQL_NULL_HANDLE;

  cSqlDefaultTransactionIsolation = [tiReadCommitted];

  cOdbcSeverity: array [Boolean] of TGMSeverityLevel = (svInformation, svError);


  cOdbcErrGeneral = 'HY000';
  cOdbcErrOptionalNotImplemented = 'HYC00';


  { --------------------------- }
  { ---- API Routine Names ---- }
  { --------------------------- }

  cStrSQLAllocConnect            = 'SQLAllocConnect';
  cStrSQLAllocEnv                = 'SQLAllocEnv';
  cStrSQLAllocHandle             = 'SQLAllocHandle';
  cStrSQLAllocStmt               = 'SQLAllocStmt';
  cStrSQLBindCol                 = 'SQLBindCol';
  cStrSQLBindParam               = 'SQLBindParam';
  cStrSQLCancel                  = 'SQLCancel';
  cStrSQLCloseCursor             = 'SQLCloseCursor';
  cStrSQLColAttribute            = {$IFDEF UNICODE}'SQLColAttributeW'{$ELSE}'SQLColAttributeA'{$ENDIF};
  cStrSQLColumns                 = {$IFDEF UNICODE}'SQLColumnsW'{$ELSE}'SQLColumnsA'{$ENDIF};
  cStrSQLConnect                 = {$IFDEF UNICODE}'SQLConnectW'{$ELSE}'SQLConnectA'{$ENDIF};
  cStrSQLCopyDesc                = 'SQLCopyDesc';
  cStrSQLDataSources             = {$IFDEF UNICODE}'SQLDataSourcesW'{$ELSE}'SQLDataSourcesA'{$ENDIF};
  cStrSQLDescribeCol             = {$IFDEF UNICODE}'SQLDescribeColW'{$ELSE}'SQLDescribeColA'{$ENDIF};
  cStrSQLDisconnect              = 'SQLDisconnect';
  cStrSQLEndTran                 = 'SQLEndTran';
  cStrSQLError                   = {$IFDEF UNICODE}'SQLErrorW'{$ELSE}'SQLErrorA'{$ENDIF};
  cStrSQLExecDirect              = {$IFDEF UNICODE}'SQLExecDirectW'{$ELSE}'SQLExecDirectA'{$ENDIF};
  cStrSQLExecute                 = 'SQLExecute';
  cStrSQLFetch                   = 'SQLFetch';
  cStrSQLFetchScroll             = 'SQLFetchScroll';
  cStrSQLFreeConnect             = 'SQLFreeConnect';
  cStrSQLFreeEnv                 = 'SQLFreeEnv';
  cStrSQLFreeHandle              = 'SQLFreeHandle';
  cStrSQLFreeStmt                = 'SQLFreeStmt';
  cStrSQLGetConnectAttr          = {$IFDEF UNICODE}'SQLGetConnectAttrW'{$ELSE}'SQLGetConnectAttrA'{$ENDIF};
  cStrSQLGetConnectOption        = {$IFDEF UNICODE}'SQLGetConnectOptionW'{$ELSE}'SQLGetConnectOptionA'{$ENDIF};
  cStrSQLGetCursorName           = {$IFDEF UNICODE}'SQLGetCursorNameW'{$ELSE}'SQLGetCursorNameA'{$ENDIF};
  cStrSQLGetData                 = 'SQLGetData';
  cStrSQLGetDescField            = {$IFDEF UNICODE}'SQLGetDescFieldW'{$ELSE}'SQLGetDescFieldA'{$ENDIF};
  cStrSQLGetDescRec              = {$IFDEF UNICODE}'SQLGetDescRecW'{$ELSE}'SQLGetDescRecA'{$ENDIF};
  cStrSQLGetDiagField            = {$IFDEF UNICODE}'SQLGetDiagFieldW'{$ELSE}'SQLGetDiagFieldA'{$ENDIF};
  cStrSQLGetDiagRec              = {$IFDEF UNICODE}'SQLGetDiagRecW'{$ELSE}'SQLGetDiagRecA'{$ENDIF};
  cStrSQLGetEnvAttr              = 'SQLGetEnvAttr';
  cStrSQLGetFunctions            = 'SQLGetFunctions';
  cStrSQLGetInfo                 = {$IFDEF UNICODE}'SQLGetInfoW'{$ELSE}'SQLGetInfoA'{$ENDIF};
  cStrSQLGetStmtAttr             = {$IFDEF UNICODE}'SQLGetStmtAttrW'{$ELSE}'SQLGetStmtAttrA'{$ENDIF};
  cStrSQLGetStmtOption           = 'SQLGetStmtOption';
  cStrSQLGetTypeInfo             = {$IFDEF UNICODE}'SQLGetTypeInfoW'{$ELSE}'SQLGetTypeInfoA'{$ENDIF};
  cStrSQLNumResultCols           = 'SQLNumResultCols';
  cStrSQLParamData               = 'SQLParamData';
  cStrSQLPrepare                 = {$IFDEF UNICODE}'SQLPrepareW'{$ELSE}'SQLPrepareA'{$ENDIF};
  cStrSQLPutData                 = 'SQLPutData';
  cStrSQLRowCount                = 'SQLRowCount';
  cStrSQLSetConnectAttr          = {$IFDEF UNICODE}'SQLSetConnectAttrW'{$ELSE}'SQLSetConnectAttrA'{$ENDIF};
  cStrSQLSetConnectOption        = {$IFDEF UNICODE}'SQLSetConnectOptionW'{$ELSE}'SQLSetConnectOptionA'{$ENDIF};
  cStrSQLSetCursorName           = {$IFDEF UNICODE}'SQLSetCursorNameW'{$ELSE}'SQLSetCursorNameA'{$ENDIF};
  cStrSQLSetDescField            = {$IFDEF UNICODE}'SQLSetDescFieldW'{$ELSE}'SQLSetDescFieldA'{$ENDIF};
  cStrSQLSetDescRec              = 'SQLSetDescRec';
  cStrSQLSetEnvAttr              = 'SQLSetEnvAttr';
  cStrSQLSetParam                = 'SQLSetParam';
  cStrSQLSetStmtAttr             = {$IFDEF UNICODE}'SQLSetStmtAttrW'{$ELSE}'SQLSetStmtAttrA'{$ENDIF};
  cStrSQLSetStmtOption           = 'SQLSetStmtOption';
  cStrSQLSpecialColumns          = {$IFDEF UNICODE}'SQLSpecialColumnsW'{$ELSE}'SQLSpecialColumnsA'{$ENDIF};
  cStrSQLStatistics              = {$IFDEF UNICODE}'SQLStatisticsW'{$ELSE}'SQLStatisticsA'{$ENDIF};
  cStrSQLTables                  = {$IFDEF UNICODE}'SQLTablesW'{$ELSE}'SQLTablesA'{$ENDIF};
  cStrSQLTransact                = 'SQLTransact';

  cStrSQLDriverConnect           = {$IFDEF UNICODE}'SQLDriverConnectW'{$ELSE}'SQLDriverConnectA'{$ENDIF};
  cStrSQLBrowseConnect           = {$IFDEF UNICODE}'SQLBrowseConnectW'{$ELSE}'SQLBrowseConnectA'{$ENDIF};
  cStrSQLBulkOperations          = 'SQLBulkOperations';
  cStrSQLColAttributes           = {$IFDEF UNICODE}'SQLColAttributesW'{$ELSE}'SQLColAttributesA'{$ENDIF};
  cStrSQLColumnPrivileges        = {$IFDEF UNICODE}'SQLColumnPrivilegesW'{$ELSE}'SQLColumnPrivilegesA'{$ENDIF};
  cStrSQLDescribeParam           = 'SQLDescribeParam';
  cStrSQLExtendedFetch           = 'SQLExtendedFetch';
  cStrSQLForeignKeys             = {$IFDEF UNICODE}'SQLForeignKeysW'{$ELSE}'SQLForeignKeysA'{$ENDIF};
  cStrSQLMoreResults             = 'SQLMoreResults';
  cStrSQLNativeSql               = {$IFDEF UNICODE}'SQLNativeSqlW'{$ELSE}'SQLNativeSqlA'{$ENDIF};
  cStrSQLNumParams               = 'SQLNumParams';
  cStrSQLParamOptions            = 'SQLParamOptions';
  cStrSQLPrimaryKeys             = {$IFDEF UNICODE}'SQLPrimaryKeysW'{$ELSE}'SQLPrimaryKeysA'{$ENDIF};
  cStrSQLProcedureColumns        = {$IFDEF UNICODE}'SQLProcedureColumnsW'{$ELSE}'SQLProcedureColumnsA'{$ENDIF};
  cStrSQLProcedures              = {$IFDEF UNICODE}'SQLProceduresW'{$ELSE}'SQLProceduresA'{$ENDIF};
  cStrSQLSetPos                  = 'SQLSetPos';
  cStrSQLTablePrivileges         = {$IFDEF UNICODE}'SQLTablePrivilegesW'{$ELSE}'SQLTablePrivilegesA'{$ENDIF};
  cStrSQLDrivers                 = {$IFDEF UNICODE}'SQLDriversW'{$ELSE}'SQLDriversA'{$ENDIF};
  cStrSQLBindParameter           = 'SQLBindParameter';
  cStrSQLAllocHandleStd          = 'SQLAllocHandleStd';
  cStrSQLSetScrollOptions        = 'SQLSetScrollOptions';

//cStrTraceOpenLogFile           = 'TraceOpenLogFile';
//cStrTraceCloseLogFile          = 'TraceCloseLogFile';
//cStrTraceReturn                = 'TraceReturn';
//cStrTraceVersion               = 'TraceVersion';


{ ---------------------------------- }
{ ---- Routines From ODBC32.DLL ---- }
{ ---------------------------------- }

{$EXTERNALSYM SQLAllocConnect}
function SQLAllocConnect(EnvironmentHandle: SQLHENV; var ConnectionHandle: SQLHDBC): SQLRETURN; stdcall;


{$EXTERNALSYM SQLAllocEnv}
function SQLAllocEnv(var EnvironmentHandle: SQLHENV): SQLRETURN; stdcall;

{$EXTERNALSYM SQLAllocHandle}
function SQLAllocHandle(HandleType: SQLSMALLINT;
            InputHandle: SQLHANDLE;
            var OutputHandle: SQLHANDLE): SQLRETURN; stdcall;

{$EXTERNALSYM SQLAllocStmt}
function SQLAllocStmt(ConnectionHandle: SQLHDBC; var StatementHandle: SQLHSTMT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLBindCol}
function SQLBindCol(StatementHandle: SQLHSTMT;
            ColumnNumber: SQLUSMALLINT; TargetType: SQLSMALLINT;
            TargetValue: SQLPOINTER; BufferLength: SQLLEN;
            pStrLen_or_Ind: PSQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLBindParam}
function SQLBindParam(StatementHandle: SQLHSTMT;
            ParameterNumber: SQLUSMALLINT; ValueType: SQLSMALLINT;
            ParameterType: SQLSMALLINT; ColumnSize: SQLULEN;
            DecimalDigits: SQLSMALLINT; ParameterValue: SQLPOINTER;
            var StrLen_or_Ind: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLCancel}
function SQLCancel(StatementHandle: SQLHSTMT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLCloseCursor}
function SQLCloseCursor(StatementHandle: SQLHSTMT): SQLRETURN; stdcall;


{$EXTERNALSYM SQLColAttribute}
function SQLColAttribute(StatementHandle: SQLHSTMT;
            ColumnNumber: SQLUSMALLINT; FieldIdentifier: SQLUSMALLINT;
            CharacterAttribute: SQLPOINTER; BufferLength: SQLSMALLINT;
            StringLengthPtr: SQLPSMALLINT; NumericAttribute: PSQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLColumns}
function SQLColumns(StatementHandle: SQLHSTMT;
            CatalogName: SQLPCHAR; NameLength1: SQLSMALLINT;
            SchemaName: SQLPCHAR; NameLength2: SQLSMALLINT;
            TableName: SQLPCHAR; NameLength3: SQLSMALLINT;
            ColumnName: SQLPCHAR; NameLength4: SQLSMALLINT): SQLRETURN; stdcall;


{$EXTERNALSYM SQLConnect}
function SQLConnect(ConnectionHandle: SQLHDBC;
            ServerName: SQLPCHAR; NameLength1: SQLSMALLINT;
            UserName: SQLPCHAR; NameLength2: SQLSMALLINT;
            Authentication: SQLPCHAR; NameLength3: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLCopyDesc}
function SQLCopyDesc(SourceDescHandle: SQLHDESC; TargetDescHandle: SQLHDESC): SQLRETURN; stdcall;

{$EXTERNALSYM SQLDataSources}
function SQLDataSources(EnvironmentHandle: SQLHENV;
            Direction: SQLUSMALLINT; ServerName: SQLPCHAR;
            BufferLength1: SQLSMALLINT; var NameLength1: SQLSMALLINT;
            Description: SQLPCHAR; BufferLength2: SQLSMALLINT;
            var NameLength2: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLDescribeCol}
function SQLDescribeCol(StatementHandle: SQLHSTMT;
            ColumnNumber: SQLUSMALLINT; ColumnName: SQLPCHAR;
            BufferLength: SQLSMALLINT; var NameLength: SQLSMALLINT;
            var DataType: SQLSMALLINT; var ColumnSize: SQLULEN;
            var DecimalDigits: SQLSMALLINT; var Nullable: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLDisconnect}
function SQLDisconnect(ConnectionHandle: SQLHDBC): SQLRETURN; stdcall;

{$EXTERNALSYM SQLEndTran}
function SQLEndTran(HandleType: SQLSMALLINT;
            Handle: SQLHANDLE;
            CompletionType: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLError}
function SQLError(EnvironmentHandle: SQLHENV;
            ConnectionHandle: SQLHDBC; StatementHandle: SQLHSTMT;
            Sqlstate: SQLPCHAR; var NativeError: SQLINTEGER;
            MessageText: SQLPCHAR; BufferLength: SQLSMALLINT;
            var TextLength: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLExecDirect}
function SQLExecDirect(StatementHandle: SQLHSTMT;
            StatementText: SQLPCHAR;
            TextLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLExecute}
function SQLExecute(StatementHandle: SQLHSTMT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFetch}
function SQLFetch(StatementHandle: SQLHSTMT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFetchScroll}
function SQLFetchScroll(StatementHandle: SQLHSTMT;
            FetchOrientation: SQLSMALLINT;
            FetchOffset: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFreeConnect}
function SQLFreeConnect(ConnectionHandle: SQLHDBC): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFreeEnv}
function SQLFreeEnv(EnvironmentHandle: SQLHENV): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFreeHandle}
function SQLFreeHandle(HandleType: SQLSMALLINT; Handle: SQLHANDLE): SQLRETURN; stdcall;

{$EXTERNALSYM SQLFreeStmt}
function SQLFreeStmt(StatementHandle: SQLHSTMT; Option: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetConnectAttr}
function SQLGetConnectAttr(ConnectionHandle: SQLHDBC;
            Attribute: SQLINTEGER; Value: SQLPOINTER;
            BufferLength: SQLINTEGER; pStringLength: SQLPINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetConnectOption}
function SQLGetConnectOption(ConnectionHandle: SQLHDBC;
            Option: SQLUSMALLINT;
            Value: SQLPOINTER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetCursorName}
function SQLGetCursorName(StatementHandle: SQLHSTMT;
            CursorName: SQLPCHAR; BufferLength: SQLSMALLINT;
            var NameLength: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetData}
function SQLGetData(StatementHandle: SQLHSTMT;
            ColumnNumber: SQLUSMALLINT; TargetType: SQLSMALLINT;
            TargetValue: SQLPOINTER; BufferLength: SQLLEN;
            pStrLen_or_Ind: PSQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetDescField}
function SQLGetDescField(DescriptorHandle: SQLHDESC;
            RecNumber: SQLSMALLINT; FieldIdentifier: SQLSMALLINT;
            Value: SQLPOINTER; BufferLength: SQLINTEGER;
            var StringLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetDescRec}
function SQLGetDescRec(DescriptorHandle: SQLHDESC;
            RecNumber: SQLSMALLINT; Name: SQLPCHAR;
            BufferLength: SQLSMALLINT; var StringLength: SQLSMALLINT;
            var Type_: SQLSMALLINT; var SubType: SQLSMALLINT;
            var Length: SQLLEN; var Precision: SQLSMALLINT;
            var Scale: SQLSMALLINT; var Nullable: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetDiagField}
function SQLGetDiagField(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
            RecNumber: SQLSMALLINT; DiagIdentifier: SQLSMALLINT;
            DiagInfo: SQLPOINTER; BufferLength: SQLSMALLINT;
            PStringLength: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetDiagRec}
function SQLGetDiagRec(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
            RecNumber: SQLSMALLINT; Sqlstate: SQLPCHAR;
            var NativeError: SQLINTEGER; MessageText: SQLPCHAR;
            BufferLength: SQLSMALLINT; var TextLength: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetEnvAttr}
function SQLGetEnvAttr(EnvironmentHandle: SQLHENV;
            Attribute: SQLINTEGER; Value: SQLPOINTER;
            BufferLength: SQLINTEGER; pStringLength: SQLPINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetFunctions}
function SQLGetFunctions(ConnectionHandle: SQLHDBC;
            FunctionId: SQLUSMALLINT;
            var Supported: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetInfo}
function SQLGetInfo(ConnectionHandle: SQLHDBC;
            InfoType: SQLUSMALLINT; InfoValue: SQLPOINTER;
            BufferLength: SQLSMALLINT; pStringLength: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetStmtAttr}
function SQLGetStmtAttr(StatementHandle: SQLHSTMT; Attribute: SQLINTEGER;
            Value: SQLPOINTER; BufferLength: SQLINTEGER;
            pStringLength: SQLPINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetStmtOption}
function SQLGetStmtOption(StatementHandle: SQLHSTMT;
            Option: SQLUSMALLINT;
            Value: SQLPOINTER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLGetTypeInfo}
function SQLGetTypeInfo(StatementHandle: SQLHSTMT; DataType: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLNumResultCols}
function SQLNumResultCols(StatementHandle: SQLHSTMT; var ColumnCount: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLParamData}
function SQLParamData(StatementHandle: SQLHSTMT; var Value: SQLPOINTER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLPrepare}
function SQLPrepare(StatementHandle: SQLHSTMT;
            StatementText: SQLPCHAR;
            TextLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLPutData}
function SQLPutData(StatementHandle: SQLHSTMT;
            Data: SQLPOINTER;
            StrLen_or_Ind: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLRowCount}
function SQLRowCount(StatementHandle: SQLHSTMT; var RowCount: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetConnectAttr}
function SQLSetConnectAttr(ConnectionHandle: SQLHDBC;
            Attribute: SQLINTEGER; Value: SQLPOINTER;
            StringLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetConnectOption}
function SQLSetConnectOption(ConnectionHandle: SQLHDBC;
            Option: SQLUSMALLINT;
            Value: SQLULEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetCursorName}
function SQLSetCursorName(StatementHandle: SQLHSTMT;
            CursorName: SQLPCHAR;
            NameLength: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetDescField}
function SQLSetDescField(DescriptorHandle: SQLHDESC;
            RecNumber: SQLSMALLINT; FieldIdentifier: SQLSMALLINT;
            Value: SQLPOINTER; BufferLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetDescRec}
function SQLSetDescRec(DescriptorHandle: SQLHDESC;
            RecNumber: SQLSMALLINT; Type_: SQLSMALLINT;
            SubType: SQLSMALLINT; Length: SQLLEN;
            Precision: SQLSMALLINT; Scale: SQLSMALLINT;
            Data: SQLPOINTER; var StringLength: SQLLEN;
            var Indicator: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetEnvAttr}
function SQLSetEnvAttr(EnvironmentHandle: SQLHENV;
            Attribute: SQLINTEGER; Value: SQLPOINTER;
            StringLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetParam}
function SQLSetParam(StatementHandle: SQLHSTMT;
            ParameterNumber: SQLUSMALLINT; ValueType: SQLSMALLINT;
            ParameterType: SQLSMALLINT; LengthPrecision: SQLULEN;
            ParameterScale: SQLSMALLINT; ParameterValue: SQLPOINTER;
            var StrLen_or_Ind: SQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetStmtAttr}
function SQLSetStmtAttr(StatementHandle: SQLHSTMT;
            Attribute: SQLINTEGER; Value: SQLPOINTER;
            StringLength: SQLINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetStmtOption}
function SQLSetStmtOption(StatementHandle: SQLHSTMT;
            Option: SQLUSMALLINT;
            Value: SQLULEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSpecialColumns}
function SQLSpecialColumns(StatementHandle: SQLHSTMT;
            IdentifierType: SQLUSMALLINT; CatalogName: SQLPCHAR;
            NameLength1: SQLSMALLINT; SchemaName: SQLPCHAR;
            NameLength2: SQLSMALLINT; TableName: SQLPCHAR;
            NameLength3: SQLSMALLINT; Scope: SQLUSMALLINT;
            Nullable: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLStatistics}
function SQLStatistics(StatementHandle: SQLHSTMT;
            CatalogName: SQLPCHAR; NameLength1: SQLSMALLINT;
            SchemaName: SQLPCHAR; NameLength2: SQLSMALLINT;
            TableName: SQLPCHAR; NameLength3: SQLSMALLINT;
            Unique: SQLUSMALLINT; Reserved: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLTables}
function SQLTables(StatementHandle: SQLHSTMT;
            CatalogName: SQLPCHAR; NameLength1: SQLSMALLINT;
            SchemaName: SQLPCHAR; NameLength2: SQLSMALLINT;
            TableName: SQLPCHAR; NameLength3: SQLSMALLINT;
            TableType: SQLPCHAR; NameLength4: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLTransact}
function SQLTransact(EnvironmentHandle: SQLHENV;
            ConnectionHandle: SQLHDBC;
            CompletionType: SQLUSMALLINT): SQLRETURN; stdcall;



{ --------------------------------- }
{ ---- Routines from SQLEXT.H  ---- }
{ --------------------------------- }

{$EXTERNALSYM SQLDriverConnect}
function SQLDriverConnect(
            hdbc: SQLHDBC;
            hwnd: SQLHWND;
            szConnStrIn: SQLPCHAR;
            cbConnStrIn: SQLSMALLINT;
            szConnStrOut: SQLPCHAR;
            cbConnStrOutMax: SQLSMALLINT;
            pcbConnStrOut: SQLPSMALLINT;
            fDriverCompletion: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLBrowseConnect}
function SQLBrowseConnect(
            hdbc: SQLHDBC;
            szConnStrIn: SQLPCHAR;
            cbConnStrIn: SQLSMALLINT;
            szConnStrOut: SQLPCHAR;
            cbConnStrOutMax: SQLSMALLINT;
            pcbConnStrOut: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLBulkOperations}
function SQLBulkOperations(
            StatementHandle: SQLHSTMT;
            Operation: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLColAttributes}
function SQLColAttributes(
            hstmt: SQLHSTMT;
            icol: SQLUSMALLINT;
            fDescType: SQLUSMALLINT;
            rgbDesc: SQLPOINTER;
            cbDescMax: SQLSMALLINT;
            pcbDesc: SQLPSMALLINT;
            pfDesc: PSQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLColumnPrivileges}
function SQLColumnPrivileges(
            hstmt: SQLHSTMT;
            szCatalogName: SQLPCHAR;
            cbCatalogName: SQLSMALLINT;
            szSchemaName: SQLPCHAR;
            cbSchemaName: SQLSMALLINT;
            szTableName: SQLPCHAR;
            cbTableName: SQLSMALLINT;
            szColumnName: SQLPCHAR;
            cbColumnName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLDescribeParam}
function SQLDescribeParam(
            StatementHandle: SQLHSTMT;
            ParameterNumber: SQLUSMALLINT;
            DataTypePtr: SQLPSMALLINT;
            ParameterSizePtr: PSQLULEN;
            DecimalDigitsPtr: SQLPSMALLINT;
            NullablePtr: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLExtendedFetch}
function SQLExtendedFetch(
            StatementHandle: SQLHSTMT;
            FetchOrientation: SQLUSMALLINT;
            FetchOffset: SQLLEN;
            RowCountPtr: PSQLULEN;
            RowStatusArray: SQLPUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLForeignKeys}
function SQLForeignKeys(
            hstmt: SQLHSTMT;
            szPkCatalogName: SQLPCHAR;
            cbPkCatalogName: SQLSMALLINT;
            szPkSchemaName: SQLPCHAR;
            cbPkSchemaName: SQLSMALLINT;
            szPkTableName: SQLPCHAR;
            cbPkTableName: SQLSMALLINT;
            szFkCatalogName: SQLPCHAR;
            cbFkCatalogName: SQLSMALLINT;
            szFkSchemaName: SQLPCHAR;
            cbFkSchemaName: SQLSMALLINT;
            szFkTableName: SQLPCHAR;
            cbFkTableName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLMoreResults}
function SQLMoreResults(hstmt: SQLHSTMT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLNativeSql}
function SQLNativeSql(
            hdbc: SQLHDBC;
            szSqlStrIn: SQLPCHAR;
            cbSqlStrIn: SQLINTEGER;
            szSqlStr: SQLPCHAR;
            cbSqlStrMax: SQLINTEGER;
            pcbSqlStr: SQLPINTEGER): SQLRETURN; stdcall;

{$EXTERNALSYM SQLNumParams}
function SQLNumParams(
            StatementHandle: SQLHSTMT;
            pcpar: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLParamOptions}
function SQLParamOptions(
            hstmt: SQLHSTMT;
            crow: SQLULEN;
            pirow: PSQLULEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLPrimaryKeys}
function SQLPrimaryKeys(
            StatementHandle: SQLHSTMT;
            szCatalogName: SQLPCHAR;
            cbCatalogName: SQLSMALLINT;
            szSchemaName: SQLPCHAR;
            cbSchemaName: SQLSMALLINT;
            szTableName: SQLPCHAR;
            cbTableName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLProcedureColumns}
function SQLProcedureColumns(
            StatementHandle: SQLHSTMT;
            szCatalogName: SQLPCHAR;
            cbCatalogName: SQLSMALLINT;
            szSchemaName: SQLPCHAR;
            cbSchemaName: SQLSMALLINT;
            szProcName: SQLPCHAR;
            cbProcName: SQLSMALLINT;
            szColumnName: SQLPCHAR;
            cbColumnName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLProcedures}
function SQLProcedures(
            StatementHandle: SQLHSTMT;
            szCatalogName: SQLPCHAR;
            cbCatalogName: SQLSMALLINT;
            szSchemaName: SQLPCHAR;
            cbSchemaName: SQLSMALLINT;
            szProcName: SQLPCHAR;
            cbProcName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetPos}
function SQLSetPos(
            StatementHandle: SQLHSTMT;
            RowNumber: SQLSETPOSIROW;
            Operation: SQLUSMALLINT;
            LockType: SQLUSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLTablePrivileges}
function SQLTablePrivileges(
            StatementHandle: SQLHSTMT;
            szCatalogName: SQLPCHAR;
            cbCatalogName: SQLSMALLINT;
            szSchemaName: SQLPCHAR;
            cbSchemaName: SQLSMALLINT;
            szTableName: SQLPCHAR;
            cbTableName: SQLSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLDrivers}
function SQLDrivers(
            henv: SQLHENV;
            fDirection: SQLUSMALLINT;
            szDriverDesc: SQLPCHAR;
            cbDriverDescMax: SQLSMALLINT;
            pcbDriverDesc: SQLPSMALLINT;
            szDriverAttributes: SQLPCHAR;
            cbDrvrAttrMax: SQLSMALLINT;
            pcbDrvrAttr: SQLPSMALLINT): SQLRETURN; stdcall;

{$EXTERNALSYM SQLBindParameter}
function SQLBindParameter(
            StatementHandle: SQLHSTMT;
            ParameterNumber: SQLUSMALLINT;
            InputOutputType: SQLSMALLINT;
            ValueType: SQLSMALLINT;
            ParameterType: SQLSMALLINT;
            ColumnSize: SQLULEN;
            DecimalDigits: SQLSMALLINT;
            ParameterValuePtr: SQLPOINTER;
            BufferLength: SQLLEN;
            StrLen_or_IndPtr: PSQLLEN): SQLRETURN; stdcall;

{$EXTERNALSYM SQLAllocHandleStd}
function SQLAllocHandleStd(
            fHandleType: SQLSMALLINT;
            hInput: SQLHANDLE;
            phOutput: SQLPHANDLE): SQLRETURN; stdcall;

{$EXTERNALSYM SQLSetScrollOptions}
function SQLSetScrollOptions(
            StatementHandle: SQLHSTMT;
            fConcurrency: SQLUSMALLINT;
            crowKeyset: SQLLEN;
            crowRowset: SQLUSMALLINT): SQLRETURN; stdcall;



{ ------------------------ }
{ ---- Trace Routines ---- }
{ ------------------------ }

//{$EXTERNALSYM TraceOpenLogFile}
//function TraceOpenLogFile(StrA: PWideChar; StrB: PWideChar; C: LongWord): RETCODE; stdcall;
//
//{$EXTERNALSYM TraceCloseLogFile}
//function TraceCloseLogFile: RETCODE; stdcall;
//
//{$EXTERNALSYM TraceReturn}
//procedure TraceReturn(A: RETCODE; B: RETCODE); stdcall;
//
//{$EXTERNALSYM TraceVersion}
//function TraceVersion: Longword; stdcall;



{ ------------------------- }
{ ---- Global Routines ---- }
{ ------------------------- }

function ODBCSucceeded(const ReturnCode: SQLRETURN): Boolean;
//function ODBCIsValidFetch(const ReturnCode: SQLRETURN): Boolean;

function DateTimeFromODBCTimestamp(const ODBCTimeStampStruct: SQL_TIMESTAMP_STRUCT): TDateTime;

function DateTimeFromODBCDate(const ODBCDateStruct: SQL_DATE_STRUCT): TDateTime;

function DateTimeFromODBCTime(const ODBCTimeStruct: SQL_TIME_STRUCT): TDateTime;

function CurrencyFromODBCNumeric(const AODBCNumericStruct: SQL_NUMERIC_STRUCT): Currency;

procedure ODBCTimeStampFromDateTime(const ADateTime: TDateTime; var AODBCTimeStampStruct: SQL_TIMESTAMP_STRUCT);

procedure ODBCDateFromDateTime(const ADate: TDateTime; var AODBCDateStruct: SQL_DATE_STRUCT);

procedure ODBCTimeFromDateTime(const ATime: TDateTime; var AODBCTimeStruct: SQL_TIME_STRUCT);

procedure ODBCNumericFromCurrecy(const ACurrVal: Currency; var AODBCNumericStruct: SQL_NUMERIC_STRUCT);

function ODBCFetchDSN(const EnvironmentHandle: SQLHENV; const FetchKind: SQLUSMALLINT; var DataSourceName, DataSourceDescription: TGMString): Boolean;

function ODBCReturnCodeAsString(const ReturnCode: SQLRETURN): TGMString;

function ODBCErrorCount(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE): SQLINTEGER;

function ODBCGetDiagString(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT; const DiagIdentifier: SQLSMALLINT; const AMaxLen: LongInt = 8192): TGMString;
//function ODBCGetFixedLenDiagString(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT; const DiagIdentifier: SQLSMALLINT; const AFixedLen: LongInt): TGMString;

function ODBCIsNullDataLength(const AValue: SQLINTEGER): Boolean;

function ODBCCharSize(DataType: SQLSMALLINT): LongInt;

procedure ODBCCheck(const AReturnCode: SQLRETURN;
                    const AObj: TObject = nil;
                    const ARoutineName: TGMString = cDfltRoutineName;
//                  const ASQLStmtText: TGMString = '';
                    const AHandleType: SQLSMALLINT = cInvalidHandleType;
                    const AHandle: SQLHANDLE = cOdbcInvalidHandle); overload;

function ODBCRowStatusAsText(const ARowStatus: LongInt): TGMString;

function OdbcDataLenAtExec(const ADataLength: LongInt): LongInt; // <- C++ Macro SQL_LEN_DATA_AT_EXEC

function OdbcErrorDescAsString(const AValue: TSQLErrorDesc): TGMString;

function OdbcErrorDesc(const AHandleType: SQLSMALLINT;
                       const AHandle: SQLHANDLE;
                       const ADiagRecNo: LongInt;
                       const ASQLCode: SQLRETURN): TSQLErrorDesc;


{ ---- Field Attributes ---- }

function ODBCFieldName(const Handle: SQLHANDLE;
                       const Position: SQLUSMALLINT;
                       const Obj: TObject = nil;
                       const ACallingName: TGMString = cDfltRoutineName): TGMString;

function ODBCTypeName(const AHandle: SQLHANDLE;
                      const APosition: SQLUSMALLINT;
                      const AObj: TObject = nil;
                      const ACallingName: TGMString = cDfltRoutineName): TGMString;

function ODBCFieldOctetLength(const AHandle: SQLHANDLE;
                              const APosition: SQLUSMALLINT;
                              const AObj: TObject = nil;
                              const ACallingName: TGMString = cDfltRoutineName): SQLLEN;

function ODBCIsSignedField(const Handle: SQLHANDLE;
                           const Position: SQLUSMALLINT;
                           const Obj: TObject = nil;
                           const ACallingName: TGMString = cDfltRoutineName): Boolean;

function ODBCFieldDataType(const Handle: SQLHANDLE;
                           const Position: SQLUSMALLINT;
                           const Obj: TObject = nil;
                           const ACallingName: TGMString = cDfltRoutineName): SQLLEN;

function ODBCFieldNullValuesAllowed(const Handle: SQLHANDLE;
                                    const Position: SQLUSMALLINT;
                                    const Obj: TObject = nil;
                                    const ACallingName: TGMString = cDfltRoutineName): TGMAllowNullValues;

function ODBCFieldUpdatable(const Handle: SQLHANDLE;
                            const Position: SQLUSMALLINT;
                            const Obj: TObject = nil;
                            const ACallingName: TGMString = cDfltRoutineName): Boolean;

function ODBCFieldIsAutoIncrementing(const Handle: SQLHANDLE;
                                     const Position: SQLUSMALLINT;
                                     const Obj: TObject = nil;
                                     const ACallingName: TGMString = cDfltRoutineName): Boolean;

type

  TOdbcErrorDescArray = array of TSQLErrorDesc;


  EGMOdbcError = class(EGMException, IGMGetHRCode)
   protected
    FHandleType: SQLSMALLINT;
    FHandle: SQLHANDLE;
    FReturnCode: SQLRETURN;
    FErrorDescs: TOdbcErrorDescArray;

    procedure ClearErrorList;
    procedure ReadODBCErrors;

   public
    constructor CreateODBCError(const AReturnCode: SQLRETURN;
                                const AObj: TObject = nil;
                                const ARoutineName: TGMString = cDfltRoutineName;
//                              const ASQLStmtText: TGMString = '';
                                const AHandleType: SQLSMALLINT = cInvalidHandleType;
                                const AHandle: SQLHANDLE = cOdbcInvalidHandle;
                                const ASeverityLevel: TGMSeverityLevel = svError); virtual;

    constructor ObjError(const AMsg: TGMString = cDfltExceptionMsg;
                         const AObj: TObject = nil;
                         const ARoutineName: TGMString = cDfltRoutineName;
                         const ASeverityLevel: TGMSeverityLevel = svError;
                         const AHelpCtx: LongInt = cDfltHelpCtx); override;

    constructor IntfError(const AMsg: TGMString = cDfltExceptionMsg;
                          const AIntf: IUnknown = nil;
                          const ARoutineName: TGMString = cDfltRoutineName;
                          const ASeverityLevel: TGMSeverityLevel = svError;
                          const AHelpCtx: LongInt = cDfltHelpCtx); override;

    destructor Destroy; override;

    function ODBCErrMsgAsString: TGMString;
    function GetHRCode: HResult; stdcall;
    function HasErrorDesc(const AOdbcCode: TGMString): Boolean;

    property ErrorDescs: TOdbcErrorDescArray read FErrorDescs;
  end;



implementation

uses SysUtils;

resourcestring

  RStrSuccess = 'Success';
  RStrSuccessWithInfo = 'Success with info';
  RStrUnknownSQLReturnCode = 'Unknown Return Code';
  RStrNoData = 'No Data';
  RStrInvalidHandle = 'Invalid handle';
  RStrStillExecuting = 'Still executing';
  RStrDataNeeded = 'Data Needed';
  RStrReturnCode = 'ODBC Return Code';

  RStrDeletedRow = 'Deleted row';
  RStrUpdatedRow = 'Updated row';
  RStrInvalidRow = 'Invalid row';
  RStrNewRow = 'New row';
  RStrUnknownRowStatus = 'Unknown row status';


const

  ODBC32_DLL = 'ODBC32.DLL';
  CODBCFractionFactor = 1000000;


{ ------------------------------------------}
{ ---- External Routines in ODBC32.DLL ---- }
{ ------------------------------------------}

function SQLAllocConnect;            external ODBC32_DLL name cStrSQLAllocConnect;
function SQLAllocEnv;                external ODBC32_DLL name cStrSQLAllocEnv;
function SQLAllocHandle;             external ODBC32_DLL name cStrSQLAllocHandle;
function SQLAllocStmt;               external ODBC32_DLL name cStrSQLAllocStmt;
function SQLBindCol;                 external ODBC32_DLL name cStrSQLBindCol;
function SQLBindParam;               external ODBC32_DLL name cStrSQLBindParam;
function SQLCancel;                  external ODBC32_DLL name cStrSQLCancel;
function SQLCloseCursor;             external ODBC32_DLL name cStrSQLCloseCursor;
function SQLColAttribute;            external ODBC32_DLL name cStrSQLColAttribute;
function SQLColumns;                 external ODBC32_DLL name cStrSQLColumns;
function SQLConnect;                 external ODBC32_DLL name cStrSQLConnect;
function SQLCopyDesc;                external ODBC32_DLL name cStrSQLCopyDesc;
function SQLDataSources;             external ODBC32_DLL name cStrSQLDataSources;
function SQLDescribeCol;             external ODBC32_DLL name cStrSQLDescribeCol;
function SQLDisconnect;              external ODBC32_DLL name cStrSQLDisconnect;
function SQLEndTran;                 external ODBC32_DLL name cStrSQLEndTran;
function SQLError;                   external ODBC32_DLL name cStrSQLError;
function SQLExecDirect;              external ODBC32_DLL name cStrSQLExecDirect;
function SQLExecute;                 external ODBC32_DLL name cStrSQLExecute;
function SQLFetch;                   external ODBC32_DLL name cStrSQLFetch;
function SQLFetchScroll;             external ODBC32_DLL name cStrSQLFetchScroll;
function SQLFreeConnect;             external ODBC32_DLL name cStrSQLFreeConnect;
function SQLFreeEnv;                 external ODBC32_DLL name cStrSQLFreeEnv;
function SQLFreeHandle;              external ODBC32_DLL name cStrSQLFreeHandle;
function SQLFreeStmt;                external ODBC32_DLL name cStrSQLFreeStmt;
function SQLGetConnectAttr;          external ODBC32_DLL name cStrSQLGetConnectAttr;
function SQLGetConnectOption;        external ODBC32_DLL name cStrSQLGetConnectOption;
function SQLGetCursorName;           external ODBC32_DLL name cStrSQLGetCursorName;
function SQLGetData;                 external ODBC32_DLL name cStrSQLGetData;
function SQLGetDescField;            external ODBC32_DLL name cStrSQLGetDescField;
function SQLGetDescRec;              external ODBC32_DLL name cStrSQLGetDescRec;
function SQLGetDiagField;            external ODBC32_DLL name cStrSQLGetDiagField;
function SQLGetDiagRec;              external ODBC32_DLL name cStrSQLGetDiagRec;
function SQLGetEnvAttr;              external ODBC32_DLL name cStrSQLGetEnvAttr;
function SQLGetFunctions;            external ODBC32_DLL name cStrSQLGetFunctions;
function SQLGetInfo;                 external ODBC32_DLL name cStrSQLGetInfo;
function SQLGetStmtAttr;             external ODBC32_DLL name cStrSQLGetStmtAttr;
function SQLGetStmtOption;           external ODBC32_DLL name cStrSQLGetStmtOption;
function SQLGetTypeInfo;             external ODBC32_DLL name cStrSQLGetTypeInfo;
function SQLNumResultCols;           external ODBC32_DLL name cStrSQLNumResultCols;
function SQLParamData;               external ODBC32_DLL name cStrSQLParamData;
function SQLPrepare;                 external ODBC32_DLL name cStrSQLPrepare;
function SQLPutData;                 external ODBC32_DLL name cStrSQLPutData;
function SQLRowCount;                external ODBC32_DLL name cStrSQLRowCount;
function SQLSetConnectAttr;          external ODBC32_DLL name cStrSQLSetConnectAttr;
function SQLSetConnectOption;        external ODBC32_DLL name cStrSQLSetConnectOption;
function SQLSetCursorName;           external ODBC32_DLL name cStrSQLSetCursorName;
function SQLSetDescField;            external ODBC32_DLL name cStrSQLSetDescField;
function SQLSetDescRec;              external ODBC32_DLL name cStrSQLSetDescRec;
function SQLSetEnvAttr;              external ODBC32_DLL name cStrSQLSetEnvAttr;
function SQLSetParam;                external ODBC32_DLL name cStrSQLSetParam;
function SQLSetStmtAttr;             external ODBC32_DLL name cStrSQLSetStmtAttr;
function SQLSetStmtOption;           external ODBC32_DLL name cStrSQLSetStmtOption;
function SQLSpecialColumns;          external ODBC32_DLL name cStrSQLSpecialColumns;
function SQLStatistics;              external ODBC32_DLL name cStrSQLStatistics;
function SQLTables;                  external ODBC32_DLL name cStrSQLTables;
function SQLTransact;                external ODBC32_DLL name cStrSQLTransact;

function SQLDriverConnect;           external ODBC32_DLL name cStrSQLDriverConnect;
function SQLBrowseConnect;           external ODBC32_DLL name cStrSQLBrowseConnect;
function SQLBulkOperations;          external ODBC32_DLL name cStrSQLBulkOperations;
function SQLColAttributes;           external ODBC32_DLL name cStrSQLColAttributes;
function SQLColumnPrivileges;        external ODBC32_DLL name cStrSQLColumnPrivileges;
function SQLDescribeParam;           external ODBC32_DLL name cStrSQLDescribeParam;
function SQLExtendedFetch;           external ODBC32_DLL name cStrSQLExtendedFetch;
function SQLForeignKeys;             external ODBC32_DLL name cStrSQLForeignKeys;
function SQLMoreResults;             external ODBC32_DLL name cStrSQLMoreResults;
function SQLNativeSql;               external ODBC32_DLL name cStrSQLNativeSql;
function SQLNumParams;               external ODBC32_DLL name cStrSQLNumParams;
function SQLParamOptions;            external ODBC32_DLL name cStrSQLParamOptions;
function SQLPrimaryKeys;             external ODBC32_DLL name cStrSQLPrimaryKeys;
function SQLProcedureColumns;        external ODBC32_DLL name cStrSQLProcedureColumns;
function SQLProcedures;              external ODBC32_DLL name cStrSQLProcedures;
function SQLSetPos;                  external ODBC32_DLL name cStrSQLSetPos;
function SQLTablePrivileges;         external ODBC32_DLL name cStrSQLTablePrivileges;
function SQLDrivers;                 external ODBC32_DLL name cStrSQLDrivers;
function SQLBindParameter;           external ODBC32_DLL name cStrSQLBindParameter;
function SQLAllocHandleStd;          external ODBC32_DLL name cStrSQLAllocHandleStd;
function SQLSetScrollOptions;        external ODBC32_DLL name cStrSQLSetScrollOptions;

//function TraceOpenLogFile;           external ODBC32_DLL name cStrTraceOpenLogFile;
//function TraceCloseLogFile;          external ODBC32_DLL name cStrTraceCloseLogFile;
//procedure TraceReturn;               external ODBC32_DLL name cStrTraceReturn;
//function TraceVersion;               external ODBC32_DLL name cStrTraceVersion;


{ ------------------------- }
{ ---- Global Routines ---- }
{ ------------------------- }

function ODBCSucceeded(const ReturnCode: SQLRETURN): Boolean;
begin
  Result := (ReturnCode = SQL_SUCCESS) or (ReturnCode = SQL_SUCCESS_WITH_INFO);
end;

{function ODBCIsValidFetch(const ReturnCode: SQLRETURN): Boolean;
begin
  Result := (ReturnCode <> SQL_NO_DATA) and (ReturnCode <> SQL_INVALID_HANDLE);
end;}

function ODBCReturnCodeAsString(const ReturnCode: SQLRETURN): TGMString;
begin
  case ReturnCode of
   SQL_SUCCESS:           Result := RStrSuccess;
   SQL_SUCCESS_WITH_INFO: Result := RStrSuccessWithInfo;
   SQL_NO_DATA:           Result := RStrNoData;
   SQL_ERROR:             Result := RStrError;
   SQL_INVALID_HANDLE:    Result := RStrInvalidHandle;
   SQL_STILL_EXECUTING:   Result := RStrStillExecuting;
   SQL_NEED_DATA:         Result := RStrDataNeeded;
   else                   Result := RStrUnknownSQLReturnCode;
  end;
  //Result := RStrReturnCode + ': ' + Result;
end;

procedure ODBCCheck(const AReturnCode: SQLRETURN;
                    const AObj: TObject;
                    const ARoutineName: TGMString;
//                  const ASQLStmtText: TGMString;
                    const AHandleType: SQLSMALLINT;
                    const AHandle: SQLHANDLE);
begin
  if not ODBCSucceeded(AReturnCode) then                              // ASQLStmtText
     raise EGMOdbcError.CreateODBCError(AReturnCode, AObj, ARoutineName, AHandleType, AHandle, cOdbcSeverity[AReturnCode < 0]);
end;

function ODBCGetDiagInt(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT; const DiagIdentifier: SQLSMALLINT): SQLINTEGER;
begin
  if not ODBCSucceeded(SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, @Result, SQL_IS_INTEGER, nil)) then Result := 0;
end;

function ODBCErrorCount(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE): SQLINTEGER;
begin
  Result := ODBCGetDiagInt(HandleType, Handle, 0, SQL_DIAG_NUMBER);
end;

//function ODBCGetFixedLenDiagString(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT; const DiagIdentifier: SQLSMALLINT; const AFixedLen: LongInt): TGMString;
//var len: SQLSMALLINT;
//begin
//SetLength(Result, AFixedLen);
////len := AMaxLen;
//if ODBCSucceeded(SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, PGMChar(Result), Length(Result) * SizeOf(TGMChar), @len)) then
//  SetLength(Result, len div SizeOf(TGMChar))
//  else
//  Result := '';
//end;

function ODBCGetDiagString(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT; const DiagIdentifier: SQLSMALLINT; const AMaxLen: LongInt): TGMString;
var len: SQLSMALLINT;
begin
  SetLength(Result, AMaxLen);
  len := AMaxLen;
  if ODBCSucceeded(SQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, PGMChar(Result), Length(Result) * SizeOf(TGMChar), @len)) then
    SetLength(Result, GMStrLen(PGMChar(Result), Min(Length(Result), len div SizeOf(TGMChar))))
  else Result := '';
end;

function ODBCISValidDiagRecNo(const HandleType: SQLSMALLINT; const Handle: SQLHANDLE; const RecNumber: SQLSMALLINT): Boolean;
var bufStr: TGMString; len: SQLSMALLINT;
begin
  SetLength(bufStr, 10);
  Result := ODBCSucceeded(SQLGetDiagField(HandleType, Handle, RecNumber, SQL_DIAG_SQLSTATE, SQLPOINTER(bufStr), Length(bufStr) * SizeOf(TGMChar), @len));
end;

function ODBCFetchDSN(const EnvironmentHandle: SQLHENV; const FetchKind: SQLUSMALLINT; var DataSourceName, DataSourceDescription: TGMString): Boolean;
var dsnNameLen, dsnDescLen: SQLSMALLINT; RetCode: SQLRETURN;
const cStrLen = 512;
begin
  SetLength(DataSourceName, cStrLen);
  SetLength(DataSourceDescription, cStrLen);
  RetCode := SQLDataSources(EnvironmentHandle, FetchKind, SQLPCHAR(DataSourceName), cStrLen, dsnNameLen, SQLPCHAR(DataSourceDescription), cStrLen, dsnDescLen);
  if ODBCSucceeded(RetCode) then
   begin
    SetLength(DataSourceName, dsnNameLen);
    SetLength(DataSourceDescription, dsnDescLen);
    Result := True;
   end
  else
   begin
    DataSourceName := '';
    DataSourceDescription := '';
    Result := False;
   end;
end;

function DateTimeFromODBCTimestamp(const ODBCTimeStampStruct: SQL_TIMESTAMP_STRUCT): TDateTime;
begin
  Result := EncodeDate(ODBCTimeStampStruct.year, ODBCTimeStampStruct.month, ODBCTimeStampStruct.day) +
            EncodeTime(ODBCTimeStampStruct.hour, ODBCTimeStampStruct.minute, ODBCTimeStampStruct.second, ODBCTimeStampStruct.fraction div CODBCFractionFactor);
end;

function DateTimeFromODBCDate(const ODBCDateStruct: SQL_DATE_STRUCT): TDateTime;
begin
  Result := EncodeDate(ODBCDateStruct.year, ODBCDateStruct.month, ODBCDateStruct.day);
end;

function DateTimeFromODBCTime(const ODBCTimeStruct: SQL_TIME_STRUCT): TDateTime;
begin
  Result := EncodeTime(ODBCTimeStruct.hour, ODBCTimeStruct.minute, ODBCTimeStruct.second, 0);
end;

procedure ODBCTimeStampFromDateTime(const ADateTime: TDateTime; var AODBCTimeStampStruct: SQL_TIMESTAMP_STRUCT);
var Year, Month, Day, Hour, Minute, Second, MilliSec: Word;
begin
  DecodeDate(ADateTime, Year, Month, Day);
  DecodeTime(ADateTime, Hour, Minute, Second, MilliSec);
  AODBCTimeStampStruct.year := Year;
  AODBCTimeStampStruct.month := Month;
  AODBCTimeStampStruct.day := Day;
  AODBCTimeStampStruct.hour := Hour;
  AODBCTimeStampStruct.minute := Minute;
  AODBCTimeStampStruct.second := Second;
  AODBCTimeStampStruct.fraction := MilliSec * CODBCFractionFactor;
end;

procedure ODBCDateFromDateTime(const ADate: TDateTime; var AODBCDateStruct: SQL_DATE_STRUCT);
var Year, Month, Day: Word;
begin
  DecodeDate(ADate, Year, Month, Day);
  AODBCDateStruct.year := Year;
  AODBCDateStruct.month := Month;
  AODBCDateStruct.day := Day;
end;

procedure ODBCTimeFromDateTime(const ATime: TDateTime; var AODBCTimeStruct: SQL_TIME_STRUCT);
var Hour, Minute, Second, MilliSec: Word;
begin
  DecodeTime(ATime, Hour, Minute, Second, MilliSec);
  AODBCTimeStruct.hour := Hour;
  AODBCTimeStruct.minute := Minute;
  AODBCTimeStruct.second := Second;
end;

function CurrencyFromODBCNumeric(const AODBCNumericStruct: SQL_NUMERIC_STRUCT): Currency;
begin
  Assert(False, 'Not Implemented: CurrencyFromODBCNumeric');
  Result := 0;
end;

procedure ODBCNumericFromCurrecy(const ACurrVal: Currency; var AODBCNumericStruct: SQL_NUMERIC_STRUCT);
begin
end;

function ODBCIsNullDataLength(const AValue: SQLINTEGER): Boolean;
begin
  Result := AValue = SQL_NULL_DATA;
end;

function ODBCCharSize(DataType: SQLSMALLINT): LongInt;
begin
  case DataType of
   SQL_C_CHAR: Result := SizeOf(TGMChar);
   SQL_C_WCHAR: Result := SizeOf(WideChar);
   else Result := 0;
  end;
end;

function ODBCRowStatusAsText(const ARowStatus: LongInt): TGMString;
begin
  case ARowStatus of
   SQL_ROW_SUCCESS: Result := RStrSuccess;
   SQL_ROW_DELETED: Result := RStrDeletedRow;
   SQL_ROW_UPDATED: Result := RStrUpdatedRow;
   SQL_ROW_NOROW:   Result := RStrInvalidRow;
   SQL_ROW_ADDED:   Result := RStrNewRow;
   SQL_ROW_ERROR:   Result := RStrError;
   SQL_ROW_SUCCESS_WITH_INFO: Result := RStrSuccessWithInfo;
   else Result := RStrUnknownRowStatus;
  end;
end;

function OdbcErrorDesc(const AHandleType: SQLSMALLINT;
                       const AHandle: SQLHANDLE;
                       const ADiagRecNo: LongInt;
                       const ASQLCode: SQLRETURN): TSQLErrorDesc;
begin
  //FillChar(Result, SizeOf(Result), 0);
  with Result do
   begin
    ReturnCode :=     ASQLCode;
    Code :=           OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_SQLSTATE);
    Origin :=         OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_CLASS_ORIGIN);
    SubClassOrigin := OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_SUBCLASS_ORIGIN);
    Msg :=            OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_MESSAGE_TEXT);
    Connection :=     OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_CONNECTION_NAME);
    Server :=         OdbcGetDiagString(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_SERVER_NAME);
    NativeCode :=     OdbcGetDiagInt(AHandleType, AHandle, ADiagRecNo, SQL_DIAG_NATIVE);
   end;
end;

function OdbcErrorDescAsString(const AValue: TSQLErrorDesc): TGMString;
const cSep = ', ';
begin
  Result := AValue.Code;
  Result := GMStringJoin(Result, cSep, AValue.Origin);
  Result := GMStringJoin(Result, cSep, GMIntToStr(AValue.NativeCode));
  Result := GMStringJoin(Result, cSep, AValue.Msg);
  Result := GMStringJoin(Result, cSep, AValue.Connection);
  Result := GMStringJoin(Result, cSep, AValue.Server);
//Result := GMStrip(Result, cSep);
end;

function OdbcDataLenAtExec(const ADataLength: LongInt): LongInt; // <- C++ Macro SQL_LEN_DATA_AT_EXEC
begin
  if ADataLength <= 0 then Result := SQL_NULL_DATA else
     Result := SQL_DATA_LEN_AT_EXEC_OFFSET - ADataLength;
end;


{ ---- Field Attributes ---- }

function ODBCFieldName(const Handle: SQLHANDLE;
                       const Position: SQLUSMALLINT;
                       const Obj: TObject = nil;
                       const ACallingName: TGMString = cDfltRoutineName): TGMString;
const cBufSize = 255;
var resultLen: SQLSMALLINT;
begin
  Setlength(Result, cBufSize);
  ODBCCheck(SQLColAttribute(Handle, Position, SQL_DESC_NAME, PGMChar(Result), cBufSize * SizeOf(TGMChar), @resultLen, nil), Obj, ACallingName);
  Setlength(Result, resultLen div SizeOf(TGMChar));
end;

function ODBCTypeName(const AHandle: SQLHANDLE;
                      const APosition: SQLUSMALLINT;
                      const AObj: TObject = nil;
                      const ACallingName: TGMString = cDfltRoutineName): TGMString;
const cBufSize = 255;
var resultLen: SQLSMALLINT;
begin                                   // SQL_DESC_LOCAL_TYPE_NAME
  Setlength(Result, cBufSize);
  ODBCCheck(SQLColAttribute(AHandle, APosition, SQL_DESC_TYPE_NAME, PGMChar(Result), cBufSize * SizeOf(TGMChar), @resultLen, nil), AObj, ACallingName);
  Setlength(Result, resultLen div SizeOf(TGMChar));
end;

function ODBCFieldOctetLength(const AHandle: SQLHANDLE;
                              const APosition: SQLUSMALLINT;
                              const AObj: TObject = nil;
                              const ACallingName: TGMString = cDfltRoutineName): SQLLEN;
//var SQLSigned: SQLUINTEGER;
begin                                   //  SQL_DESC_LENGTH   SQL_DESC_OCTET_LENGTH
  ODBCCheck(SQLColAttribute(AHandle, APosition, SQL_DESC_LENGTH, nil, 0, nil, @Result), AObj, ACallingName, SQL_HANDLE_STMT, AHandle);
end;

function ODBCIsSignedField(const Handle: SQLHANDLE;
                           const Position: SQLUSMALLINT;
                           const Obj: TObject = nil;
                           const ACallingName: TGMString = cDfltRoutineName): Boolean;
var sqlSigned: SQLLEN;
begin
  ODBCCheck(SQLColAttribute(Handle, Position, SQL_COLUMN_UNSIGNED, nil, 0, nil, @sqlSigned), Obj, ACallingName, SQL_HANDLE_STMT, Handle);
  case sqlSigned of
   SQL_TRUE:  Result := False;
   SQL_FALSE: Result := True;
   else raise EGMException.ObjError(MsgUnknownPropVal('Signed', sqlSigned), Obj, ACallingName);
  end;
end;

function ODBCFieldDataType(const Handle: SQLHANDLE;
                           const Position: SQLUSMALLINT;
                           const Obj: TObject = nil;
                           const ACallingName: TGMString = cDfltRoutineName): SQLLEN;
begin
  // Some drivers report wrong Bookmark data type.
  // We conform to ODBC 3.0 that bokmarks are always variable length binary data.
  if Position = cOdbcBookmarkColPos then
   Result := SQL_C_VARBOOKMARK
  else
   // SQL_DESC_CONCISE_TYPE works against 2.x Drivers too - SQL_DESC_TYPE only with 3.x
   ODBCCheck(SQLColAttribute(Handle, Position, SQL_DESC_CONCISE_TYPE, nil, 0, nil, @Result), Obj, ACallingName, SQL_HANDLE_STMT, Handle);
end;

function ODBCFieldNullValuesAllowed(const Handle: SQLHANDLE;
                                    const Position: SQLUSMALLINT;
                                    const Obj: TObject = nil;
                                    const ACallingName: TGMString = cDfltRoutineName): TGMAllowNullValues;
var nullsAllowed: SQLLEN;
begin
  ODBCCheck(SQLColAttribute(Handle, Position, SQL_DESC_NULLABLE, nil, 0, nil, @nullsAllowed), Obj, ACallingName);
  case nullsAllowed of
   SQL_NO_NULLS:         Result := nvNullValuesNotAllowed;
   SQL_NULLABLE:         Result := nvNullValuesAllowed;
   SQL_NULLABLE_UNKNOWN: Result := nvNullableUnknown;
   else raise EGMException.ObjError(MsgUnknownPropVal('NullValuesAllowed', nullsAllowed), Obj, ACallingName);
  end;
end;

function ODBCFieldUpdatable(const Handle: SQLHANDLE;
                            const Position: SQLUSMALLINT;
                            const Obj: TObject = nil;
                            const ACallingName: TGMString = cDfltRoutineName): Boolean;
var updt: SQLLEN;
begin
  ODBCCheck(SQLColAttribute(Handle, Position, SQL_COLUMN_UPDATABLE, nil, 0, nil, @updt), Obj, ACallingName);
  case updt of
   SQL_ATTR_READONLY: Result := False;
   SQL_ATTR_WRITE, SQL_ATTR_READWRITE_UNKNOWN: Result := True;
   else raise EGMException.ObjError(MsgUnknownPropVal('Updatable', updt), Obj, ACallingName);
  end;
end;

function ODBCFieldIsAutoIncrementing(const Handle: SQLHANDLE;
                                     const Position: SQLUSMALLINT;
                                     const Obj: TObject = nil;
                                     const ACallingName: TGMString = cDfltRoutineName): Boolean;
var autoInc: SQLLEN;
begin
  ODBCCheck(SQLColAttribute(Handle, Position, SQL_COLUMN_AUTO_INCREMENT, nil, 0, nil, @autoInc), Obj, ACallingName);
  case autoInc of
   SQL_TRUE:  Result := True;
   SQL_FALSE: Result := False;
   else raise EGMException.ObjError(MsgUnknownPropVal('AutoIncrementing', autoInc), Obj, ACallingName);
  end;
end;


{ ---------------------- }
{ ---- EGMOdbcError ---- }
{ ---------------------- }

constructor EGMOdbcError.CreateODBCError(const AReturnCode: SQLRETURN;
                                         const AObj: TObject;
                                         const ARoutineName: TGMString;
//                                       const ASQLStmtText: TGMString;
                                         const AHandleType: SQLSMALLINT;
                                         const AHandle: SQLHANDLE;
                                         const ASeverityLevel: TGMSeverityLevel);
const CHelpCtx = 0; // cSqlTxtMaxLen = 100000;
var getHandleType: IGMGetHandleType; getHandle: IGMGetHandle; // sqlTxt: TGMString;
begin
  FReturnCode := AReturnCode;

  if AHandleType <> cInvalidHandleType then FHandleType := AHandleType
  else
   //if AObj is TGMOdbcComponent then FHandleType := TGMOdbcComponent(AObj).AHandleType
   if (AObj <> nil) and AObj.GetInterface(IGMGetHandleType, getHandleType) then FHandleType := getHandleType.getHandleType
   else FHandleType := SQL_HANDLE_ENV;

  if AHandle <> cOdbcInvalidHandle then FHandle := AHandle
  else
   //if AObj is TGMOdbcComponent then FHandle := TGMOdbcComponent(AObj).AHandle
   if (AObj <> nil) and AObj.GetInterface(IGMGetHandle, getHandle) then FHandle := getHandle.Handle
   else FHandle := SQL_NULL_HANDLE;

//if Length(ASQLStmtText) <= cSqlTxtMaxLen then sqlTxt := ASQLStmtText else sqlTxt := Copy(ASQLStmtText, 1, cSqlTxtMaxLen) + cStr_More;

  ReadODBCErrors;
  SetupInformation(ODBCErrMsgAsString, GMGetObjName(AObj), GMObjClassName(AObj), ARoutineName, ASeverityLevel, CHelpCtx);
//SetupInformation(GMStringJoin(ODBCErrMsgAsString, c2NewLine, sqlTxt), GMGetObjName(AObj), GMObjClassName(AObj), ARoutineName, ASeverityLevel, CHelpCtx);
  inherited CreateHelp(GMBuildExceptionMsg(Self), CHelpCtx);
end;

constructor EGMOdbcError.ObjError(const AMsg: TGMString;
                                  const AObj: TObject;
                                  const ARoutineName: TGMString;
                                  const ASeverityLevel: TGMSeverityLevel;
                                  const AHelpCtx: LongInt);
begin
  FReturnCode := SQL_ERROR;

  SetLength(FErrorDescs, 1);
  with FErrorDescs[High(FErrorDescs)] do
   begin
    ReturnCode := FReturnCode; Code := cOdbcErrGeneral; Msg := AMsg;
    Origin := GMStrip(GMFormat('%s.%s', [GMObjClassName(AObj), ARoutineName]), cWhiteSpace + '.');
   end;

  inherited ObjError(ODBCErrMsgAsString, AObj, ARoutineName, ASeverityLevel, AHelpCtx);
end;

constructor EGMOdbcError.IntfError(const AMsg: TGMString = cDfltExceptionMsg;
                                   const AIntf: IUnknown = nil;
                                   const ARoutineName: TGMString = cDfltRoutineName;
                                   const ASeverityLevel: TGMSeverityLevel = svError;
                                   const AHelpCtx: LongInt= cDfltHelpCtx);
begin
  FReturnCode := SQL_ERROR;

  SetLength(FErrorDescs, 1);
  with FErrorDescs[High(FErrorDescs)] do
   begin
    ReturnCode := FReturnCode; Code := cOdbcErrGeneral; Msg := AMsg;
    Origin := GMStrip(GMFormat('%s.%s', [RStrInterface, ARoutineName]), cWhiteSpace + '.');
   end;

  inherited IntfError(ODBCErrMsgAsString, AIntf, ARoutineName, ASeverityLevel, AHelpCtx);
end;

destructor EGMOdbcError.Destroy;
begin
  ClearErrorList;
  inherited Destroy;
end;

function EGMOdbcError.GetHRCode: HResult; stdcall;
begin
  Result := HRESULT($80004005); // E_FAIL;
end;

function EGMOdbcError.HasErrorDesc(const AOdbcCode: TGMString): Boolean;
var i: Integer;
begin
  for i:=Low(FErrorDescs) to High(FErrorDescs) do
    if GMSameText(FErrorDescs[i].Code, AOdbcCode) then Exit(True);

  Result := False;
end;

procedure EGMOdbcError.ClearErrorList;
begin
  SetLength(FErrorDescs, 0);
end;

procedure EGMOdbcError.ReadODBCErrors;
var i: LongInt;
begin
  ClearErrorList;
  i:=1;
  while ODBCISValidDiagRecNo(FHandleType, FHandle, i) do
   begin
    SetLength(FErrorDescs, Length(FErrorDescs) + 1);
    FErrorDescs[High(FErrorDescs)] := OdbcErrorDesc(FHandleType, FHandle, i, FReturnCode);
    Inc(i);
   end;
end;

function EGMOdbcError.ODBCErrMsgAsString: TGMString;
var i: LongInt; errRecStr: TGMString;
begin
  Result := RStrReturnCode + ': ' + ODBCReturnCodeAsString(FReturnCode) + ' (' + GMIntToStr(FReturnCode) + ')';
  for i:=Low(FErrorDescs) to High(FErrorDescs) do
     errRecStr := GMStringJoin(errRecStr, cNewLine, OdbcErrorDescAsString(FErrorDescs[i]));

  Result := GMStringJoin(Result, c2NewLine, errRecStr);
end;

end.