View Issue Details

IDProjectCategoryView StatusLast Update
0022095FPCDatabasepublic2019-08-17 12:52
ReporterLudo BrandsAssigned ToLacaK 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionunable to reproduce 
Product Version2.7.1Product Build 
Target VersionFixed in Version 
Summary0022095: [Patch] odbc unicode support added
DescriptionAdded unicode api header translations and stubs to map sql functions conditionally to unicode or ansi versions. The stubs do also the char/byte length conversions and widestring/string conversions.
Added some missing constants and functions.

Unicode api support is needed for windows since the MS driver manager will only report string fields as SQL_WVARCHAR when using the unicode API, independent of the database definition of the field.
Tagsodbc, unicode, unicodestring, widestring
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files
  • odbc.inc.diff (63,006 bytes)
    Index: src/odbcsql.inc
    ===================================================================
    --- src/odbcsql.inc	(revision 21326)
    +++ src/odbcsql.inc	(working copy)
    @@ -1,3 +1,10 @@
    +{
    +    This file is part of the Freepascal Free Component Library (FCL)
    +
    +    Unicode support added by Ludo Brands 2012.
    +}
    +
    +
     {$ifdef fpc}
     {$mode objfpc}
     {$macro on}
    @@ -78,6 +85,14 @@
       SQLDOUBLE    = cdouble;
       SQLFLOAT     = cdouble;
       SQLHWND      = pointer;
    +  {$IFDEF CPU64}
    +  SQLLEN=int64;
    +  SQLULEN =QWord;
    +  {$ELSE}
    +  SQLLEN=SQLINTEGER;
    +  SQLULEN =SQLUINTEGER;
    +  {$ENDIF}
    +
       PSQLCHAR      = PChar;
       PSQLINTEGER   = ^SQLINTEGER;
       PSQLUINTEGER  = ^SQLUINTEGER;
    @@ -826,6 +841,208 @@
       SQL_USER_NAME                       = 47;
       SQL_TXN_ISOLATION_OPTION            = 72;
       SQL_TRANSACTION_ISOLATION_OPTION    = SQL_TXN_ISOLATION_OPTION;
    +  SQL_MAX_DRIVER_CONNECTIONS=0;
    +  SQL_MAXIMUM_DRIVER_CONNECTIONS=SQL_MAX_DRIVER_CONNECTIONS;
    +  SQL_MAX_CONCURRENT_ACTIVITIES=1;
    +  SQL_MAXIMUM_CONCURRENT_ACTIVITIES=SQL_MAX_CONCURRENT_ACTIVITIES;
    +  SQL_DATA_SOURCE_NAME=2;
    +  SQL_FETCH_DIRECTION=8;
    +  SQL_SERVER_NAME=13;
    +  SQL_SEARCH_PATTERN_ESCAPE=14;
    +  SQL_DBMS_NAME=17;
    +  SQL_DBMS_VER=18;
    +  SQL_ACCESSIBLE_TABLES=19;
    +  SQL_ACCESSIBLE_PROCEDURES=20;
    +  SQL_CURSOR_COMMIT_BEHAVIOR=23;
    +  SQL_DATA_SOURCE_READ_ONLY=25;
    +  SQL_DEFAULT_TXN_ISOLATION=26;
    +  SQL_IDENTIFIER_CASE=28;
    +  SQL_IDENTIFIER_QUOTE_CHAR=29;
    +  SQL_MAX_COLUMN_NAME_LEN=30;
    +  SQL_MAXIMUM_COLUMN_NAME_LENGTH=SQL_MAX_COLUMN_NAME_LEN;
    +  SQL_MAX_CURSOR_NAME_LEN=31;
    +  SQL_MAXIMUM_CURSOR_NAME_LENGTH=SQL_MAX_CURSOR_NAME_LEN;
    +  SQL_MAX_SCHEMA_NAME_LEN=32;
    +  SQL_MAXIMUM_SCHEMA_NAME_LENGTH=SQL_MAX_SCHEMA_NAME_LEN;
    +  SQL_MAX_CATALOG_NAME_LEN=34;
    +  SQL_MAXIMUM_CATALOG_NAME_LENGTH=SQL_MAX_CATALOG_NAME_LEN;
    +  SQL_MAX_TABLE_NAME_LEN=35;
    +  SQL_INTEGRITY=73;
    +  SQL_GETDATA_EXTENSIONS=81;
    +  SQL_NULL_COLLATION=85;
    +  SQL_ALTER_TABLE=86;
    +  SQL_ORDER_BY_COLUMNS_IN_SELECT=90;
    +  SQL_SPECIAL_CHARACTERS=94;
    +  SQL_MAX_COLUMNS_IN_GROUP_BY=97;
    +  SQL_MAXIMUM_COLUMNS_IN_GROUP_BY=SQL_MAX_COLUMNS_IN_GROUP_BY;
    +  SQL_MAX_COLUMNS_IN_INDEX=98;
    +  SQL_MAXIMUM_COLUMNS_IN_INDEX=SQL_MAX_COLUMNS_IN_INDEX;
    +  SQL_MAX_COLUMNS_IN_ORDER_BY=99;
    +  SQL_MAXIMUM_COLUMNS_IN_ORDER_BY=SQL_MAX_COLUMNS_IN_ORDER_BY;
    +  SQL_MAX_COLUMNS_IN_SELECT=100;
    +  SQL_MAXIMUM_COLUMNS_IN_SELECT=SQL_MAX_COLUMNS_IN_SELECT;
    +  SQL_MAX_COLUMNS_IN_TABLE=101;
    +  SQL_MAX_INDEX_SIZE=102;
    +  SQL_MAXIMUM_INDEX_SIZE=SQL_MAX_INDEX_SIZE;
    +  SQL_MAX_ROW_SIZE=104;
    +  SQL_MAXIMUM_ROW_SIZE=SQL_MAX_ROW_SIZE;
    +  SQL_MAX_STATEMENT_LEN=105;
    +  SQL_MAXIMUM_STATEMENT_LENGTH=SQL_MAX_STATEMENT_LEN;
    +  SQL_MAX_TABLES_IN_SELECT=106;
    +  SQL_MAXIMUM_TABLES_IN_SELECT=SQL_MAX_TABLES_IN_SELECT;
    +  SQL_MAX_USER_NAME_LEN=107;
    +  SQL_MAXIMUM_USER_NAME_LENGTH=SQL_MAX_USER_NAME_LEN;
    +
    +  SQL_OJ_CAPABILITIES=115;
    +  SQL_OUTER_JOIN_CAPABILITIES=SQL_OJ_CAPABILITIES;
    +
    +  SQL_XOPEN_CLI_YEAR=10000;
    +  SQL_CURSOR_SENSITIVITY=10001;
    +  SQL_DESCRIBE_PARAMETER=10002;
    +  SQL_CATALOG_NAME=10003;
    +  SQL_COLLATION_SEQ=10004;
    +  SQL_MAX_IDENTIFIER_LEN=10005;
    +  SQL_MAXIMUM_IDENTIFIER_LENGTH=SQL_MAX_IDENTIFIER_LEN;
    +
    +  SQL_INFO_FIRST=   0;
    +  SQL_ACTIVE_CONNECTIONS=   0 ;	//* MAX_DRIVER_CONNECTIONS */;
    +  SQL_ACTIVE_STATEMENTS=1;	//* MAX_CONCURRENT_ACTIVITIES */;
    +  SQL_DRIVER_HDBC=  3;
    +  SQL_DRIVER_HENV=  4;
    +  SQL_DRIVER_HSTMT= 5;
    +  SQL_DRIVER_NAME=  6;
    +  SQL_DRIVER_VER=   7;
    +  SQL_ODBC_API_CONFORMANCE= 9;
    +  SQL_ODBC_VER=10;
    +  SQL_ROW_UPDATES= 11;
    +  SQL_ODBC_SAG_CLI_CONFORMANCE=12;
    +  SQL_ODBC_SQL_CONFORMANCE=15;
    +  SQL_PROCEDURES=  21;
    +  SQL_CONCAT_NULL_BEHAVIOR=22;
    +  SQL_CURSOR_ROLLBACK_BEHAVIOR=24;
    +  SQL_EXPRESSIONS_IN_ORDERBY=  27;
    +  SQL_MAX_OWNER_NAME_LEN=  32;	//* MAX_SCHEMA_NAME_LEN */;
    +  SQL_MAX_PROCEDURE_NAME_LEN=  33;
    +  SQL_MAX_QUALIFIER_NAME_LEN=  34;	//* MAX_CATALOG_NAME_LEN */;
    +  SQL_MULT_RESULT_SETS=36;
    +  SQL_MULTIPLE_ACTIVE_TXN= 37;
    +  SQL_OUTER_JOINS= 38;
    +  SQL_OWNER_TERM=  39;
    +  SQL_PROCEDURE_TERM=  40;
    +  SQL_QUALIFIER_NAME_SEPARATOR=41;
    +  SQL_QUALIFIER_TERM=  42;
    +  SQL_TABLE_TERM=  45;
    +  SQL_CONVERT_FUNCTIONS=   48;
    +  SQL_NUMERIC_FUNCTIONS=   49;
    +  SQL_STRING_FUNCTIONS=50;
    +  SQL_SYSTEM_FUNCTIONS=51;
    +  SQL_TIMEDATE_FUNCTIONS=  52;
    +  SQL_CONVERT_BIGINT=  53;
    +  SQL_CONVERT_BINARY=  54;
    +  SQL_CONVERT_BIT= 55;
    +  SQL_CONVERT_CHAR=56;
    +  SQL_CONVERT_DATE=57;
    +  SQL_CONVERT_DECIMAL= 58;
    +  SQL_CONVERT_DOUBLE=  59;
    +  SQL_CONVERT_FLOAT=   60;
    +  SQL_CONVERT_INTEGER= 61;
    +  SQL_CONVERT_LONGVARCHAR= 62;
    +  SQL_CONVERT_NUMERIC= 63;
    +  SQL_CONVERT_REAL=64;
    +  SQL_CONVERT_SMALLINT=65;
    +  SQL_CONVERT_TIME=66;
    +  SQL_CONVERT_TIMESTAMP=   67;
    +  SQL_CONVERT_TINYINT= 68;
    +  SQL_CONVERT_VARBINARY=   69;
    +  SQL_CONVERT_VARCHAR= 70;
    +  SQL_CONVERT_LONGVARBINARY=   71;
    +  SQL_ODBC_SQL_OPT_IEF=73;		//* SQL_INTEGRITY */;
    +  SQL_CORRELATION_NAME=74;
    +  SQL_NON_NULLABLE_COLUMNS=75;
    +  SQL_DRIVER_HLIB= 76;
    +  SQL_DRIVER_ODBC_VER= 77;
    +  SQL_LOCK_TYPES=  78;
    +  SQL_POS_OPERATIONS=  79;
    +  SQL_POSITIONED_STATEMENTS=   80;
    +  SQL_FILE_USAGE=  84;
    +  SQL_COLUMN_ALIAS=87;
    +  SQL_GROUP_BY=88;
    +  SQL_KEYWORDS=89;
    +  SQL_OWNER_USAGE= 91;
    +  SQL_QUALIFIER_USAGE= 92;
    +  SQL_QUOTED_IDENTIFIER_CASE=  93;
    +  SQL_SUBQUERIES=  95;
    +  SQL_UNION=   96;
    +  SQL_MAX_ROW_SIZE_INCLUDES_LONG=  103;
    +  SQL_MAX_CHAR_LITERAL_LEN=108;
    +  SQL_TIMEDATE_ADD_INTERVALS=  109;
    +  SQL_TIMEDATE_DIFF_INTERVALS= 110;
    +  SQL_NEED_LONG_DATA_LEN=  111;
    +  SQL_MAX_BINARY_LITERAL_LEN=  112;
    +  SQL_LIKE_ESCAPE_CLAUSE=  113;
    +  SQL_QUALIFIER_LOCATION=  114;
    +  SQL_ACTIVE_ENVIRONMENTS=		116;
    + 	SQL_ALTER_DOMAIN=117;
    + 	SQL_SQL_CONFORMANCE=118;
    +  SQL_DATETIME_LITERALS=		119;
    + 	SQL_ASYNC_MODE=	10021;	//* new X/Open spec */;
    +  SQL_BATCH_ROW_COUNT=120;
    +  SQL_BATCH_SUPPORT=121;
    +  SQL_CATALOG_LOCATION=		SQL_QUALIFIER_LOCATION;
    +  SQL_CATALOG_NAME_SEPARATOR=	SQL_QUALIFIER_NAME_SEPARATOR;
    +  SQL_CATALOG_TERM=SQL_QUALIFIER_TERM;
    +  SQL_CATALOG_USAGE=SQL_QUALIFIER_USAGE;
    + 	SQL_CONVERT_WCHAR=122;
    +  SQL_CONVERT_INTERVAL_DAY_TIME=123;
    +  SQL_CONVERT_INTERVAL_YEAR_MONTH=124;
    + 	SQL_CONVERT_WLONGVARCHAR=	125;
    + 	SQL_CONVERT_WVARCHAR=		126;
    + 	SQL_CREATE_ASSERTION=		127;
    + 	SQL_CREATE_CHARACTER_SET=	128;
    + 	SQL_CREATE_COLLATION=		129;
    + 	SQL_CREATE_DOMAIN=130;
    + 	SQL_CREATE_SCHEMA=131;
    + 	SQL_CREATE_TABLE=132;
    + 	SQL_CREATE_TRANSLATION=		133;
    + 	SQL_CREATE_VIEW=	134;
    +  SQL_DRIVER_HDESC=135;
    + 	SQL_DROP_ASSERTION=136;
    + 	SQL_DROP_CHARACTER_SET=		137;
    + 	SQL_DROP_COLLATION=138;
    + 	SQL_DROP_DOMAIN=	139;
    + 	SQL_DROP_SCHEMA=	140;
    + 	SQL_DROP_TABLE=	141;
    + 	SQL_DROP_TRANSLATION=		142;
    + 	SQL_DROP_VIEW=	143;
    +  SQL_MAX_ASYNC_CONCURRENT_STATEMENTS=10022;	//* new X/Open spec */;
    +  SQL_ODBC_INTERFACE_CONFORMANCE=152;
    +  SQL_PARAM_ARRAY_ROW_COUNTS     =153;
    +  SQL_PARAM_ARRAY_SELECTS     =154;
    +  SQL_SCHEMA_TERM=	SQL_OWNER_TERM;
    +  SQL_SCHEMA_USAGE=SQL_OWNER_USAGE;
    +  SQL_SQL92_DATETIME_FUNCTIONS=155;
    +  SQL_SQL92_FOREIGN_KEY_DELETE_RULE =		156;
    +  SQL_SQL92_FOREIGN_KEY_UPDATE_RULE =		157;
    +  SQL_SQL92_GRANT=	158;
    +  SQL_SQL92_NUMERIC_VALUE_FUNCTIONS =		159;
    +  SQL_SQL92_PREDICATES=		160;
    +  SQL_SQL92_RELATIONAL_JOIN_OPERATORS=		161;
    +  SQL_SQL92_REVOKE=162;
    +  SQL_SQL92_ROW_VALUE_CONSTRUCTOR=163;
    +  SQL_SQL92_STRING_FUNCTIONS=	164;
    +  SQL_SQL92_VALUE_EXPRESSIONS=	165;
    +  SQL_STANDARD_CLI_CONFORMANCE=166;
    +  SQL_AGGREGATE_FUNCTIONS=		169;
    +  SQL_DDL_INDEX=	170;
    +  SQL_DM_VER=		171;
    +  SQL_INSERT_STATEMENT=		172;
    +  SQL_CONVERT_GUID=173;
    +  SQL_UNION_STATEMENT=SQL_UNION;
    +  SQL_DTC_TRANSITION_COST=		1750;
    +
    +  { Deprecated defines from prior versions of ODBC }
    +  SQL_DATABASE_NAME=16;
    +
     {
     #define SQL_INTEGRITY                       73
     #define SQL_GETDATA_EXTENSIONS              81
    @@ -852,20 +1069,7 @@
     #define SQL_MAXIMUM_TABLES_IN_SELECT       SQL_MAX_TABLES_IN_SELECT
     #define SQL_MAX_USER_NAME_LEN              107
     #define SQL_MAXIMUM_USER_NAME_LENGTH       SQL_MAX_USER_NAME_LEN}
    -{$ifdef ODBCVER3}
    -  SQL_OJ_CAPABILITIES         = 115;
    -  SQL_OUTER_JOIN_CAPABILITIES = SQL_OJ_CAPABILITIES;
    -{$endif} { ODBCVER >= 0x0300 }
     
    -{$ifdef ODBCVER3}
    -  SQL_XOPEN_CLI_YEAR            = 10000;
    -  SQL_CURSOR_SENSITIVITY        = 10001;
    -  SQL_DESCRIBE_PARAMETER        = 10002;
    -  SQL_CATALOG_NAME              = 10003;
    -  SQL_COLLATION_SEQ             = 10004;
    -  SQL_MAX_IDENTIFIER_LEN        = 10005;
    -  SQL_MAXIMUM_IDENTIFIER_LENGTH = SQL_MAX_IDENTIFIER_LEN;
    -{$endif} { ODBCVER >= 0x0300 }
     
     {/* SQL_ALTER_TABLE bitmasks */
     #if (ODBCVER >= 0x0200)
    @@ -1134,7 +1338,7 @@
     
     type   tSQLGetInfo=function (ConnectionHandle:SQLHDBC;
                InfoType:SQLUSMALLINT;InfoValue:SQLPOINTER;
    -           BufferLength:SQLSMALLINT;StringLength:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +           BufferLength:SQLSMALLINT;var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
     
     type   TSQLBulkOperations=function (StatementHandle: SQLHSTMT;
                Operation:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    @@ -1234,53 +1438,230 @@
                TableName:PSQLCHAR; NameLength3:SQLSMALLINT;
                Unique:SQLUSMALLINT;
                Reserved:SQLUSMALLINT): SQLRETURN; {$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDescRec = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:PChar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLForeignKeys = function (StatementHandle:SQLHSTMT; PKCatalogName:PChar; NameLength1:SQLSMALLINT; PKSchemaName:PChar; NameLength2:SQLSMALLINT; PKTableName:PChar; NameLength3:SQLSMALLINT;
    +                               FKCatalogName:PChar; NameLength4:SQLSMALLINT; FKSchemaName:PChar; NameLength5:SQLSMALLINT; FKTableName:PChar; NameLength6:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetConnectAttr = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDescField = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLNativeSql = function (StatementHandle:SQLHSTMT;InStatementText:PChar;TextLength1:SQLINTEGER;
    +                                OutStatementText:PChar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
     
    +
    +type   TSQLColAttributeW = function (StatementHandle:SQLHSTMT;
    +                                                ColumnNumber:SQLUSMALLINT;  FieldIdentifier:SQLUSMALLINT;
    +                                                CharacterAttribute:PWideChar;  BufferLength:SQLSMALLINT;
    +                                                StringLength:PSQLSMALLINT;  NumericAttribute:SQLPOINTER
    +                                                ):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLColumnsW = function (StatementHandle:SQLHSTMT;CatalogName:PWideChar;  NameLength1:SQLSMALLINT;
    +                    SchemaName:PWideChar;  NameLength2:SQLSMALLINT;TableName:PWideChar;  NameLength3:SQLSMALLINT;
    +                    ColumnName:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLConnectW = function (ConnectionHandle:SQLHDBC ;
    +                                          ServerName:PWideChar;  NameLength1:SQLSMALLINT;
    +                                          UserName:PWideChar;  NameLength2:SQLSMALLINT;
    +                                          Authentication:PWideChar;  NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLDataSourcesW = function (EnvironmentHandle:SQLHENV;
    +           Direction:SQLUSMALLINT;ServerName:PWideChar;
    +           BufferLength1:SQLSMALLINT;NameLength1:PSQLSMALLINT;
    +           Description:PWideChar;BufferLength2:SQLSMALLINT;
    +           NameLength2:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLDescribeColW = function (StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT;
    +                 ColumnName:PWideChar; BufferLength:SQLSMALLINT; var NameLength:SQLSMALLINT;
    +                 var DataType:SQLSMALLINT; var ColumnSize:SQLULEN; var DecimalDigits:SQLSMALLINT;
    +                 var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLDriverConnectW = function (ConnectionHandle:SQLHDBC;hWnd:SQLHWND;szConnStrIn:PWideChar;
    +               nConnStrIn:SQLSMALLINT;szConnStrOut:PWideChar;cbConnStrOutMax:SQLSMALLINT;
    +               var pnConnStrOut:SQLSMALLINT;nDriverCompletion:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLDriversW=function (EnvironmentHandle:SQLHENV;
    +           Direction:SQLUSMALLINT;DriverDescription:PWideChar;
    +           BufferLength1:SQLSMALLINT;DescriptionLength1:PSQLSMALLINT;
    +           DriverAttributes:PWideChar;BufferLength2:SQLSMALLINT;
    +           AttributesLength2:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLExecDirectW = function (StatementHandle:SQLHSTMT; StatementText:PWideChar;  TextLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLForeignKeysW = function (StatementHandle:SQLHSTMT; PKCatalogName:PWideChar; NameLength1:SQLSMALLINT; PKSchemaName:PWideChar; NameLength2:SQLSMALLINT; PKTableName:PWideChar; NameLength3:SQLSMALLINT;
    +                               FKCatalogName:PWideChar; NameLength4:SQLSMALLINT; FKSchemaName:PWideChar; NameLength5:SQLSMALLINT; FKTableName:PWideChar; NameLength6:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetConnectAttrW = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetCursorNameW = function (StatementHandle:SQLHSTMT; CursorName:PWideChar; BufferLength:SQLSMALLINT;  NameLength:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDescFieldW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDescRecW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:PWideChar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDiagFieldW = function (HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; DiagIdentifier:SQLSMALLINT; DiagInfo:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetDiagRecW = function (HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; Sqlstate:PWideChar; var NativeError:SQLINTEGER;  MessageText:PWideChar; BufferLength:SQLSMALLINT;  var TextLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetInfoW = function (ConnectionHandle:SQLHDBC ; InfoType:SQLUSMALLINT; InfoValue:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLGetStmtAttrW = function (StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER;  StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLNativeSqlW = function (StatementHandle:SQLHSTMT;InStatementText:PWideChar;TextLength1:SQLINTEGER;
    +                                OutStatementText:PWideChar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLPrepareW = function (StatementHandle:SQLHSTMT; StatementText:PWideChar;  TextLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLPrimaryKeysW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
    +              SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLProcedureColumnsW = function (StatementHandle:SQLHSTMT;CatalogName:PWideChar;  NameLength1:SQLSMALLINT;
    +                    SchemaName:PWideChar;  NameLength2:SQLSMALLINT;ProcName:PWideChar;  NameLength3:SQLSMALLINT;
    +                    ColumnName:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLProceduresW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
    +              SchemaName:PWideChar; NameLength2:SQLSMALLINT; ProcName:PWideChar; NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLSetConnectAttrW = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLSetCursorNameW = function (StatementHandle:SQLHSTMT; CursorName:PWideChar;  NameLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLSetDescFieldW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER;  BufferLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLSetStmtAttrW = function (StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLSpecialColumnsW = function (StatementHandle:SQLHSTMT; IdentifierType:SQLUSMALLINT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
    +              SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT;
    +              Scope:SQLUSMALLINT;  Nullable:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLStatisticsW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
    +             SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT;
    +             Unique:SQLUSMALLINT;  Reserved:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +type   TSQLTablesW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT; SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT; TableType:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
    +
    +
    +
    +var    SQLColAttributeW:TSQLColAttributeW;
    +var    SQLColumnsW:TSQLColumnsW;
    +var    SQLConnectW:TSQLConnectW;
    +var    SQLDataSourcesW:TSQLDataSourcesW;
    +var    SQLDescribeColW:TSQLDescribeColW;
    +var    SQLDriverConnectW:TSQLDriverConnectW;
    +var    SQLDriversW:TSQLDriversW;
    +var    SQLExecDirectW:TSQLExecDirectW;
    +var    SQLForeignKeysW:TSQLForeignKeysW;
    +var    SQLGetConnectAttrW:TSQLGetConnectAttrW;
    +var    SQLGetCursorNameW:TSQLGetCursorNameW;
    +var    SQLGetDescFieldW:TSQLGetDescFieldW;
    +var    SQLGetDescRecW:TSQLGetDescRecW;
    +var    SQLGetDiagFieldW:TSQLGetDiagFieldW;
    +var    SQLGetDiagRecW:TSQLGetDiagRecW;
    +var    SQLGetInfoW:TSQLGetInfoW;
    +var    SQLGetStmtAttrW:TSQLGetStmtAttrW;
    +var    SQLPrepareW:TSQLPrepareW;
    +var    SQLPrimaryKeysW:TSQLPrimaryKeysW;
    +var    SQLProcedureColumnsW : TSQLProcedureColumnsW;
    +var    SQLProceduresW:TSQLProceduresW;
    +var    SQLNativeSqlW:TSQLNativeSqlW;
    +var    SQLSetConnectAttrW:TSQLSetConnectAttrW;
    +var    SQLSetCursorNameW:TSQLSetCursorNameW;
    +var    SQLSetDescFieldW:TSQLSetDescFieldW;
    +var    SQLSetStmtAttrW:TSQLSetStmtAttrW;
    +var    SQLSpecialColumnsW:TSQLSpecialColumnsW;
    +var    SQLStatisticsW: TSQLStatisticsW;
    +var    SQLTablesW:TSQLTablesW;
    +
    +var    SQLColAttributeA:TSQLColAttribute;
    +var    SQLColumnsA:TSQLColumns;
    +var    SQLConnectA:TSQLConnect;
    +var    SQLDataSourcesA:TSQLDataSources;
    +var    SQLDescribeColA:TSQLDescribeCol;
    +var    SQLGetDescRecA:TSQLGetDescRec;
    +var    SQLDriverConnectA:TSQLDriverConnect;
    +var    SQLDriversA:TSQLDrivers;
    +var    SQLExecDirectA:TSQLExecDirect;
    +var    SQLForeignKeysA:TSQLForeignKeys;
    +var    SQLGetConnectAttrA:TSQLGetConnectAttr;
    +var    SQLGetCursorNameA:TSQLGetCursorName;
    +var    SQLGetDescFieldA:TSQLGetDescField;
    +var    SQLGetDiagFieldA:TSQLGetDiagField;
    +var    SQLGetDiagRecA:TSQLGetDiagRec;
    +var    SQLGetInfoA:tSQLGetInfo;
    +var    SQLGetStmtAttrA:TSQLGetStmtAttr;
    +var    SQLPrepareA:TSQLPrepare;
    +var    SQLPrimaryKeysA:TSQLPrimaryKeys;
    +var    SQLProcedureColumnsA : TSQLProcedureColumns;
    +var    SQLProceduresA:TSQLProcedures;
    +var    SQLNativeSqlA:TSQLNativeSql;
    +var    SQLSetConnectAttrA:TSQLSetConnectAttr;
    +var    SQLSetCursorNameA:TSQLSetCursorName;
    +var    SQLSetDescFieldA:TSQLSetDescField;
    +var    SQLSetStmtAttrA:TSQLSetStmtAttr;
    +var    SQLSpecialColumnsA:TSQLSpecialColumns;
    +var    SQLStatisticsA: TSQLStatistics;
    +var    SQLTablesA:TSQLTables;
    +
     var    SQLAllocHandle:tSQLAllocHandle;
    -var    SQLSetEnvAttr:tSQLSetEnvAttr;
    -var    SQLFreeHandle:tSQLFreeHandle;
    -var    SQLGetInfo:tSQLGetInfo;
    -var    SQLProcedures:TSQLProcedures;
    -var    SQLColumns:TSQLColumns;
    -var    SQLSpecialColumns:TSQLSpecialColumns;
    -var    SQLGetDiagRec:TSQLGetDiagRec;
    -var    SQLGetDiagField:TSQLGetDiagField;
    -var    SQLConnect:TSQLConnect;
    +var    SQLBindCol:TSQLBindCol;
    +var    SQLBindParameter:TSQLBindParameter;
    +var    SQLBulkOperations:TSQLBulkOperations;
    +var    SQLCloseCursor:TSQLCloseCursor;
     var    SQLDisconnect:TSQLDisconnect;
    -var    SQLDriverConnect:TSQLDriverConnect;
    -var    SQLExecDirect:TSQLExecDirect;
    -var    SQLPrepare:TSQLPrepare;
    -var    SQLCloseCursor:TSQLCloseCursor;
    +var    SQLEndTran:TSQLEndTran;
     var    SQLExecute:TSQLExecute;
    +var    SQLExtendedFetch:TSQLExtendedFetch;
     var    SQLFetch:TSQLFetch;
    -var    SQLNumResultCols:TSQLNumResultCols;
    -var    SQLDescribeCol:TSQLDescribeCol;
     var    SQLFetchScroll:TSQLFetchScroll;
    -var    SQLExtendedFetch:TSQLExtendedFetch;
    +var    SQLFreeHandle:tSQLFreeHandle;
    +var    SQLFreeStmt:TSQLFreeStmt;
     var    SQLGetData:TSQLGetData;
    -var    SQLSetStmtAttr:TSQLSetStmtAttr;
    -var    SQLGetStmtAttr:TSQLGetStmtAttr;
    -//var    SQLSetDescField:TSQLSetDescField;
    +var    SQLNumResultCols:TSQLNumResultCols;
    +var    SQLPutData:TSQLPutData;
    +var    SQLRowCount:TSQLRowCount;
     var    SQLSetDescRec:TSQLSetDescRec;
    -var    SQLBulkOperations:TSQLBulkOperations;
    -var    SQLPutData:TSQLPutData;
    -var    SQLBindCol:TSQLBindCol;
    +var    SQLSetEnvAttr:tSQLSetEnvAttr;
     var    SQLSetPos:TSQLSetPos;
    -var    SQLDataSources:TSQLDataSources;
    -var    SQLDrivers:TSQLDrivers;
    -var    SQLSetConnectAttr:TSQLSetConnectAttr;
    -var    SQLGetCursorName:TSQLGetCursorName;
    -var    SQLSetCursorName:TSQLSetCursorName;
    -var    SQLRowCount:TSQLRowCount;
    -var    SQLBindParameter:TSQLBindParameter;
    -var    SQLFreeStmt:TSQLFreeStmt;
    -var    SQLColAttribute:TSQLColAttribute;
    -var    SQLEndTran:TSQLEndTran;
    -var    SQLTables:TSQLTables;
    -var    SQLPrimaryKeys:TSQLPrimaryKeys;
    -var    SQLProcedureColumns : TSQLProcedureColumns;
    -var    SQLStatistics: TSQLStatistics;
    +
     var    odbcversion:word;
     
    +//ansi unicode stubs
    +
    +function SQLColAttribute(StatementHandle:SQLHSTMT;
    +                                                ColumnNumber:SQLUSMALLINT;  FieldIdentifier:SQLUSMALLINT;
    +                                                CharacterAttribute:pchar;  BufferLength:SQLSMALLINT;
    +                                                StringLength:PSQLSMALLINT;  NumericAttribute:SQLPOINTER
    +                                                ):SQLRETURN;
    +function SQLColumns(StatementHandle:SQLHSTMT;CatalogName:pchar;  NameLength1:SQLSMALLINT;
    +                    SchemaName:pchar;  NameLength2:SQLSMALLINT;TableName:pchar;  NameLength3:SQLSMALLINT;
    +                    ColumnName:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
    +function SQLConnect(ConnectionHandle:SQLHDBC ;
    +                                          ServerName:pchar;  NameLength1:SQLSMALLINT;
    +                                          UserName:pchar;  NameLength2:SQLSMALLINT;
    +                                          Authentication:pchar;  NameLength3:SQLSMALLINT):SQLRETURN;
    +function SQLDataSources(EnvironmentHandle:SQLHENV;
    +           Direction:SQLUSMALLINT;ServerName:pchar;
    +           BufferLength1:SQLSMALLINT;NameLength1:PSQLSMALLINT;
    +           Description:pchar;BufferLength2:SQLSMALLINT;
    +           NameLength2:PSQLSMALLINT):SQLRETURN;
    +function SQLDescribeCol(StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT;
    +                 ColumnName:pchar; BufferLength:SQLSMALLINT; var NameLength:SQLSMALLINT;
    +                 var DataType:SQLSMALLINT; var ColumnSize:SQLULEN; var DecimalDigits:SQLSMALLINT;
    +                 var Nullable:SQLSMALLINT):SQLRETURN;
    +function SQLDriverConnect(ConnectionHandle:SQLHDBC;hWnd:SQLHWND;szConnStrIn:pchar;
    +               nConnStrIn:SQLSMALLINT;szConnStrOut:pchar;cbConnStrOutMax:SQLSMALLINT;
    +               var pnConnStrOut:SQLSMALLINT;nDriverCompletion:SQLUSMALLINT):SQLRETURN;
    +function SQLDrivers(EnvironmentHandle:SQLHENV;
    +           Direction:SQLUSMALLINT;DriverDescription:pchar;
    +           BufferLength1:SQLSMALLINT;DescriptionLength1:PSQLSMALLINT;
    +           DriverAttributes:pchar;BufferLength2:SQLSMALLINT;
    +           AttributesLength2:PSQLSMALLINT):SQLRETURN;
    +function SQLExecDirect(StatementHandle:SQLHSTMT; StatementText:pchar;  TextLength:SQLINTEGER):SQLRETURN;
    +function SQLForeignKeys(StatementHandle:SQLHSTMT; PKCatalogName:pchar; NameLength1:SQLSMALLINT; PKSchemaName:pchar; NameLength2:SQLSMALLINT; PKTableName:pchar; NameLength3:SQLSMALLINT;
    +                               FKCatalogName:pchar; NameLength4:SQLSMALLINT; FKSchemaName:pchar; NameLength5:SQLSMALLINT; FKTableName:pchar; NameLength6:SQLSMALLINT):SQLRETURN;
    +function SQLGetConnectAttr(ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;
    +function SQLGetCursorName(StatementHandle:SQLHSTMT; CursorName:pchar; BufferLength:SQLSMALLINT;  NameLength:PSQLSMALLINT):SQLRETURN;
    +function SQLGetDescField(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;
    +function SQLGetDescRec(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:pchar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;
    +function SQLGetDiagField(HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; DiagIdentifier:SQLSMALLINT; DiagInfo:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;
    +function SQLGetDiagRec(HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; Sqlstate:pchar; var NativeError:SQLINTEGER;  MessageText:pchar; BufferLength:SQLSMALLINT;  var TextLength:SQLSMALLINT):SQLRETURN;
    +function SQLGetInfo(ConnectionHandle:SQLHDBC ; InfoType:SQLUSMALLINT; InfoValue:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;
    +function SQLGetStmtAttr(StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER;  StringLength:SQLPOINTER):SQLRETURN;
    +function SQLNativeSql(StatementHandle:SQLHSTMT;InStatementText:pchar;TextLength1:SQLINTEGER;
    +                                OutStatementText:pchar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;
    +function SQLPrepare(StatementHandle:SQLHSTMT; StatementText:pchar;  TextLength:SQLINTEGER):SQLRETURN;
    +function SQLPrimaryKeys(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
    +              SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT):SQLRETURN;
    +function SQLProcedureColumns(StatementHandle:SQLHSTMT;CatalogName:pchar;  NameLength1:SQLSMALLINT;
    +                    SchemaName:pchar;  NameLength2:SQLSMALLINT;ProcName:pchar;  NameLength3:SQLSMALLINT;
    +                    ColumnName:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
    +function SQLProcedures(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
    +              SchemaName:pchar; NameLength2:SQLSMALLINT; ProcName:pchar; NameLength3:SQLSMALLINT):SQLRETURN;
    +function SQLSetConnectAttr(ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;
    +function SQLSetCursorName(StatementHandle:SQLHSTMT; CursorName:PSQLCHAR;  NameLength:SQLSMALLINT):SQLRETURN;
    +function SQLSetDescField(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER;  BufferLength:SQLINTEGER):SQLRETURN;
    +function SQLSetStmtAttr(StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;
    +function SQLSpecialColumns(StatementHandle:SQLHSTMT; IdentifierType:SQLUSMALLINT; CatalogName:pchar; NameLength1:SQLSMALLINT;
    +              SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT;
    +              Scope:SQLUSMALLINT;  Nullable:SQLUSMALLINT):SQLRETURN;
    +function SQLStatistics(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
    +             SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT;
    +             Unique:SQLUSMALLINT;  Reserved:SQLUSMALLINT):SQLRETURN;
    +function SQLTables(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT; SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT; TableType:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
    +
    +
    +
    +
    +
     {$else}
     
       function SQLAllocHandle(
    @@ -1559,6 +1940,7 @@
     {$IFDEF DYNLOADINGODBC}
     
     var RefCount : integer;
    +  IsUnicode:boolean;
     
     Procedure InitialiseODBC(OverrideName : string ='');
     
    @@ -1580,50 +1962,88 @@
           end;
     
     {$ifdef fpc}
    +//Unicode version
    +    pointer(SQLColAttributeW) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttributeW');
    +    pointer(SQLColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumnsW');
    +    pointer(SQLConnectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnectW');
    +    pointer(SQLDataSourcesW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSourcesW');
    +    pointer(SQLDescribeColW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeColW');
    +    pointer(SQLDriverConnectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnectW');
    +    pointer(SQLDriversW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriversW');
    +    pointer(SQLExecDirectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirectW');
    +    //pointer(SQLSetDescFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescFieldW');
    +    pointer(SQLGetConnectAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetConnectAttrW');
    +    pointer(SQLGetCursorNameW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorNameW');
    +    pointer(SQLGetDescFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescFieldW');
    +    pointer(SQLGetDescRecW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescRecW');
    +    pointer(SQLGetDiagFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagFieldW');
    +    pointer(SQLGetDiagRecW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRecW');
    +    pointer(SQLGetInfoW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfoW');
    +    pointer(SQLGetStmtAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttrW');
    +    pointer(SQLPrepareW) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepareW');
    +    pointer(SQLPrimaryKeysW) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeysW');
    +    pointer(SQLProcedureColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumnsW');
    +    pointer(SQLProceduresW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProceduresW');
    +    pointer(SQLProceduresW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProceduresW');
    +    pointer(SQLNativeSqlW) := GetProcedureAddress(ODBCLibraryHandle,'SQLNativeSqlW');
    +    pointer(SQLSetConnectAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttrW');
    +    pointer(SQLSetCursorNameW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorNameW');
    +    pointer(SQLSetStmtAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttrW');
    +    pointer(SQLStatisticsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLStatisticsW');
    +    pointer(SQLSpecialColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumnsW');
    +    pointer(SQLTablesW) := GetProcedureAddress(ODBCLibraryHandle,'SQLTablesW');
    +
    +    IsUnicode:=assigned(SQLDriverConnectW);
    +
    +//Ansi version
    +    pointer(SQLColAttributeA) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttribute');
    +    pointer(SQLColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumns');
    +    pointer(SQLConnectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnect');
    +    pointer(SQLDataSourcesA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSources');
    +    pointer(SQLDescribeColA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeCol');
    +    pointer(SQLDriverConnectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnect');
    +    pointer(SQLDriversA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDrivers');
    +    pointer(SQLExecDirectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirect');
    +    //pointer(SQLSetDescField) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescField');
    +    pointer(SQLGetConnectAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetConnectAttr');
    +    pointer(SQLGetCursorNameA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorName');
    +    pointer(SQLGetDescFieldA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescField');
    +    pointer(SQLGetDescRecA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescRec');
    +    pointer(SQLGetDiagFieldA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagField');
    +    pointer(SQLGetDiagRecA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRec');
    +    pointer(SQLGetInfoA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfo');
    +    pointer(SQLGetStmtAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttr');
    +    pointer(SQLPrepareA) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepare');
    +    pointer(SQLPrimaryKeysA) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeys');
    +    pointer(SQLProcedureColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumns');
    +    pointer(SQLProceduresA) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedures');
    +    pointer(SQLNativeSqlA) := GetProcedureAddress(ODBCLibraryHandle,'SQLNativeSql');
    +    pointer(SQLSetConnectAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttr');
    +    pointer(SQLSetCursorNameA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorName');
    +    pointer(SQLSetStmtAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttr');
    +    pointer(SQLSpecialColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumns');
    +    pointer(SQLTablesA) := GetProcedureAddress(ODBCLibraryHandle,'SQLTables');
    +// Common ansi unicode
         pointer(SQLAllocHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLAllocHandle');
    -    pointer(SQLSetEnvAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
    -    pointer(SQLFreeHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeHandle');
    -    pointer(SQLGetInfo) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfo');
    -    pointer(SQLProcedures) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedures');
    -    pointer(SQLColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumns');
    -    pointer(SQLSpecialColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumns');
    -    pointer(SQLGetDiagRec) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRec');
    -    pointer(SQLGetDiagField) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagField');
    -    pointer(SQLConnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnect');
    +    pointer(SQLBindCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindCol');
    +    pointer(SQLBindParameter) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindParameter');
    +    pointer(SQLBulkOperations) := GetProcedureAddress(ODBCLibraryHandle,'SQLBulkOperations');
    +    pointer(SQLCloseCursor) := GetProcedureAddress(ODBCLibraryHandle,'SQLCloseCursor');
         pointer(SQLDisconnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLDisconnect');
    -    pointer(SQLDriverConnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnect');
    -    pointer(SQLExecDirect) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirect');
    -    pointer(SQLPrepare) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepare');
    -    pointer(SQLCloseCursor) := GetProcedureAddress(ODBCLibraryHandle,'SQLCloseCursor');
    +    pointer(SQLEndTran) := GetProcedureAddress(ODBCLibraryHandle,'SQLEndTran');
         pointer(SQLExecute) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecute');
    +    pointer(SQLExtendedFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLExtendedFetch');
         pointer(SQLFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetch');
    -    pointer(SQLNumResultCols) := GetProcedureAddress(ODBCLibraryHandle,'SQLNumResultCols');
    -    pointer(SQLDescribeCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeCol');
         pointer(SQLFetchScroll) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetchScroll');
    -    pointer(SQLExtendedFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLExtendedFetch');
    +    pointer(SQLFreeHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeHandle');
    +    pointer(SQLFreeStmt) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeStmt');
         pointer(SQLGetData) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetData');
    -    pointer(SQLSetStmtAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttr');
    -    pointer(SQLGetStmtAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttr');
    -    //pointer(SQLSetDescField) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescField');
    +    pointer(SQLNumResultCols) := GetProcedureAddress(ODBCLibraryHandle,'SQLNumResultCols');
    +    pointer(SQLPutData) := GetProcedureAddress(ODBCLibraryHandle,'SQLPutData');
    +    pointer(SQLRowCount) := GetProcedureAddress(ODBCLibraryHandle,'SQLRowCount');
         pointer(SQLSetDescRec) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescRec');
    -    pointer(SQLBulkOperations) := GetProcedureAddress(ODBCLibraryHandle,'SQLBulkOperations');
    -    pointer(SQLPutData) := GetProcedureAddress(ODBCLibraryHandle,'SQLPutData');
    -    pointer(SQLBindCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindCol');
    +    pointer(SQLSetEnvAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
         pointer(SQLSetPos) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetPos');
    -    pointer(SQLDataSources) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSources');
    -    pointer(SQLDrivers) := GetProcedureAddress(ODBCLibraryHandle,'SQLDrivers');
    -    pointer(SQLSetConnectAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttr');
    -    pointer(SQLGetCursorName) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorName');
    -    pointer(SQLSetCursorName) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorName');
    -    pointer(SQLRowCount) := GetProcedureAddress(ODBCLibraryHandle,'SQLRowCount');
    -    pointer(SQLBindParameter) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindParameter');
    -    pointer(SQLFreeStmt) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeStmt');
    -    pointer(SQLColAttribute) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttribute');
    -    pointer(SQLEndTran) := GetProcedureAddress(ODBCLibraryHandle,'SQLEndTran');
    -    pointer(SQLTables) := GetProcedureAddress(ODBCLibraryHandle,'SQLTables');
    -    pointer(SQLPrimaryKeys) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeys');
    -    pointer(SQLProcedureColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumns');
    -    pointer(SQLStatistics) := GetProcedureAddress(ODBCLibraryHandle,'SQLStatistics');
     {$else}
         SQLAllocHandle := GetProcedureAddress(ODBCLibraryHandle,'SQLAllocHandle');
         SQLSetEnvAttr := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
    @@ -1687,6 +2107,662 @@
     
     {$ENDIF}
     
    +{$ifdef DYNLOADINGODBC}
    +
    +function GetWidePtr(param:pchar; charlen:integer; var wparam:widestring):pwidechar;
    +
    +begin
    +  if assigned(param) then
    +    begin
    +    setlength(wparam,charlen);
    +    result:=@wparam[1];
    +    end
    +  else
    +    result:=nil;
    +end;
    +
    +procedure SetCharVal(wval:widestring;param:pchar; charlen:integer);
    +begin
    +  if assigned(param) then
    +    begin
    +    SetLength(wval,charlen);
    +    StrPCopy(param,wval);
    +    end;
    +end;
    +
    +function SQLColAttribute(StatementHandle: SQLHSTMT; ColumnNumber: SQLUSMALLINT;
    +  FieldIdentifier: SQLUSMALLINT; CharacterAttribute: pchar;
    +  BufferLength: SQLSMALLINT; StringLength:PSQLSMALLINT;
    +  NumericAttribute: SQLPOINTER): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CharacterAttribute;
    +    result:=SQLColAttributeW(StatementHandle,ColumnNumber, FieldIdentifier, @wp1[1],
    +      BufferLength,StringLength,NumericAttribute);
    +    end
    +  else
    +    result:=SQLColAttributeA(StatementHandle,ColumnNumber, FieldIdentifier, CharacterAttribute,
    +      BufferLength,StringLength,NumericAttribute)
    +end;
    +
    +function SQLColumns(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  TableName: pchar; NameLength3: SQLSMALLINT; ColumnName: pchar;
    +  NameLength4: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3,wp4:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=TableName;
    +    wp3:=ColumnName;
    +    result:=SQLColumnsW(StatementHandle,@wp1[1],length(wp1),@wp2[1],
    +      length(wp2),@wp3[1],length(wp3),@wp4[1],length(wp4))
    +    end
    +  else
    +    result:=SQLColumnsA(StatementHandle,CatalogName,NameLength1,SchemaName,
    +      NameLength2,TableName,NameLength3,ColumnName,NameLength4)
    +end;
    +
    +function SQLConnect(ConnectionHandle: SQLHDBC; ServerName: pchar;
    +  NameLength1: SQLSMALLINT; UserName: pchar; NameLength2: SQLSMALLINT;
    +  Authentication: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=ServerName;
    +    wp2:=UserName;
    +    wp3:=Authentication;
    +    result:=SQLConnectW(ConnectionHandle,@wp1[1],length(wp1),
    +      @wp2[1],length(wp2),@wp3[1],length(wp3))
    +    end
    +  else
    +    result:=SQLConnectA(ConnectionHandle,ServerName,NameLength1,
    +      UserName,NameLength2,Authentication,NameLength3)
    +end;
    +
    +function SQLDataSources(EnvironmentHandle: SQLHENV; Direction: SQLUSMALLINT;
    +  ServerName: pchar; BufferLength1: SQLSMALLINT; NameLength1: PSQLSMALLINT;
    +  Description: pchar; BufferLength2: SQLSMALLINT; NameLength2: PSQLSMALLINT
    +  ): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLDataSourcesW(EnvironmentHandle,Direction,
    +      GetWidePtr(ServerName,BufferLength1,wp1),BufferLength1,NameLength1,
    +      GetWidePtr(Description,BufferLength2,wp2),BufferLength2,NameLength2);
    +    if result<>SQL_ERROR then
    +      begin
    +      SetCharVal(wp1,ServerName,NameLength1^);
    +      SetCharVal(wp2,Description,NameLength2^);
    +      end;
    +    end
    +  else
    +    result:=SQLDataSourcesA(EnvironmentHandle,Direction,
    +      ServerName,BufferLength1,NameLength1,
    +      Description,BufferLength2,NameLength2)
    +end;
    +
    +function SQLDescribeCol(StatementHandle: SQLHSTMT;
    +  ColumnNumber: SQLUSMALLINT; ColumnName: pchar; BufferLength: SQLSMALLINT;
    +  var NameLength: SQLSMALLINT; var DataType: SQLSMALLINT;
    +  var ColumnSize: SQLULEN; var DecimalDigits: SQLSMALLINT;
    +  var Nullable: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1:widestring;
    +  p1:pwidechar;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLDescribeColW(StatementHandle,ColumnNumber,GetWidePtr(ColumnName,BufferLength,wp1),BufferLength,
    +      NameLength,DataType,ColumnSize,DecimalDigits,Nullable);
    +    if result<>SQL_ERROR then
    +      SetCharVal(wp1,ColumnName,NameLength);
    +    end
    +  else
    +    result:=SQLDescribeColA(StatementHandle,ColumnNumber,ColumnName,BufferLength,
    +      NameLength,DataType,ColumnSize,DecimalDigits,Nullable)
    +end;
    +
    +function SQLDriverConnect(ConnectionHandle: SQLHDBC; hWnd: SQLHWND;
    +  szConnStrIn: pchar; nConnStrIn: SQLSMALLINT; szConnStrOut: pchar;
    +  cbConnStrOutMax: SQLSMALLINT; var pnConnStrOut: SQLSMALLINT;
    +  nDriverCompletion: SQLUSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=szConnStrIn;
    +    result:=SQLDriverConnectW(ConnectionHandle,hWnd,
    +      @wp1[1],length(wp1), GetWidePtr(szConnStrOut,cbConnStrOutMax,wp2), cbConnStrOutMax,pnConnStrOut,
    +      nDriverCompletion);
    +    if result<>SQL_ERROR then
    +      SetCharVal(wp2,szConnStrOut,pnConnStrOut);
    +    end
    +  else
    +    result:=SQLDriverConnectA(ConnectionHandle,hWnd,
    +      szConnStrIn, nConnStrIn, szConnStrOut, cbConnStrOutMax,pnConnStrOut,
    +      nDriverCompletion)
    +end;
    +
    +function SQLDrivers(EnvironmentHandle: SQLHENV; Direction: SQLUSMALLINT;
    +  DriverDescription: pchar; BufferLength1: SQLSMALLINT;
    +  DescriptionLength1: PSQLSMALLINT; DriverAttributes: pchar;
    +  BufferLength2: SQLSMALLINT; AttributesLength2: PSQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLDriversW(EnvironmentHandle, Direction,
    +      GetWidePtr(DriverDescription,BufferLength1,wp1), BufferLength1,
    +      DescriptionLength1, GetWidePtr(DriverAttributes,BufferLength2,wp2),
    +      BufferLength2, AttributesLength2);
    +    if result<>SQL_ERROR then
    +      begin
    +      SetCharVal(wp1,DriverDescription,DescriptionLength1^);
    +      SetCharVal(wp2,DriverAttributes,AttributesLength2^);
    +      end;
    +    end
    +  else
    +    result:=SQLDrivers(EnvironmentHandle, Direction,
    +      DriverDescription, BufferLength1,
    +      DescriptionLength1, DriverAttributes,
    +      BufferLength2, AttributesLength2)
    +end;
    +
    +function SQLExecDirect(StatementHandle: SQLHSTMT; StatementText: pchar;
    +  TextLength: SQLINTEGER): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=StatementText;
    +    result:=SQLExecDirectW(StatementHandle,@wp1[1],length(wp1))
    +    end
    +  else
    +    result:=SQLExecDirectA(StatementHandle,StatementText,TextLength)
    +end;
    +
    +function SQLForeignKeys(StatementHandle: SQLHSTMT; PKCatalogName: pchar;
    +  NameLength1: SQLSMALLINT; PKSchemaName: pchar; NameLength2: SQLSMALLINT;
    +  PKTableName: pchar; NameLength3: SQLSMALLINT; FKCatalogName: pchar;
    +  NameLength4: SQLSMALLINT; FKSchemaName: pchar; NameLength5: SQLSMALLINT;
    +  FKTableName: pchar; NameLength6: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3,wp4,wp5,wp6:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=PKCatalogName;
    +    wp2:=PKSchemaName;
    +    wp3:=PKTableName;
    +    wp4:=FKCatalogName;
    +    wp5:=FKSchemaName;
    +    wp6:=FKTableName;
    +    result:=SQLForeignKeysW(StatementHandle,@wp1[1],length(wp1),
    +      @wp2[1],length(wp2),@wp3[1],length(wp3),
    +      @wp4[1],length(wp4),@wp5[1],length(wp5),
    +      @wp6[1],length(wp6))
    +    end
    +  else
    +    result:=SQLForeignKeysA(StatementHandle,PKCatalogName,NameLength1,
    +      PKSchemaName,NameLength2,PKTableName,NameLength3,
    +      FKCatalogName,NameLength4,FKSchemaName,NameLength5,
    +      FKTableName,NameLength6)
    +end;
    +
    +function SQLGetConnectAttr(ConnectionHandle: SQLHDBC; Attribute: SQLINTEGER;
    +  Value: SQLPOINTER; BufferLength: SQLINTEGER; StringLength: SQLPOINTER
    +  ): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    if (Attribute in [SQL_ATTR_CURRENT_CATALOG,SQL_ATTR_TRACEFILE,SQL_ATTR_TRANSLATE_LIB])
    +      and assigned(Value) then
    +      begin
    +      setlength(wp1,BufferLength div sizeof(widechar));
    +      result:=SQLGetConnectAttrW(ConnectionHandle,Attribute,
    +        GetWidePtr(Value,BufferLength div sizeof(widechar),wp1), BufferLength, StringLength);
    +      if result<>SQL_ERROR then
    +        begin
    +        SetCharVal(wp1,Value,PSQLINTEGER(StringLength)^ div sizeof(widechar));
    +        PSQLINTEGER(StringLength)^:=length(pchar(Value));
    +        end;
    +      end
    +    else
    +      result:=SQLGetConnectAttrW(ConnectionHandle,Attribute,
    +        Value, BufferLength, StringLength)
    +    end
    +  else
    +    result:=SQLGetConnectAttrA(ConnectionHandle,Attribute,
    +      Value, BufferLength, StringLength)
    +end;
    +
    +function SQLGetCursorName(StatementHandle: SQLHSTMT; CursorName: pchar;
    +  BufferLength: SQLSMALLINT; NameLength: PSQLSMALLINT): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLGetCursorNameW(StatementHandle,GetWidePtr(CursorName,BufferLength,wp1),
    +      BufferLength, NameLength);
    +    if result<>SQL_ERROR then
    +      SetCharVal(wp1,CursorName,NameLength^);
    +    end
    +  else
    +    result:=SQLGetCursorNameA(StatementHandle,CursorName,BufferLength, NameLength)
    +end;
    +
    +function SQLGetDescField(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
    +  FieldIdentifier: SQLSMALLINT; Value: SQLPOINTER; BufferLength: SQLINTEGER;
    +  var StringLength: SQLINTEGER): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    if (FieldIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
    +        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
    +        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
    +       assigned(Value) then
    +      begin
    +      result:=SQLGetDescFieldW(DescriptorHandle,RecNumber,
    +        FieldIdentifier,GetWidePtr(Value,BufferLength div sizeof(widechar),wp1),BufferLength,StringLength);
    +      if result<>SQL_ERROR then
    +        begin
    +        SetCharVal(wp1,Value,StringLength);
    +        StringLength:=length(pchar(Value));
    +        end;
    +      end
    +    else
    +      result:=SQLGetDescFieldW(DescriptorHandle,RecNumber,
    +        FieldIdentifier,Value,BufferLength,StringLength);
    +    end
    +  else
    +    result:=SQLGetDescFieldA(DescriptorHandle,RecNumber,
    +      FieldIdentifier,Value,BufferLength,StringLength)
    +end;
    +
    +function SQLGetDescRec(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
    +  Name: pchar; BufferLength: SQLSMALLINT; var StringLength: SQLSMALLINT;
    +  var tType: SQLSMALLINT; var SubType: SQLSMALLINT; var Length: SQLLEN;
    +  var Precision: SQLSMALLINT; var Scale: SQLSMALLINT; var Nullable: SQLSMALLINT
    +  ): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLGetDescRecW(DescriptorHandle,RecNumber,
    +      GetWidePtr(Name,BufferLength,wp1),BufferLength,StringLength,tType,SubType,Length,
    +      Precision,Scale,Nullable);
    +    if result<>SQL_ERROR then
    +      SetCharVal(wp1,Name,StringLength);
    +    end
    +  else
    +    result:=SQLGetDescRecA(DescriptorHandle,RecNumber,
    +      Name,BufferLength,StringLength,tType,SubType,Length,
    +      Precision,Scale,Nullable)
    +end;
    +
    +function SQLGetDiagField(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
    +  RecNumber: SQLSMALLINT; DiagIdentifier: SQLSMALLINT; DiagInfo: SQLPOINTER;
    +  BufferLength: SQLSMALLINT; var StringLength: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    if (DiagIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
    +        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
    +        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
    +       assigned(DiagInfo) then
    +      begin
    +      result:=SQLGetDiagFieldW(HandleType, Handle,RecNumber, DiagIdentifier,
    +        GetWidePtr(DiagInfo,BufferLength,wp1),BufferLength,StringLength);
    +      if result<>SQL_ERROR then
    +        begin
    +        SetCharVal(wp1,DiagInfo,StringLength div sizeof(widechar));
    +        StringLength:=length(pchar(DiagInfo));
    +        end;
    +      end
    +    else
    +      result:=SQLGetDiagFieldW(HandleType,Handle,RecNumber, DiagIdentifier, DiagInfo,
    +        BufferLength,StringLength);
    +    end
    +  else
    +    result:=SQLGetDiagFieldA(HandleType,Handle,RecNumber, DiagIdentifier, DiagInfo,
    +      BufferLength,StringLength)
    +end;
    +
    +function SQLGetDiagRec(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
    +  RecNumber: SQLSMALLINT; Sqlstate: pchar; var NativeError: SQLINTEGER;
    +  MessageText: pchar; BufferLength: SQLSMALLINT; var TextLength: SQLSMALLINT
    +  ): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLGetDiagRecW(HandleType,Handle,RecNumber,GetWidePtr(Sqlstate,5,wp1),NativeError,
    +       GetWidePtr(MessageText,BufferLength,wp2),BufferLength,TextLength);
    +    if result<>SQL_ERROR then
    +      begin
    +      SetCharVal(wp1,Sqlstate,5);
    +      SetCharVal(wp2,MessageText,TextLength);
    +      end;
    +    end
    +  else
    +    result:=SQLGetDiagRecA(HandleType,Handle,RecNumber,Sqlstate,NativeError,
    +       MessageText,BufferLength,TextLength)
    +end;
    +
    +function SQLGetInfo(ConnectionHandle: SQLHDBC; InfoType: SQLUSMALLINT;
    +  InfoValue: SQLPOINTER; BufferLength: SQLSMALLINT;
    +  var StringLength: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    case InfoType of
    +      SQL_CATALOG_NAME,SQL_CATALOG_NAME_SEPARATOR,
    +      SQL_CATALOG_TERM,SQL_SCHEMA_TERM,SQL_COLLATION_SEQ,
    +      SQL_COLUMN_ALIAS,
    +      SQL_DATA_SOURCE_NAME,SQL_DATA_SOURCE_READ_ONLY,SQL_DATABASE_NAME,SQL_DBMS_NAME,SQL_DBMS_VER,
    +      SQL_DESCRIBE_PARAMETER,SQL_DRIVER_NAME,SQL_DRIVER_ODBC_VER,SQL_DRIVER_VER,
    +      SQL_EXPRESSIONS_IN_ORDERBY,SQL_IDENTIFIER_QUOTE_CHAR,SQL_INTEGRITY,SQL_KEYWORDS,
    +      SQL_LIKE_ESCAPE_CLAUSE,SQL_MAX_ROW_SIZE_INCLUDES_LONG,SQL_MULT_RESULT_SETS,
    +      SQL_MULTIPLE_ACTIVE_TXN,SQL_NEED_LONG_DATA_LEN,SQL_ORDER_BY_COLUMNS_IN_SELECT,
    +      SQL_PROCEDURE_TERM,SQL_PROCEDURES,SQL_ROW_UPDATES,SQL_SEARCH_PATTERN_ESCAPE,
    +      SQL_SERVER_NAME,SQL_SPECIAL_CHARACTERS,SQL_TABLE_TERM,SQL_USER_NAME,SQL_XOPEN_CLI_YEAR,
    +      SQL_ACCESSIBLE_PROCEDURES, SQL_ACCESSIBLE_TABLES,SQL_OUTER_JOINS:
    +            begin
    +            result:=SQLGetInfoW(ConnectionHandle,InfoType,
    +              GetWidePtr(InfoValue,BufferLength div sizeof(widechar),wp1),
    +              BufferLength,StringLength);
    +            if result<>SQL_ERROR then
    +              begin
    +              SetCharVal(wp1,InfoValue,StringLength div sizeof(widechar));
    +              StringLength:=length(pchar(InfoValue));
    +              end;
    +            end
    +    else
    +      result:=SQLGetInfoW(ConnectionHandle,InfoType,InfoValue,BufferLength,StringLength);
    +    end
    +  else
    +    result:=SQLGetInfoA(ConnectionHandle,InfoType,InfoValue,BufferLength,StringLength)
    +end;
    +
    +function SQLGetStmtAttr(StatementHandle: SQLHSTMT; Attribute: SQLINTEGER;
    +  Value: SQLPOINTER; BufferLength: SQLINTEGER; StringLength: SQLPOINTER
    +  ): SQLRETURN;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLGetStmtAttrW(StatementHandle,Attribute,
    +      Value,BufferLength,StringLength);
    +    end
    +  else
    +    result:=SQLGetStmtAttrA(StatementHandle,Attribute,
    +      Value,BufferLength,StringLength)
    +end;
    +
    +
    +function SQLNativeSql(StatementHandle: SQLHSTMT; InStatementText: pchar;
    +  TextLength1: SQLINTEGER; OutStatementText: pchar; BufferLength: SQLINTEGER;
    +  var TextLength2Ptr: SQLINTEGER): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=InStatementText;
    +    result:=SQLNativeSqlW(StatementHandle,@wp1[1],length(wp1),
    +      GetWidePtr(OutStatementText,BufferLength,wp2),BufferLength,TextLength2Ptr);
    +    if result<>SQL_ERROR then
    +      SetCharVal(wp2,OutStatementText,TextLength2Ptr);
    +    end
    +  else
    +    result:=SQLNativeSqlA(StatementHandle,InStatementText,TextLength1,
    +      OutStatementText,BufferLength,TextLength2Ptr)
    +end;
    +
    +function SQLPrepare(StatementHandle: SQLHSTMT; StatementText: pchar;
    +  TextLength: SQLINTEGER): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=StatementText;
    +    result:=SQLPrepareW(StatementHandle, @wp1[1],length(wp1));
    +    end
    +  else
    +    result:=SQLPrepareA(StatementHandle, StatementText,TextLength)
    +end;
    +
    +function SQLPrimaryKeys(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  TableName: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=TableName;
    +    result:=SQLPrimaryKeysW(StatementHandle,@wp1[1],length(wp1),
    +      @wp2[1],length(wp2),@wp3[1],length(wp3));
    +    end
    +  else
    +    result:=SQLPrimaryKeysA(StatementHandle,CatalogName,
    +      NameLength1,SchemaName, NameLength2,TableName, NameLength3)
    +end;
    +
    +function SQLProcedureColumns(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  ProcName: pchar; NameLength3: SQLSMALLINT; ColumnName: pchar;
    +  NameLength4: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3,wp4:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=ProcName;
    +    wp4:=ColumnName;
    +    result:=SQLProcedureColumnsW(StatementHandle,@wp1[1],length(wp1),
    +      @wp2[1],length(wp2),@wp3[1],length(wp3),@wp4[1],length(wp4));
    +    end
    +  else
    +    result:=SQLProcedureColumnsA(StatementHandle,CatalogName,
    +      NameLength1, SchemaName,NameLength2,ProcName,NameLength3,
    +      ColumnName,NameLength4)
    +end;
    +
    +function SQLProcedures(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  ProcName: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=ProcName;
    +    result:=SQLPrimaryKeysW(StatementHandle,@wp1[1],length(wp1),
    +      @wp2[1],length(wp2),@wp3[1],length(wp3));
    +    end
    +  else
    +    result:=SQLProcedures(StatementHandle,CatalogName,
    +      NameLength1,SchemaName,NameLength2,ProcName,NameLength3)
    +end;
    +
    +function SQLSetConnectAttr(ConnectionHandle: SQLHDBC; Attribute: SQLINTEGER;
    +  Value: SQLPOINTER; StringLength: SQLINTEGER): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    if (Attribute in [SQL_ATTR_CURRENT_CATALOG,SQL_ATTR_TRACEFILE,SQL_ATTR_TRANSLATE_LIB])
    +      and assigned(Value) then
    +      begin
    +      wp1:=pchar(Value);
    +      result:=SQLSetConnectAttrW(ConnectionHandle,Attribute,
    +        @wp1[1],length(wp1)*sizeof(widechar));
    +      end
    +    else
    +      result:=SQLSetConnectAttrW(ConnectionHandle,Attribute,
    +        Value, StringLength)
    +    end
    +  else
    +    result:=SQLSetConnectAttrA(ConnectionHandle,Attribute,
    +      Value, StringLength)
    +end;
    +
    +function SQLSetCursorName(StatementHandle: SQLHSTMT; CursorName: PSQLCHAR;
    +  NameLength: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CursorName;
    +    result:=SQLSetCursorNameW(StatementHandle,@wp1[1],length(wp1));
    +    end
    +  else
    +    result:=SQLSetCursorNameA(StatementHandle,CursorName,NameLength)
    +end;
    +
    +function SQLSetDescField(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
    +  FieldIdentifier: SQLSMALLINT; Value: SQLPOINTER; BufferLength: SQLINTEGER
    +  ): SQLRETURN;
    +var
    +  wp1,wp2:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    if (FieldIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
    +        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
    +        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
    +       assigned(Value) then
    +      begin
    +      wp1:=pchar(Value);
    +      result:=SQLSetDescField(DescriptorHandle,RecNumber,
    +        FieldIdentifier,@wp1[1],length(wp1)*sizeof(widechar));
    +      end
    +    else
    +      result:=SQLSetDescFieldW(DescriptorHandle,RecNumber,
    +        FieldIdentifier,Value,BufferLength);
    +    end
    +  else
    +    result:=SQLSetDescFieldA(DescriptorHandle,RecNumber,
    +      FieldIdentifier,Value,BufferLength)
    +end;
    +
    +function SQLSetStmtAttr(StatementHandle: SQLHSTMT; Attribute: SQLINTEGER;
    +  Value: SQLPOINTER; StringLength: SQLINTEGER): SQLRETURN;
    +begin
    +  if IsUnicode then
    +    begin
    +    result:=SQLSetStmtAttrW(StatementHandle,Attribute,
    +      Value,StringLength);
    +    end
    +  else
    +    result:=SQLSetStmtAttrA(StatementHandle,Attribute,
    +      Value,StringLength)
    +end;
    +
    +function SQLSpecialColumns(StatementHandle: SQLHSTMT;
    +  IdentifierType: SQLUSMALLINT; CatalogName: pchar; NameLength1: SQLSMALLINT;
    +  SchemaName: pchar; NameLength2: SQLSMALLINT; TableName: pchar;
    +  NameLength3: SQLSMALLINT; Scope: SQLUSMALLINT; Nullable: SQLUSMALLINT
    +  ): SQLRETURN;
    +var
    +  wp1,wp2,wp3:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=TableName;
    +    result:=SQLSpecialColumnsW(StatementHandle,IdentifierType,
    +      @wp1[1],length(wp1),@wp2[1],length(wp2),
    +      @wp3[1],length(wp3), Scope, Nullable)
    +    end
    +  else
    +    result:=SQLSpecialColumnsA(StatementHandle,IdentifierType,
    +      CatalogName,NameLength1,SchemaName, NameLength2,
    +      TableName,NameLength3, Scope, Nullable)
    +end;
    +
    +function SQLStatistics(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  TableName: pchar; NameLength3: SQLSMALLINT; Unique: SQLUSMALLINT;
    +  Reserved: SQLUSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=TableName;
    +    result:=SQLStatisticsW(StatementHandle,
    +      @wp1[1],length(wp1),@wp2[1],length(wp2),
    +      @wp3[1],length(wp3), Unique,Reserved)
    +    end
    +  else
    +    result:=SQLStatisticsA(StatementHandle,CatalogName,
    +      NameLength1,SchemaName,NameLength2,
    +      TableName,NameLength3,Unique,Reserved)
    +end;
    +
    +function SQLTables(StatementHandle: SQLHSTMT; CatalogName: pchar;
    +  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
    +  TableName: pchar; NameLength3: SQLSMALLINT; TableType: pchar;
    +  NameLength4: SQLSMALLINT): SQLRETURN;
    +var
    +  wp1,wp2,wp3,wp4:widestring;
    +begin
    +  if IsUnicode then
    +    begin
    +    wp1:=CatalogName;
    +    wp2:=SchemaName;
    +    wp3:=TableName;
    +    wp4:=TableType;
    +    result:=SQLTablesW(StatementHandle,
    +      @wp1[1],length(wp1),@wp2[1],length(wp2),
    +      @wp3[1],length(wp3),@wp4[1],length(wp4))
    +    end
    +  else
    +    result:=SQLTablesA(StatementHandle,CatalogName,
    +      NameLength1,SchemaName,NameLength2,
    +      TableName,NameLength3,TableType,NameLength4)
    +end;
    +
    +{$endif DYNLOADINGODBC}
    +
    +
     function DateStructToDateTime( b:PSQL_DATE_STRUCT):TDateTime;
     begin
       Result:=EncodeDate( b^.Year, b^.Month, b^.Day);
    
    odbc.inc.diff (63,006 bytes)

Relationships

related to 0012206 resolvedLacaK ODBC Query in DBGrid, some Cells are Empty (Encoding) 

Activities

2012-05-21 17:11

 

odbc.inc.diff (63,006 bytes)
Index: src/odbcsql.inc
===================================================================
--- src/odbcsql.inc	(revision 21326)
+++ src/odbcsql.inc	(working copy)
@@ -1,3 +1,10 @@
+{
+    This file is part of the Freepascal Free Component Library (FCL)
+
+    Unicode support added by Ludo Brands 2012.
+}
+
+
 {$ifdef fpc}
 {$mode objfpc}
 {$macro on}
@@ -78,6 +85,14 @@
   SQLDOUBLE    = cdouble;
   SQLFLOAT     = cdouble;
   SQLHWND      = pointer;
+  {$IFDEF CPU64}
+  SQLLEN=int64;
+  SQLULEN =QWord;
+  {$ELSE}
+  SQLLEN=SQLINTEGER;
+  SQLULEN =SQLUINTEGER;
+  {$ENDIF}
+
   PSQLCHAR      = PChar;
   PSQLINTEGER   = ^SQLINTEGER;
   PSQLUINTEGER  = ^SQLUINTEGER;
@@ -826,6 +841,208 @@
   SQL_USER_NAME                       = 47;
   SQL_TXN_ISOLATION_OPTION            = 72;
   SQL_TRANSACTION_ISOLATION_OPTION    = SQL_TXN_ISOLATION_OPTION;
+  SQL_MAX_DRIVER_CONNECTIONS=0;
+  SQL_MAXIMUM_DRIVER_CONNECTIONS=SQL_MAX_DRIVER_CONNECTIONS;
+  SQL_MAX_CONCURRENT_ACTIVITIES=1;
+  SQL_MAXIMUM_CONCURRENT_ACTIVITIES=SQL_MAX_CONCURRENT_ACTIVITIES;
+  SQL_DATA_SOURCE_NAME=2;
+  SQL_FETCH_DIRECTION=8;
+  SQL_SERVER_NAME=13;
+  SQL_SEARCH_PATTERN_ESCAPE=14;
+  SQL_DBMS_NAME=17;
+  SQL_DBMS_VER=18;
+  SQL_ACCESSIBLE_TABLES=19;
+  SQL_ACCESSIBLE_PROCEDURES=20;
+  SQL_CURSOR_COMMIT_BEHAVIOR=23;
+  SQL_DATA_SOURCE_READ_ONLY=25;
+  SQL_DEFAULT_TXN_ISOLATION=26;
+  SQL_IDENTIFIER_CASE=28;
+  SQL_IDENTIFIER_QUOTE_CHAR=29;
+  SQL_MAX_COLUMN_NAME_LEN=30;
+  SQL_MAXIMUM_COLUMN_NAME_LENGTH=SQL_MAX_COLUMN_NAME_LEN;
+  SQL_MAX_CURSOR_NAME_LEN=31;
+  SQL_MAXIMUM_CURSOR_NAME_LENGTH=SQL_MAX_CURSOR_NAME_LEN;
+  SQL_MAX_SCHEMA_NAME_LEN=32;
+  SQL_MAXIMUM_SCHEMA_NAME_LENGTH=SQL_MAX_SCHEMA_NAME_LEN;
+  SQL_MAX_CATALOG_NAME_LEN=34;
+  SQL_MAXIMUM_CATALOG_NAME_LENGTH=SQL_MAX_CATALOG_NAME_LEN;
+  SQL_MAX_TABLE_NAME_LEN=35;
+  SQL_INTEGRITY=73;
+  SQL_GETDATA_EXTENSIONS=81;
+  SQL_NULL_COLLATION=85;
+  SQL_ALTER_TABLE=86;
+  SQL_ORDER_BY_COLUMNS_IN_SELECT=90;
+  SQL_SPECIAL_CHARACTERS=94;
+  SQL_MAX_COLUMNS_IN_GROUP_BY=97;
+  SQL_MAXIMUM_COLUMNS_IN_GROUP_BY=SQL_MAX_COLUMNS_IN_GROUP_BY;
+  SQL_MAX_COLUMNS_IN_INDEX=98;
+  SQL_MAXIMUM_COLUMNS_IN_INDEX=SQL_MAX_COLUMNS_IN_INDEX;
+  SQL_MAX_COLUMNS_IN_ORDER_BY=99;
+  SQL_MAXIMUM_COLUMNS_IN_ORDER_BY=SQL_MAX_COLUMNS_IN_ORDER_BY;
+  SQL_MAX_COLUMNS_IN_SELECT=100;
+  SQL_MAXIMUM_COLUMNS_IN_SELECT=SQL_MAX_COLUMNS_IN_SELECT;
+  SQL_MAX_COLUMNS_IN_TABLE=101;
+  SQL_MAX_INDEX_SIZE=102;
+  SQL_MAXIMUM_INDEX_SIZE=SQL_MAX_INDEX_SIZE;
+  SQL_MAX_ROW_SIZE=104;
+  SQL_MAXIMUM_ROW_SIZE=SQL_MAX_ROW_SIZE;
+  SQL_MAX_STATEMENT_LEN=105;
+  SQL_MAXIMUM_STATEMENT_LENGTH=SQL_MAX_STATEMENT_LEN;
+  SQL_MAX_TABLES_IN_SELECT=106;
+  SQL_MAXIMUM_TABLES_IN_SELECT=SQL_MAX_TABLES_IN_SELECT;
+  SQL_MAX_USER_NAME_LEN=107;
+  SQL_MAXIMUM_USER_NAME_LENGTH=SQL_MAX_USER_NAME_LEN;
+
+  SQL_OJ_CAPABILITIES=115;
+  SQL_OUTER_JOIN_CAPABILITIES=SQL_OJ_CAPABILITIES;
+
+  SQL_XOPEN_CLI_YEAR=10000;
+  SQL_CURSOR_SENSITIVITY=10001;
+  SQL_DESCRIBE_PARAMETER=10002;
+  SQL_CATALOG_NAME=10003;
+  SQL_COLLATION_SEQ=10004;
+  SQL_MAX_IDENTIFIER_LEN=10005;
+  SQL_MAXIMUM_IDENTIFIER_LENGTH=SQL_MAX_IDENTIFIER_LEN;
+
+  SQL_INFO_FIRST=   0;
+  SQL_ACTIVE_CONNECTIONS=   0 ;	//* MAX_DRIVER_CONNECTIONS */;
+  SQL_ACTIVE_STATEMENTS=1;	//* MAX_CONCURRENT_ACTIVITIES */;
+  SQL_DRIVER_HDBC=  3;
+  SQL_DRIVER_HENV=  4;
+  SQL_DRIVER_HSTMT= 5;
+  SQL_DRIVER_NAME=  6;
+  SQL_DRIVER_VER=   7;
+  SQL_ODBC_API_CONFORMANCE= 9;
+  SQL_ODBC_VER=10;
+  SQL_ROW_UPDATES= 11;
+  SQL_ODBC_SAG_CLI_CONFORMANCE=12;
+  SQL_ODBC_SQL_CONFORMANCE=15;
+  SQL_PROCEDURES=  21;
+  SQL_CONCAT_NULL_BEHAVIOR=22;
+  SQL_CURSOR_ROLLBACK_BEHAVIOR=24;
+  SQL_EXPRESSIONS_IN_ORDERBY=  27;
+  SQL_MAX_OWNER_NAME_LEN=  32;	//* MAX_SCHEMA_NAME_LEN */;
+  SQL_MAX_PROCEDURE_NAME_LEN=  33;
+  SQL_MAX_QUALIFIER_NAME_LEN=  34;	//* MAX_CATALOG_NAME_LEN */;
+  SQL_MULT_RESULT_SETS=36;
+  SQL_MULTIPLE_ACTIVE_TXN= 37;
+  SQL_OUTER_JOINS= 38;
+  SQL_OWNER_TERM=  39;
+  SQL_PROCEDURE_TERM=  40;
+  SQL_QUALIFIER_NAME_SEPARATOR=41;
+  SQL_QUALIFIER_TERM=  42;
+  SQL_TABLE_TERM=  45;
+  SQL_CONVERT_FUNCTIONS=   48;
+  SQL_NUMERIC_FUNCTIONS=   49;
+  SQL_STRING_FUNCTIONS=50;
+  SQL_SYSTEM_FUNCTIONS=51;
+  SQL_TIMEDATE_FUNCTIONS=  52;
+  SQL_CONVERT_BIGINT=  53;
+  SQL_CONVERT_BINARY=  54;
+  SQL_CONVERT_BIT= 55;
+  SQL_CONVERT_CHAR=56;
+  SQL_CONVERT_DATE=57;
+  SQL_CONVERT_DECIMAL= 58;
+  SQL_CONVERT_DOUBLE=  59;
+  SQL_CONVERT_FLOAT=   60;
+  SQL_CONVERT_INTEGER= 61;
+  SQL_CONVERT_LONGVARCHAR= 62;
+  SQL_CONVERT_NUMERIC= 63;
+  SQL_CONVERT_REAL=64;
+  SQL_CONVERT_SMALLINT=65;
+  SQL_CONVERT_TIME=66;
+  SQL_CONVERT_TIMESTAMP=   67;
+  SQL_CONVERT_TINYINT= 68;
+  SQL_CONVERT_VARBINARY=   69;
+  SQL_CONVERT_VARCHAR= 70;
+  SQL_CONVERT_LONGVARBINARY=   71;
+  SQL_ODBC_SQL_OPT_IEF=73;		//* SQL_INTEGRITY */;
+  SQL_CORRELATION_NAME=74;
+  SQL_NON_NULLABLE_COLUMNS=75;
+  SQL_DRIVER_HLIB= 76;
+  SQL_DRIVER_ODBC_VER= 77;
+  SQL_LOCK_TYPES=  78;
+  SQL_POS_OPERATIONS=  79;
+  SQL_POSITIONED_STATEMENTS=   80;
+  SQL_FILE_USAGE=  84;
+  SQL_COLUMN_ALIAS=87;
+  SQL_GROUP_BY=88;
+  SQL_KEYWORDS=89;
+  SQL_OWNER_USAGE= 91;
+  SQL_QUALIFIER_USAGE= 92;
+  SQL_QUOTED_IDENTIFIER_CASE=  93;
+  SQL_SUBQUERIES=  95;
+  SQL_UNION=   96;
+  SQL_MAX_ROW_SIZE_INCLUDES_LONG=  103;
+  SQL_MAX_CHAR_LITERAL_LEN=108;
+  SQL_TIMEDATE_ADD_INTERVALS=  109;
+  SQL_TIMEDATE_DIFF_INTERVALS= 110;
+  SQL_NEED_LONG_DATA_LEN=  111;
+  SQL_MAX_BINARY_LITERAL_LEN=  112;
+  SQL_LIKE_ESCAPE_CLAUSE=  113;
+  SQL_QUALIFIER_LOCATION=  114;
+  SQL_ACTIVE_ENVIRONMENTS=		116;
+ 	SQL_ALTER_DOMAIN=117;
+ 	SQL_SQL_CONFORMANCE=118;
+  SQL_DATETIME_LITERALS=		119;
+ 	SQL_ASYNC_MODE=	10021;	//* new X/Open spec */;
+  SQL_BATCH_ROW_COUNT=120;
+  SQL_BATCH_SUPPORT=121;
+  SQL_CATALOG_LOCATION=		SQL_QUALIFIER_LOCATION;
+  SQL_CATALOG_NAME_SEPARATOR=	SQL_QUALIFIER_NAME_SEPARATOR;
+  SQL_CATALOG_TERM=SQL_QUALIFIER_TERM;
+  SQL_CATALOG_USAGE=SQL_QUALIFIER_USAGE;
+ 	SQL_CONVERT_WCHAR=122;
+  SQL_CONVERT_INTERVAL_DAY_TIME=123;
+  SQL_CONVERT_INTERVAL_YEAR_MONTH=124;
+ 	SQL_CONVERT_WLONGVARCHAR=	125;
+ 	SQL_CONVERT_WVARCHAR=		126;
+ 	SQL_CREATE_ASSERTION=		127;
+ 	SQL_CREATE_CHARACTER_SET=	128;
+ 	SQL_CREATE_COLLATION=		129;
+ 	SQL_CREATE_DOMAIN=130;
+ 	SQL_CREATE_SCHEMA=131;
+ 	SQL_CREATE_TABLE=132;
+ 	SQL_CREATE_TRANSLATION=		133;
+ 	SQL_CREATE_VIEW=	134;
+  SQL_DRIVER_HDESC=135;
+ 	SQL_DROP_ASSERTION=136;
+ 	SQL_DROP_CHARACTER_SET=		137;
+ 	SQL_DROP_COLLATION=138;
+ 	SQL_DROP_DOMAIN=	139;
+ 	SQL_DROP_SCHEMA=	140;
+ 	SQL_DROP_TABLE=	141;
+ 	SQL_DROP_TRANSLATION=		142;
+ 	SQL_DROP_VIEW=	143;
+  SQL_MAX_ASYNC_CONCURRENT_STATEMENTS=10022;	//* new X/Open spec */;
+  SQL_ODBC_INTERFACE_CONFORMANCE=152;
+  SQL_PARAM_ARRAY_ROW_COUNTS     =153;
+  SQL_PARAM_ARRAY_SELECTS     =154;
+  SQL_SCHEMA_TERM=	SQL_OWNER_TERM;
+  SQL_SCHEMA_USAGE=SQL_OWNER_USAGE;
+  SQL_SQL92_DATETIME_FUNCTIONS=155;
+  SQL_SQL92_FOREIGN_KEY_DELETE_RULE =		156;
+  SQL_SQL92_FOREIGN_KEY_UPDATE_RULE =		157;
+  SQL_SQL92_GRANT=	158;
+  SQL_SQL92_NUMERIC_VALUE_FUNCTIONS =		159;
+  SQL_SQL92_PREDICATES=		160;
+  SQL_SQL92_RELATIONAL_JOIN_OPERATORS=		161;
+  SQL_SQL92_REVOKE=162;
+  SQL_SQL92_ROW_VALUE_CONSTRUCTOR=163;
+  SQL_SQL92_STRING_FUNCTIONS=	164;
+  SQL_SQL92_VALUE_EXPRESSIONS=	165;
+  SQL_STANDARD_CLI_CONFORMANCE=166;
+  SQL_AGGREGATE_FUNCTIONS=		169;
+  SQL_DDL_INDEX=	170;
+  SQL_DM_VER=		171;
+  SQL_INSERT_STATEMENT=		172;
+  SQL_CONVERT_GUID=173;
+  SQL_UNION_STATEMENT=SQL_UNION;
+  SQL_DTC_TRANSITION_COST=		1750;
+
+  { Deprecated defines from prior versions of ODBC }
+  SQL_DATABASE_NAME=16;
+
 {
 #define SQL_INTEGRITY                       73
 #define SQL_GETDATA_EXTENSIONS              81
@@ -852,20 +1069,7 @@
 #define SQL_MAXIMUM_TABLES_IN_SELECT       SQL_MAX_TABLES_IN_SELECT
 #define SQL_MAX_USER_NAME_LEN              107
 #define SQL_MAXIMUM_USER_NAME_LENGTH       SQL_MAX_USER_NAME_LEN}
-{$ifdef ODBCVER3}
-  SQL_OJ_CAPABILITIES         = 115;
-  SQL_OUTER_JOIN_CAPABILITIES = SQL_OJ_CAPABILITIES;
-{$endif} { ODBCVER >= 0x0300 }
 
-{$ifdef ODBCVER3}
-  SQL_XOPEN_CLI_YEAR            = 10000;
-  SQL_CURSOR_SENSITIVITY        = 10001;
-  SQL_DESCRIBE_PARAMETER        = 10002;
-  SQL_CATALOG_NAME              = 10003;
-  SQL_COLLATION_SEQ             = 10004;
-  SQL_MAX_IDENTIFIER_LEN        = 10005;
-  SQL_MAXIMUM_IDENTIFIER_LENGTH = SQL_MAX_IDENTIFIER_LEN;
-{$endif} { ODBCVER >= 0x0300 }
 
 {/* SQL_ALTER_TABLE bitmasks */
 #if (ODBCVER >= 0x0200)
@@ -1134,7 +1338,7 @@
 
 type   tSQLGetInfo=function (ConnectionHandle:SQLHDBC;
            InfoType:SQLUSMALLINT;InfoValue:SQLPOINTER;
-           BufferLength:SQLSMALLINT;StringLength:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+           BufferLength:SQLSMALLINT;var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
 
 type   TSQLBulkOperations=function (StatementHandle: SQLHSTMT;
            Operation:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
@@ -1234,53 +1438,230 @@
            TableName:PSQLCHAR; NameLength3:SQLSMALLINT;
            Unique:SQLUSMALLINT;
            Reserved:SQLUSMALLINT): SQLRETURN; {$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDescRec = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:PChar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLForeignKeys = function (StatementHandle:SQLHSTMT; PKCatalogName:PChar; NameLength1:SQLSMALLINT; PKSchemaName:PChar; NameLength2:SQLSMALLINT; PKTableName:PChar; NameLength3:SQLSMALLINT;
+                               FKCatalogName:PChar; NameLength4:SQLSMALLINT; FKSchemaName:PChar; NameLength5:SQLSMALLINT; FKTableName:PChar; NameLength6:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetConnectAttr = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDescField = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLNativeSql = function (StatementHandle:SQLHSTMT;InStatementText:PChar;TextLength1:SQLINTEGER;
+                                OutStatementText:PChar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
 
+
+type   TSQLColAttributeW = function (StatementHandle:SQLHSTMT;
+                                                ColumnNumber:SQLUSMALLINT;  FieldIdentifier:SQLUSMALLINT;
+                                                CharacterAttribute:PWideChar;  BufferLength:SQLSMALLINT;
+                                                StringLength:PSQLSMALLINT;  NumericAttribute:SQLPOINTER
+                                                ):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLColumnsW = function (StatementHandle:SQLHSTMT;CatalogName:PWideChar;  NameLength1:SQLSMALLINT;
+                    SchemaName:PWideChar;  NameLength2:SQLSMALLINT;TableName:PWideChar;  NameLength3:SQLSMALLINT;
+                    ColumnName:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLConnectW = function (ConnectionHandle:SQLHDBC ;
+                                          ServerName:PWideChar;  NameLength1:SQLSMALLINT;
+                                          UserName:PWideChar;  NameLength2:SQLSMALLINT;
+                                          Authentication:PWideChar;  NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLDataSourcesW = function (EnvironmentHandle:SQLHENV;
+           Direction:SQLUSMALLINT;ServerName:PWideChar;
+           BufferLength1:SQLSMALLINT;NameLength1:PSQLSMALLINT;
+           Description:PWideChar;BufferLength2:SQLSMALLINT;
+           NameLength2:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLDescribeColW = function (StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT;
+                 ColumnName:PWideChar; BufferLength:SQLSMALLINT; var NameLength:SQLSMALLINT;
+                 var DataType:SQLSMALLINT; var ColumnSize:SQLULEN; var DecimalDigits:SQLSMALLINT;
+                 var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLDriverConnectW = function (ConnectionHandle:SQLHDBC;hWnd:SQLHWND;szConnStrIn:PWideChar;
+               nConnStrIn:SQLSMALLINT;szConnStrOut:PWideChar;cbConnStrOutMax:SQLSMALLINT;
+               var pnConnStrOut:SQLSMALLINT;nDriverCompletion:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLDriversW=function (EnvironmentHandle:SQLHENV;
+           Direction:SQLUSMALLINT;DriverDescription:PWideChar;
+           BufferLength1:SQLSMALLINT;DescriptionLength1:PSQLSMALLINT;
+           DriverAttributes:PWideChar;BufferLength2:SQLSMALLINT;
+           AttributesLength2:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLExecDirectW = function (StatementHandle:SQLHSTMT; StatementText:PWideChar;  TextLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLForeignKeysW = function (StatementHandle:SQLHSTMT; PKCatalogName:PWideChar; NameLength1:SQLSMALLINT; PKSchemaName:PWideChar; NameLength2:SQLSMALLINT; PKTableName:PWideChar; NameLength3:SQLSMALLINT;
+                               FKCatalogName:PWideChar; NameLength4:SQLSMALLINT; FKSchemaName:PWideChar; NameLength5:SQLSMALLINT; FKTableName:PWideChar; NameLength6:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetConnectAttrW = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetCursorNameW = function (StatementHandle:SQLHSTMT; CursorName:PWideChar; BufferLength:SQLSMALLINT;  NameLength:PSQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDescFieldW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDescRecW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:PWideChar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDiagFieldW = function (HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; DiagIdentifier:SQLSMALLINT; DiagInfo:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetDiagRecW = function (HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; Sqlstate:PWideChar; var NativeError:SQLINTEGER;  MessageText:PWideChar; BufferLength:SQLSMALLINT;  var TextLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetInfoW = function (ConnectionHandle:SQLHDBC ; InfoType:SQLUSMALLINT; InfoValue:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLGetStmtAttrW = function (StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER;  StringLength:SQLPOINTER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLNativeSqlW = function (StatementHandle:SQLHSTMT;InStatementText:PWideChar;TextLength1:SQLINTEGER;
+                                OutStatementText:PWideChar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLPrepareW = function (StatementHandle:SQLHSTMT; StatementText:PWideChar;  TextLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLPrimaryKeysW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
+              SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLProcedureColumnsW = function (StatementHandle:SQLHSTMT;CatalogName:PWideChar;  NameLength1:SQLSMALLINT;
+                    SchemaName:PWideChar;  NameLength2:SQLSMALLINT;ProcName:PWideChar;  NameLength3:SQLSMALLINT;
+                    ColumnName:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLProceduresW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
+              SchemaName:PWideChar; NameLength2:SQLSMALLINT; ProcName:PWideChar; NameLength3:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLSetConnectAttrW = function (ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLSetCursorNameW = function (StatementHandle:SQLHSTMT; CursorName:PWideChar;  NameLength:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLSetDescFieldW = function (DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER;  BufferLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLSetStmtAttrW = function (StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLSpecialColumnsW = function (StatementHandle:SQLHSTMT; IdentifierType:SQLUSMALLINT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
+              SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT;
+              Scope:SQLUSMALLINT;  Nullable:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLStatisticsW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT;
+             SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT;
+             Unique:SQLUSMALLINT;  Reserved:SQLUSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+type   TSQLTablesW = function (StatementHandle:SQLHSTMT; CatalogName:PWideChar; NameLength1:SQLSMALLINT; SchemaName:PWideChar; NameLength2:SQLSMALLINT; TableName:PWideChar; NameLength3:SQLSMALLINT; TableType:PWideChar;  NameLength4:SQLSMALLINT):SQLRETURN;{$ifdef fpc} extdecl {$else} stdcall {$endif};
+
+
+
+var    SQLColAttributeW:TSQLColAttributeW;
+var    SQLColumnsW:TSQLColumnsW;
+var    SQLConnectW:TSQLConnectW;
+var    SQLDataSourcesW:TSQLDataSourcesW;
+var    SQLDescribeColW:TSQLDescribeColW;
+var    SQLDriverConnectW:TSQLDriverConnectW;
+var    SQLDriversW:TSQLDriversW;
+var    SQLExecDirectW:TSQLExecDirectW;
+var    SQLForeignKeysW:TSQLForeignKeysW;
+var    SQLGetConnectAttrW:TSQLGetConnectAttrW;
+var    SQLGetCursorNameW:TSQLGetCursorNameW;
+var    SQLGetDescFieldW:TSQLGetDescFieldW;
+var    SQLGetDescRecW:TSQLGetDescRecW;
+var    SQLGetDiagFieldW:TSQLGetDiagFieldW;
+var    SQLGetDiagRecW:TSQLGetDiagRecW;
+var    SQLGetInfoW:TSQLGetInfoW;
+var    SQLGetStmtAttrW:TSQLGetStmtAttrW;
+var    SQLPrepareW:TSQLPrepareW;
+var    SQLPrimaryKeysW:TSQLPrimaryKeysW;
+var    SQLProcedureColumnsW : TSQLProcedureColumnsW;
+var    SQLProceduresW:TSQLProceduresW;
+var    SQLNativeSqlW:TSQLNativeSqlW;
+var    SQLSetConnectAttrW:TSQLSetConnectAttrW;
+var    SQLSetCursorNameW:TSQLSetCursorNameW;
+var    SQLSetDescFieldW:TSQLSetDescFieldW;
+var    SQLSetStmtAttrW:TSQLSetStmtAttrW;
+var    SQLSpecialColumnsW:TSQLSpecialColumnsW;
+var    SQLStatisticsW: TSQLStatisticsW;
+var    SQLTablesW:TSQLTablesW;
+
+var    SQLColAttributeA:TSQLColAttribute;
+var    SQLColumnsA:TSQLColumns;
+var    SQLConnectA:TSQLConnect;
+var    SQLDataSourcesA:TSQLDataSources;
+var    SQLDescribeColA:TSQLDescribeCol;
+var    SQLGetDescRecA:TSQLGetDescRec;
+var    SQLDriverConnectA:TSQLDriverConnect;
+var    SQLDriversA:TSQLDrivers;
+var    SQLExecDirectA:TSQLExecDirect;
+var    SQLForeignKeysA:TSQLForeignKeys;
+var    SQLGetConnectAttrA:TSQLGetConnectAttr;
+var    SQLGetCursorNameA:TSQLGetCursorName;
+var    SQLGetDescFieldA:TSQLGetDescField;
+var    SQLGetDiagFieldA:TSQLGetDiagField;
+var    SQLGetDiagRecA:TSQLGetDiagRec;
+var    SQLGetInfoA:tSQLGetInfo;
+var    SQLGetStmtAttrA:TSQLGetStmtAttr;
+var    SQLPrepareA:TSQLPrepare;
+var    SQLPrimaryKeysA:TSQLPrimaryKeys;
+var    SQLProcedureColumnsA : TSQLProcedureColumns;
+var    SQLProceduresA:TSQLProcedures;
+var    SQLNativeSqlA:TSQLNativeSql;
+var    SQLSetConnectAttrA:TSQLSetConnectAttr;
+var    SQLSetCursorNameA:TSQLSetCursorName;
+var    SQLSetDescFieldA:TSQLSetDescField;
+var    SQLSetStmtAttrA:TSQLSetStmtAttr;
+var    SQLSpecialColumnsA:TSQLSpecialColumns;
+var    SQLStatisticsA: TSQLStatistics;
+var    SQLTablesA:TSQLTables;
+
 var    SQLAllocHandle:tSQLAllocHandle;
-var    SQLSetEnvAttr:tSQLSetEnvAttr;
-var    SQLFreeHandle:tSQLFreeHandle;
-var    SQLGetInfo:tSQLGetInfo;
-var    SQLProcedures:TSQLProcedures;
-var    SQLColumns:TSQLColumns;
-var    SQLSpecialColumns:TSQLSpecialColumns;
-var    SQLGetDiagRec:TSQLGetDiagRec;
-var    SQLGetDiagField:TSQLGetDiagField;
-var    SQLConnect:TSQLConnect;
+var    SQLBindCol:TSQLBindCol;
+var    SQLBindParameter:TSQLBindParameter;
+var    SQLBulkOperations:TSQLBulkOperations;
+var    SQLCloseCursor:TSQLCloseCursor;
 var    SQLDisconnect:TSQLDisconnect;
-var    SQLDriverConnect:TSQLDriverConnect;
-var    SQLExecDirect:TSQLExecDirect;
-var    SQLPrepare:TSQLPrepare;
-var    SQLCloseCursor:TSQLCloseCursor;
+var    SQLEndTran:TSQLEndTran;
 var    SQLExecute:TSQLExecute;
+var    SQLExtendedFetch:TSQLExtendedFetch;
 var    SQLFetch:TSQLFetch;
-var    SQLNumResultCols:TSQLNumResultCols;
-var    SQLDescribeCol:TSQLDescribeCol;
 var    SQLFetchScroll:TSQLFetchScroll;
-var    SQLExtendedFetch:TSQLExtendedFetch;
+var    SQLFreeHandle:tSQLFreeHandle;
+var    SQLFreeStmt:TSQLFreeStmt;
 var    SQLGetData:TSQLGetData;
-var    SQLSetStmtAttr:TSQLSetStmtAttr;
-var    SQLGetStmtAttr:TSQLGetStmtAttr;
-//var    SQLSetDescField:TSQLSetDescField;
+var    SQLNumResultCols:TSQLNumResultCols;
+var    SQLPutData:TSQLPutData;
+var    SQLRowCount:TSQLRowCount;
 var    SQLSetDescRec:TSQLSetDescRec;
-var    SQLBulkOperations:TSQLBulkOperations;
-var    SQLPutData:TSQLPutData;
-var    SQLBindCol:TSQLBindCol;
+var    SQLSetEnvAttr:tSQLSetEnvAttr;
 var    SQLSetPos:TSQLSetPos;
-var    SQLDataSources:TSQLDataSources;
-var    SQLDrivers:TSQLDrivers;
-var    SQLSetConnectAttr:TSQLSetConnectAttr;
-var    SQLGetCursorName:TSQLGetCursorName;
-var    SQLSetCursorName:TSQLSetCursorName;
-var    SQLRowCount:TSQLRowCount;
-var    SQLBindParameter:TSQLBindParameter;
-var    SQLFreeStmt:TSQLFreeStmt;
-var    SQLColAttribute:TSQLColAttribute;
-var    SQLEndTran:TSQLEndTran;
-var    SQLTables:TSQLTables;
-var    SQLPrimaryKeys:TSQLPrimaryKeys;
-var    SQLProcedureColumns : TSQLProcedureColumns;
-var    SQLStatistics: TSQLStatistics;
+
 var    odbcversion:word;
 
+//ansi unicode stubs
+
+function SQLColAttribute(StatementHandle:SQLHSTMT;
+                                                ColumnNumber:SQLUSMALLINT;  FieldIdentifier:SQLUSMALLINT;
+                                                CharacterAttribute:pchar;  BufferLength:SQLSMALLINT;
+                                                StringLength:PSQLSMALLINT;  NumericAttribute:SQLPOINTER
+                                                ):SQLRETURN;
+function SQLColumns(StatementHandle:SQLHSTMT;CatalogName:pchar;  NameLength1:SQLSMALLINT;
+                    SchemaName:pchar;  NameLength2:SQLSMALLINT;TableName:pchar;  NameLength3:SQLSMALLINT;
+                    ColumnName:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
+function SQLConnect(ConnectionHandle:SQLHDBC ;
+                                          ServerName:pchar;  NameLength1:SQLSMALLINT;
+                                          UserName:pchar;  NameLength2:SQLSMALLINT;
+                                          Authentication:pchar;  NameLength3:SQLSMALLINT):SQLRETURN;
+function SQLDataSources(EnvironmentHandle:SQLHENV;
+           Direction:SQLUSMALLINT;ServerName:pchar;
+           BufferLength1:SQLSMALLINT;NameLength1:PSQLSMALLINT;
+           Description:pchar;BufferLength2:SQLSMALLINT;
+           NameLength2:PSQLSMALLINT):SQLRETURN;
+function SQLDescribeCol(StatementHandle:SQLHSTMT; ColumnNumber:SQLUSMALLINT;
+                 ColumnName:pchar; BufferLength:SQLSMALLINT; var NameLength:SQLSMALLINT;
+                 var DataType:SQLSMALLINT; var ColumnSize:SQLULEN; var DecimalDigits:SQLSMALLINT;
+                 var Nullable:SQLSMALLINT):SQLRETURN;
+function SQLDriverConnect(ConnectionHandle:SQLHDBC;hWnd:SQLHWND;szConnStrIn:pchar;
+               nConnStrIn:SQLSMALLINT;szConnStrOut:pchar;cbConnStrOutMax:SQLSMALLINT;
+               var pnConnStrOut:SQLSMALLINT;nDriverCompletion:SQLUSMALLINT):SQLRETURN;
+function SQLDrivers(EnvironmentHandle:SQLHENV;
+           Direction:SQLUSMALLINT;DriverDescription:pchar;
+           BufferLength1:SQLSMALLINT;DescriptionLength1:PSQLSMALLINT;
+           DriverAttributes:pchar;BufferLength2:SQLSMALLINT;
+           AttributesLength2:PSQLSMALLINT):SQLRETURN;
+function SQLExecDirect(StatementHandle:SQLHSTMT; StatementText:pchar;  TextLength:SQLINTEGER):SQLRETURN;
+function SQLForeignKeys(StatementHandle:SQLHSTMT; PKCatalogName:pchar; NameLength1:SQLSMALLINT; PKSchemaName:pchar; NameLength2:SQLSMALLINT; PKTableName:pchar; NameLength3:SQLSMALLINT;
+                               FKCatalogName:pchar; NameLength4:SQLSMALLINT; FKSchemaName:pchar; NameLength5:SQLSMALLINT; FKTableName:pchar; NameLength6:SQLSMALLINT):SQLRETURN;
+function SQLGetConnectAttr(ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER; StringLength:SQLPOINTER):SQLRETURN;
+function SQLGetCursorName(StatementHandle:SQLHSTMT; CursorName:pchar; BufferLength:SQLSMALLINT;  NameLength:PSQLSMALLINT):SQLRETURN;
+function SQLGetDescField(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER; BufferLength:SQLINTEGER;  var StringLength:SQLINTEGER):SQLRETURN;
+function SQLGetDescRec(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; Name:pchar; BufferLength:SQLSMALLINT; var StringLength:SQLSMALLINT; var tType:SQLSMALLINT; var SubType:SQLSMALLINT; var Length:SQLLEN; var Precision:SQLSMALLINT; var Scale:SQLSMALLINT;  var Nullable:SQLSMALLINT):SQLRETURN;
+function SQLGetDiagField(HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; DiagIdentifier:SQLSMALLINT; DiagInfo:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;
+function SQLGetDiagRec(HandleType:SQLSMALLINT ; Handle:SQLHANDLE; RecNumber:SQLSMALLINT; Sqlstate:pchar; var NativeError:SQLINTEGER;  MessageText:pchar; BufferLength:SQLSMALLINT;  var TextLength:SQLSMALLINT):SQLRETURN;
+function SQLGetInfo(ConnectionHandle:SQLHDBC ; InfoType:SQLUSMALLINT; InfoValue:SQLPOINTER; BufferLength:SQLSMALLINT;  var StringLength:SQLSMALLINT):SQLRETURN;
+function SQLGetStmtAttr(StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER; BufferLength:SQLINTEGER;  StringLength:SQLPOINTER):SQLRETURN;
+function SQLNativeSql(StatementHandle:SQLHSTMT;InStatementText:pchar;TextLength1:SQLINTEGER;
+                                OutStatementText:pchar;BufferLength:SQLINTEGER;var TextLength2Ptr:SQLINTEGER):SQLRETURN;
+function SQLPrepare(StatementHandle:SQLHSTMT; StatementText:pchar;  TextLength:SQLINTEGER):SQLRETURN;
+function SQLPrimaryKeys(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
+              SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT):SQLRETURN;
+function SQLProcedureColumns(StatementHandle:SQLHSTMT;CatalogName:pchar;  NameLength1:SQLSMALLINT;
+                    SchemaName:pchar;  NameLength2:SQLSMALLINT;ProcName:pchar;  NameLength3:SQLSMALLINT;
+                    ColumnName:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
+function SQLProcedures(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
+              SchemaName:pchar; NameLength2:SQLSMALLINT; ProcName:pchar; NameLength3:SQLSMALLINT):SQLRETURN;
+function SQLSetConnectAttr(ConnectionHandle:SQLHDBC ; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;
+function SQLSetCursorName(StatementHandle:SQLHSTMT; CursorName:PSQLCHAR;  NameLength:SQLSMALLINT):SQLRETURN;
+function SQLSetDescField(DescriptorHandle:SQLHDESC; RecNumber:SQLSMALLINT; FieldIdentifier:SQLSMALLINT; Value:SQLPOINTER;  BufferLength:SQLINTEGER):SQLRETURN;
+function SQLSetStmtAttr(StatementHandle:SQLHSTMT; Attribute:SQLINTEGER; Value:SQLPOINTER;  StringLength:SQLINTEGER):SQLRETURN;
+function SQLSpecialColumns(StatementHandle:SQLHSTMT; IdentifierType:SQLUSMALLINT; CatalogName:pchar; NameLength1:SQLSMALLINT;
+              SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT;
+              Scope:SQLUSMALLINT;  Nullable:SQLUSMALLINT):SQLRETURN;
+function SQLStatistics(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT;
+             SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT;
+             Unique:SQLUSMALLINT;  Reserved:SQLUSMALLINT):SQLRETURN;
+function SQLTables(StatementHandle:SQLHSTMT; CatalogName:pchar; NameLength1:SQLSMALLINT; SchemaName:pchar; NameLength2:SQLSMALLINT; TableName:pchar; NameLength3:SQLSMALLINT; TableType:pchar;  NameLength4:SQLSMALLINT):SQLRETURN;
+
+
+
+
+
 {$else}
 
   function SQLAllocHandle(
@@ -1559,6 +1940,7 @@
 {$IFDEF DYNLOADINGODBC}
 
 var RefCount : integer;
+  IsUnicode:boolean;
 
 Procedure InitialiseODBC(OverrideName : string ='');
 
@@ -1580,50 +1962,88 @@
       end;
 
 {$ifdef fpc}
+//Unicode version
+    pointer(SQLColAttributeW) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttributeW');
+    pointer(SQLColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumnsW');
+    pointer(SQLConnectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnectW');
+    pointer(SQLDataSourcesW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSourcesW');
+    pointer(SQLDescribeColW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeColW');
+    pointer(SQLDriverConnectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnectW');
+    pointer(SQLDriversW) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriversW');
+    pointer(SQLExecDirectW) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirectW');
+    //pointer(SQLSetDescFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescFieldW');
+    pointer(SQLGetConnectAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetConnectAttrW');
+    pointer(SQLGetCursorNameW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorNameW');
+    pointer(SQLGetDescFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescFieldW');
+    pointer(SQLGetDescRecW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescRecW');
+    pointer(SQLGetDiagFieldW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagFieldW');
+    pointer(SQLGetDiagRecW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRecW');
+    pointer(SQLGetInfoW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfoW');
+    pointer(SQLGetStmtAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttrW');
+    pointer(SQLPrepareW) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepareW');
+    pointer(SQLPrimaryKeysW) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeysW');
+    pointer(SQLProcedureColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumnsW');
+    pointer(SQLProceduresW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProceduresW');
+    pointer(SQLProceduresW) := GetProcedureAddress(ODBCLibraryHandle,'SQLProceduresW');
+    pointer(SQLNativeSqlW) := GetProcedureAddress(ODBCLibraryHandle,'SQLNativeSqlW');
+    pointer(SQLSetConnectAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttrW');
+    pointer(SQLSetCursorNameW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorNameW');
+    pointer(SQLSetStmtAttrW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttrW');
+    pointer(SQLStatisticsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLStatisticsW');
+    pointer(SQLSpecialColumnsW) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumnsW');
+    pointer(SQLTablesW) := GetProcedureAddress(ODBCLibraryHandle,'SQLTablesW');
+
+    IsUnicode:=assigned(SQLDriverConnectW);
+
+//Ansi version
+    pointer(SQLColAttributeA) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttribute');
+    pointer(SQLColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumns');
+    pointer(SQLConnectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnect');
+    pointer(SQLDataSourcesA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSources');
+    pointer(SQLDescribeColA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeCol');
+    pointer(SQLDriverConnectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnect');
+    pointer(SQLDriversA) := GetProcedureAddress(ODBCLibraryHandle,'SQLDrivers');
+    pointer(SQLExecDirectA) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirect');
+    //pointer(SQLSetDescField) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescField');
+    pointer(SQLGetConnectAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetConnectAttr');
+    pointer(SQLGetCursorNameA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorName');
+    pointer(SQLGetDescFieldA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescField');
+    pointer(SQLGetDescRecA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDescRec');
+    pointer(SQLGetDiagFieldA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagField');
+    pointer(SQLGetDiagRecA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRec');
+    pointer(SQLGetInfoA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfo');
+    pointer(SQLGetStmtAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttr');
+    pointer(SQLPrepareA) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepare');
+    pointer(SQLPrimaryKeysA) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeys');
+    pointer(SQLProcedureColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumns');
+    pointer(SQLProceduresA) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedures');
+    pointer(SQLNativeSqlA) := GetProcedureAddress(ODBCLibraryHandle,'SQLNativeSql');
+    pointer(SQLSetConnectAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttr');
+    pointer(SQLSetCursorNameA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorName');
+    pointer(SQLSetStmtAttrA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttr');
+    pointer(SQLSpecialColumnsA) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumns');
+    pointer(SQLTablesA) := GetProcedureAddress(ODBCLibraryHandle,'SQLTables');
+// Common ansi unicode
     pointer(SQLAllocHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLAllocHandle');
-    pointer(SQLSetEnvAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
-    pointer(SQLFreeHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeHandle');
-    pointer(SQLGetInfo) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetInfo');
-    pointer(SQLProcedures) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedures');
-    pointer(SQLColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLColumns');
-    pointer(SQLSpecialColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLSpecialColumns');
-    pointer(SQLGetDiagRec) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagRec');
-    pointer(SQLGetDiagField) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetDiagField');
-    pointer(SQLConnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLConnect');
+    pointer(SQLBindCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindCol');
+    pointer(SQLBindParameter) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindParameter');
+    pointer(SQLBulkOperations) := GetProcedureAddress(ODBCLibraryHandle,'SQLBulkOperations');
+    pointer(SQLCloseCursor) := GetProcedureAddress(ODBCLibraryHandle,'SQLCloseCursor');
     pointer(SQLDisconnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLDisconnect');
-    pointer(SQLDriverConnect) := GetProcedureAddress(ODBCLibraryHandle,'SQLDriverConnect');
-    pointer(SQLExecDirect) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecDirect');
-    pointer(SQLPrepare) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrepare');
-    pointer(SQLCloseCursor) := GetProcedureAddress(ODBCLibraryHandle,'SQLCloseCursor');
+    pointer(SQLEndTran) := GetProcedureAddress(ODBCLibraryHandle,'SQLEndTran');
     pointer(SQLExecute) := GetProcedureAddress(ODBCLibraryHandle,'SQLExecute');
+    pointer(SQLExtendedFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLExtendedFetch');
     pointer(SQLFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetch');
-    pointer(SQLNumResultCols) := GetProcedureAddress(ODBCLibraryHandle,'SQLNumResultCols');
-    pointer(SQLDescribeCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLDescribeCol');
     pointer(SQLFetchScroll) := GetProcedureAddress(ODBCLibraryHandle,'SQLFetchScroll');
-    pointer(SQLExtendedFetch) := GetProcedureAddress(ODBCLibraryHandle,'SQLExtendedFetch');
+    pointer(SQLFreeHandle) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeHandle');
+    pointer(SQLFreeStmt) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeStmt');
     pointer(SQLGetData) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetData');
-    pointer(SQLSetStmtAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetStmtAttr');
-    pointer(SQLGetStmtAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetStmtAttr');
-    //pointer(SQLSetDescField) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescField');
+    pointer(SQLNumResultCols) := GetProcedureAddress(ODBCLibraryHandle,'SQLNumResultCols');
+    pointer(SQLPutData) := GetProcedureAddress(ODBCLibraryHandle,'SQLPutData');
+    pointer(SQLRowCount) := GetProcedureAddress(ODBCLibraryHandle,'SQLRowCount');
     pointer(SQLSetDescRec) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetDescRec');
-    pointer(SQLBulkOperations) := GetProcedureAddress(ODBCLibraryHandle,'SQLBulkOperations');
-    pointer(SQLPutData) := GetProcedureAddress(ODBCLibraryHandle,'SQLPutData');
-    pointer(SQLBindCol) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindCol');
+    pointer(SQLSetEnvAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
     pointer(SQLSetPos) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetPos');
-    pointer(SQLDataSources) := GetProcedureAddress(ODBCLibraryHandle,'SQLDataSources');
-    pointer(SQLDrivers) := GetProcedureAddress(ODBCLibraryHandle,'SQLDrivers');
-    pointer(SQLSetConnectAttr) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetConnectAttr');
-    pointer(SQLGetCursorName) := GetProcedureAddress(ODBCLibraryHandle,'SQLGetCursorName');
-    pointer(SQLSetCursorName) := GetProcedureAddress(ODBCLibraryHandle,'SQLSetCursorName');
-    pointer(SQLRowCount) := GetProcedureAddress(ODBCLibraryHandle,'SQLRowCount');
-    pointer(SQLBindParameter) := GetProcedureAddress(ODBCLibraryHandle,'SQLBindParameter');
-    pointer(SQLFreeStmt) := GetProcedureAddress(ODBCLibraryHandle,'SQLFreeStmt');
-    pointer(SQLColAttribute) := GetProcedureAddress(ODBCLibraryHandle,'SQLColAttribute');
-    pointer(SQLEndTran) := GetProcedureAddress(ODBCLibraryHandle,'SQLEndTran');
-    pointer(SQLTables) := GetProcedureAddress(ODBCLibraryHandle,'SQLTables');
-    pointer(SQLPrimaryKeys) := GetProcedureAddress(ODBCLibraryHandle,'SQLPrimaryKeys');
-    pointer(SQLProcedureColumns) := GetProcedureAddress(ODBCLibraryHandle,'SQLProcedureColumns');
-    pointer(SQLStatistics) := GetProcedureAddress(ODBCLibraryHandle,'SQLStatistics');
 {$else}
     SQLAllocHandle := GetProcedureAddress(ODBCLibraryHandle,'SQLAllocHandle');
     SQLSetEnvAttr := GetProcedureAddress(ODBCLibraryHandle,'SQLSetEnvAttr');
@@ -1687,6 +2107,662 @@
 
 {$ENDIF}
 
+{$ifdef DYNLOADINGODBC}
+
+function GetWidePtr(param:pchar; charlen:integer; var wparam:widestring):pwidechar;
+
+begin
+  if assigned(param) then
+    begin
+    setlength(wparam,charlen);
+    result:=@wparam[1];
+    end
+  else
+    result:=nil;
+end;
+
+procedure SetCharVal(wval:widestring;param:pchar; charlen:integer);
+begin
+  if assigned(param) then
+    begin
+    SetLength(wval,charlen);
+    StrPCopy(param,wval);
+    end;
+end;
+
+function SQLColAttribute(StatementHandle: SQLHSTMT; ColumnNumber: SQLUSMALLINT;
+  FieldIdentifier: SQLUSMALLINT; CharacterAttribute: pchar;
+  BufferLength: SQLSMALLINT; StringLength:PSQLSMALLINT;
+  NumericAttribute: SQLPOINTER): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CharacterAttribute;
+    result:=SQLColAttributeW(StatementHandle,ColumnNumber, FieldIdentifier, @wp1[1],
+      BufferLength,StringLength,NumericAttribute);
+    end
+  else
+    result:=SQLColAttributeA(StatementHandle,ColumnNumber, FieldIdentifier, CharacterAttribute,
+      BufferLength,StringLength,NumericAttribute)
+end;
+
+function SQLColumns(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  TableName: pchar; NameLength3: SQLSMALLINT; ColumnName: pchar;
+  NameLength4: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3,wp4:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=TableName;
+    wp3:=ColumnName;
+    result:=SQLColumnsW(StatementHandle,@wp1[1],length(wp1),@wp2[1],
+      length(wp2),@wp3[1],length(wp3),@wp4[1],length(wp4))
+    end
+  else
+    result:=SQLColumnsA(StatementHandle,CatalogName,NameLength1,SchemaName,
+      NameLength2,TableName,NameLength3,ColumnName,NameLength4)
+end;
+
+function SQLConnect(ConnectionHandle: SQLHDBC; ServerName: pchar;
+  NameLength1: SQLSMALLINT; UserName: pchar; NameLength2: SQLSMALLINT;
+  Authentication: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=ServerName;
+    wp2:=UserName;
+    wp3:=Authentication;
+    result:=SQLConnectW(ConnectionHandle,@wp1[1],length(wp1),
+      @wp2[1],length(wp2),@wp3[1],length(wp3))
+    end
+  else
+    result:=SQLConnectA(ConnectionHandle,ServerName,NameLength1,
+      UserName,NameLength2,Authentication,NameLength3)
+end;
+
+function SQLDataSources(EnvironmentHandle: SQLHENV; Direction: SQLUSMALLINT;
+  ServerName: pchar; BufferLength1: SQLSMALLINT; NameLength1: PSQLSMALLINT;
+  Description: pchar; BufferLength2: SQLSMALLINT; NameLength2: PSQLSMALLINT
+  ): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLDataSourcesW(EnvironmentHandle,Direction,
+      GetWidePtr(ServerName,BufferLength1,wp1),BufferLength1,NameLength1,
+      GetWidePtr(Description,BufferLength2,wp2),BufferLength2,NameLength2);
+    if result<>SQL_ERROR then
+      begin
+      SetCharVal(wp1,ServerName,NameLength1^);
+      SetCharVal(wp2,Description,NameLength2^);
+      end;
+    end
+  else
+    result:=SQLDataSourcesA(EnvironmentHandle,Direction,
+      ServerName,BufferLength1,NameLength1,
+      Description,BufferLength2,NameLength2)
+end;
+
+function SQLDescribeCol(StatementHandle: SQLHSTMT;
+  ColumnNumber: SQLUSMALLINT; ColumnName: pchar; BufferLength: SQLSMALLINT;
+  var NameLength: SQLSMALLINT; var DataType: SQLSMALLINT;
+  var ColumnSize: SQLULEN; var DecimalDigits: SQLSMALLINT;
+  var Nullable: SQLSMALLINT): SQLRETURN;
+var
+  wp1:widestring;
+  p1:pwidechar;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLDescribeColW(StatementHandle,ColumnNumber,GetWidePtr(ColumnName,BufferLength,wp1),BufferLength,
+      NameLength,DataType,ColumnSize,DecimalDigits,Nullable);
+    if result<>SQL_ERROR then
+      SetCharVal(wp1,ColumnName,NameLength);
+    end
+  else
+    result:=SQLDescribeColA(StatementHandle,ColumnNumber,ColumnName,BufferLength,
+      NameLength,DataType,ColumnSize,DecimalDigits,Nullable)
+end;
+
+function SQLDriverConnect(ConnectionHandle: SQLHDBC; hWnd: SQLHWND;
+  szConnStrIn: pchar; nConnStrIn: SQLSMALLINT; szConnStrOut: pchar;
+  cbConnStrOutMax: SQLSMALLINT; var pnConnStrOut: SQLSMALLINT;
+  nDriverCompletion: SQLUSMALLINT): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=szConnStrIn;
+    result:=SQLDriverConnectW(ConnectionHandle,hWnd,
+      @wp1[1],length(wp1), GetWidePtr(szConnStrOut,cbConnStrOutMax,wp2), cbConnStrOutMax,pnConnStrOut,
+      nDriverCompletion);
+    if result<>SQL_ERROR then
+      SetCharVal(wp2,szConnStrOut,pnConnStrOut);
+    end
+  else
+    result:=SQLDriverConnectA(ConnectionHandle,hWnd,
+      szConnStrIn, nConnStrIn, szConnStrOut, cbConnStrOutMax,pnConnStrOut,
+      nDriverCompletion)
+end;
+
+function SQLDrivers(EnvironmentHandle: SQLHENV; Direction: SQLUSMALLINT;
+  DriverDescription: pchar; BufferLength1: SQLSMALLINT;
+  DescriptionLength1: PSQLSMALLINT; DriverAttributes: pchar;
+  BufferLength2: SQLSMALLINT; AttributesLength2: PSQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLDriversW(EnvironmentHandle, Direction,
+      GetWidePtr(DriverDescription,BufferLength1,wp1), BufferLength1,
+      DescriptionLength1, GetWidePtr(DriverAttributes,BufferLength2,wp2),
+      BufferLength2, AttributesLength2);
+    if result<>SQL_ERROR then
+      begin
+      SetCharVal(wp1,DriverDescription,DescriptionLength1^);
+      SetCharVal(wp2,DriverAttributes,AttributesLength2^);
+      end;
+    end
+  else
+    result:=SQLDrivers(EnvironmentHandle, Direction,
+      DriverDescription, BufferLength1,
+      DescriptionLength1, DriverAttributes,
+      BufferLength2, AttributesLength2)
+end;
+
+function SQLExecDirect(StatementHandle: SQLHSTMT; StatementText: pchar;
+  TextLength: SQLINTEGER): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=StatementText;
+    result:=SQLExecDirectW(StatementHandle,@wp1[1],length(wp1))
+    end
+  else
+    result:=SQLExecDirectA(StatementHandle,StatementText,TextLength)
+end;
+
+function SQLForeignKeys(StatementHandle: SQLHSTMT; PKCatalogName: pchar;
+  NameLength1: SQLSMALLINT; PKSchemaName: pchar; NameLength2: SQLSMALLINT;
+  PKTableName: pchar; NameLength3: SQLSMALLINT; FKCatalogName: pchar;
+  NameLength4: SQLSMALLINT; FKSchemaName: pchar; NameLength5: SQLSMALLINT;
+  FKTableName: pchar; NameLength6: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3,wp4,wp5,wp6:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=PKCatalogName;
+    wp2:=PKSchemaName;
+    wp3:=PKTableName;
+    wp4:=FKCatalogName;
+    wp5:=FKSchemaName;
+    wp6:=FKTableName;
+    result:=SQLForeignKeysW(StatementHandle,@wp1[1],length(wp1),
+      @wp2[1],length(wp2),@wp3[1],length(wp3),
+      @wp4[1],length(wp4),@wp5[1],length(wp5),
+      @wp6[1],length(wp6))
+    end
+  else
+    result:=SQLForeignKeysA(StatementHandle,PKCatalogName,NameLength1,
+      PKSchemaName,NameLength2,PKTableName,NameLength3,
+      FKCatalogName,NameLength4,FKSchemaName,NameLength5,
+      FKTableName,NameLength6)
+end;
+
+function SQLGetConnectAttr(ConnectionHandle: SQLHDBC; Attribute: SQLINTEGER;
+  Value: SQLPOINTER; BufferLength: SQLINTEGER; StringLength: SQLPOINTER
+  ): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    if (Attribute in [SQL_ATTR_CURRENT_CATALOG,SQL_ATTR_TRACEFILE,SQL_ATTR_TRANSLATE_LIB])
+      and assigned(Value) then
+      begin
+      setlength(wp1,BufferLength div sizeof(widechar));
+      result:=SQLGetConnectAttrW(ConnectionHandle,Attribute,
+        GetWidePtr(Value,BufferLength div sizeof(widechar),wp1), BufferLength, StringLength);
+      if result<>SQL_ERROR then
+        begin
+        SetCharVal(wp1,Value,PSQLINTEGER(StringLength)^ div sizeof(widechar));
+        PSQLINTEGER(StringLength)^:=length(pchar(Value));
+        end;
+      end
+    else
+      result:=SQLGetConnectAttrW(ConnectionHandle,Attribute,
+        Value, BufferLength, StringLength)
+    end
+  else
+    result:=SQLGetConnectAttrA(ConnectionHandle,Attribute,
+      Value, BufferLength, StringLength)
+end;
+
+function SQLGetCursorName(StatementHandle: SQLHSTMT; CursorName: pchar;
+  BufferLength: SQLSMALLINT; NameLength: PSQLSMALLINT): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLGetCursorNameW(StatementHandle,GetWidePtr(CursorName,BufferLength,wp1),
+      BufferLength, NameLength);
+    if result<>SQL_ERROR then
+      SetCharVal(wp1,CursorName,NameLength^);
+    end
+  else
+    result:=SQLGetCursorNameA(StatementHandle,CursorName,BufferLength, NameLength)
+end;
+
+function SQLGetDescField(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
+  FieldIdentifier: SQLSMALLINT; Value: SQLPOINTER; BufferLength: SQLINTEGER;
+  var StringLength: SQLINTEGER): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    if (FieldIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
+        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
+        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
+       assigned(Value) then
+      begin
+      result:=SQLGetDescFieldW(DescriptorHandle,RecNumber,
+        FieldIdentifier,GetWidePtr(Value,BufferLength div sizeof(widechar),wp1),BufferLength,StringLength);
+      if result<>SQL_ERROR then
+        begin
+        SetCharVal(wp1,Value,StringLength);
+        StringLength:=length(pchar(Value));
+        end;
+      end
+    else
+      result:=SQLGetDescFieldW(DescriptorHandle,RecNumber,
+        FieldIdentifier,Value,BufferLength,StringLength);
+    end
+  else
+    result:=SQLGetDescFieldA(DescriptorHandle,RecNumber,
+      FieldIdentifier,Value,BufferLength,StringLength)
+end;
+
+function SQLGetDescRec(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
+  Name: pchar; BufferLength: SQLSMALLINT; var StringLength: SQLSMALLINT;
+  var tType: SQLSMALLINT; var SubType: SQLSMALLINT; var Length: SQLLEN;
+  var Precision: SQLSMALLINT; var Scale: SQLSMALLINT; var Nullable: SQLSMALLINT
+  ): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLGetDescRecW(DescriptorHandle,RecNumber,
+      GetWidePtr(Name,BufferLength,wp1),BufferLength,StringLength,tType,SubType,Length,
+      Precision,Scale,Nullable);
+    if result<>SQL_ERROR then
+      SetCharVal(wp1,Name,StringLength);
+    end
+  else
+    result:=SQLGetDescRecA(DescriptorHandle,RecNumber,
+      Name,BufferLength,StringLength,tType,SubType,Length,
+      Precision,Scale,Nullable)
+end;
+
+function SQLGetDiagField(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
+  RecNumber: SQLSMALLINT; DiagIdentifier: SQLSMALLINT; DiagInfo: SQLPOINTER;
+  BufferLength: SQLSMALLINT; var StringLength: SQLSMALLINT): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    if (DiagIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
+        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
+        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
+       assigned(DiagInfo) then
+      begin
+      result:=SQLGetDiagFieldW(HandleType, Handle,RecNumber, DiagIdentifier,
+        GetWidePtr(DiagInfo,BufferLength,wp1),BufferLength,StringLength);
+      if result<>SQL_ERROR then
+        begin
+        SetCharVal(wp1,DiagInfo,StringLength div sizeof(widechar));
+        StringLength:=length(pchar(DiagInfo));
+        end;
+      end
+    else
+      result:=SQLGetDiagFieldW(HandleType,Handle,RecNumber, DiagIdentifier, DiagInfo,
+        BufferLength,StringLength);
+    end
+  else
+    result:=SQLGetDiagFieldA(HandleType,Handle,RecNumber, DiagIdentifier, DiagInfo,
+      BufferLength,StringLength)
+end;
+
+function SQLGetDiagRec(HandleType: SQLSMALLINT; Handle: SQLHANDLE;
+  RecNumber: SQLSMALLINT; Sqlstate: pchar; var NativeError: SQLINTEGER;
+  MessageText: pchar; BufferLength: SQLSMALLINT; var TextLength: SQLSMALLINT
+  ): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLGetDiagRecW(HandleType,Handle,RecNumber,GetWidePtr(Sqlstate,5,wp1),NativeError,
+       GetWidePtr(MessageText,BufferLength,wp2),BufferLength,TextLength);
+    if result<>SQL_ERROR then
+      begin
+      SetCharVal(wp1,Sqlstate,5);
+      SetCharVal(wp2,MessageText,TextLength);
+      end;
+    end
+  else
+    result:=SQLGetDiagRecA(HandleType,Handle,RecNumber,Sqlstate,NativeError,
+       MessageText,BufferLength,TextLength)
+end;
+
+function SQLGetInfo(ConnectionHandle: SQLHDBC; InfoType: SQLUSMALLINT;
+  InfoValue: SQLPOINTER; BufferLength: SQLSMALLINT;
+  var StringLength: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    case InfoType of
+      SQL_CATALOG_NAME,SQL_CATALOG_NAME_SEPARATOR,
+      SQL_CATALOG_TERM,SQL_SCHEMA_TERM,SQL_COLLATION_SEQ,
+      SQL_COLUMN_ALIAS,
+      SQL_DATA_SOURCE_NAME,SQL_DATA_SOURCE_READ_ONLY,SQL_DATABASE_NAME,SQL_DBMS_NAME,SQL_DBMS_VER,
+      SQL_DESCRIBE_PARAMETER,SQL_DRIVER_NAME,SQL_DRIVER_ODBC_VER,SQL_DRIVER_VER,
+      SQL_EXPRESSIONS_IN_ORDERBY,SQL_IDENTIFIER_QUOTE_CHAR,SQL_INTEGRITY,SQL_KEYWORDS,
+      SQL_LIKE_ESCAPE_CLAUSE,SQL_MAX_ROW_SIZE_INCLUDES_LONG,SQL_MULT_RESULT_SETS,
+      SQL_MULTIPLE_ACTIVE_TXN,SQL_NEED_LONG_DATA_LEN,SQL_ORDER_BY_COLUMNS_IN_SELECT,
+      SQL_PROCEDURE_TERM,SQL_PROCEDURES,SQL_ROW_UPDATES,SQL_SEARCH_PATTERN_ESCAPE,
+      SQL_SERVER_NAME,SQL_SPECIAL_CHARACTERS,SQL_TABLE_TERM,SQL_USER_NAME,SQL_XOPEN_CLI_YEAR,
+      SQL_ACCESSIBLE_PROCEDURES, SQL_ACCESSIBLE_TABLES,SQL_OUTER_JOINS:
+            begin
+            result:=SQLGetInfoW(ConnectionHandle,InfoType,
+              GetWidePtr(InfoValue,BufferLength div sizeof(widechar),wp1),
+              BufferLength,StringLength);
+            if result<>SQL_ERROR then
+              begin
+              SetCharVal(wp1,InfoValue,StringLength div sizeof(widechar));
+              StringLength:=length(pchar(InfoValue));
+              end;
+            end
+    else
+      result:=SQLGetInfoW(ConnectionHandle,InfoType,InfoValue,BufferLength,StringLength);
+    end
+  else
+    result:=SQLGetInfoA(ConnectionHandle,InfoType,InfoValue,BufferLength,StringLength)
+end;
+
+function SQLGetStmtAttr(StatementHandle: SQLHSTMT; Attribute: SQLINTEGER;
+  Value: SQLPOINTER; BufferLength: SQLINTEGER; StringLength: SQLPOINTER
+  ): SQLRETURN;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLGetStmtAttrW(StatementHandle,Attribute,
+      Value,BufferLength,StringLength);
+    end
+  else
+    result:=SQLGetStmtAttrA(StatementHandle,Attribute,
+      Value,BufferLength,StringLength)
+end;
+
+
+function SQLNativeSql(StatementHandle: SQLHSTMT; InStatementText: pchar;
+  TextLength1: SQLINTEGER; OutStatementText: pchar; BufferLength: SQLINTEGER;
+  var TextLength2Ptr: SQLINTEGER): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=InStatementText;
+    result:=SQLNativeSqlW(StatementHandle,@wp1[1],length(wp1),
+      GetWidePtr(OutStatementText,BufferLength,wp2),BufferLength,TextLength2Ptr);
+    if result<>SQL_ERROR then
+      SetCharVal(wp2,OutStatementText,TextLength2Ptr);
+    end
+  else
+    result:=SQLNativeSqlA(StatementHandle,InStatementText,TextLength1,
+      OutStatementText,BufferLength,TextLength2Ptr)
+end;
+
+function SQLPrepare(StatementHandle: SQLHSTMT; StatementText: pchar;
+  TextLength: SQLINTEGER): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=StatementText;
+    result:=SQLPrepareW(StatementHandle, @wp1[1],length(wp1));
+    end
+  else
+    result:=SQLPrepareA(StatementHandle, StatementText,TextLength)
+end;
+
+function SQLPrimaryKeys(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  TableName: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=TableName;
+    result:=SQLPrimaryKeysW(StatementHandle,@wp1[1],length(wp1),
+      @wp2[1],length(wp2),@wp3[1],length(wp3));
+    end
+  else
+    result:=SQLPrimaryKeysA(StatementHandle,CatalogName,
+      NameLength1,SchemaName, NameLength2,TableName, NameLength3)
+end;
+
+function SQLProcedureColumns(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  ProcName: pchar; NameLength3: SQLSMALLINT; ColumnName: pchar;
+  NameLength4: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3,wp4:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=ProcName;
+    wp4:=ColumnName;
+    result:=SQLProcedureColumnsW(StatementHandle,@wp1[1],length(wp1),
+      @wp2[1],length(wp2),@wp3[1],length(wp3),@wp4[1],length(wp4));
+    end
+  else
+    result:=SQLProcedureColumnsA(StatementHandle,CatalogName,
+      NameLength1, SchemaName,NameLength2,ProcName,NameLength3,
+      ColumnName,NameLength4)
+end;
+
+function SQLProcedures(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  ProcName: pchar; NameLength3: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=ProcName;
+    result:=SQLPrimaryKeysW(StatementHandle,@wp1[1],length(wp1),
+      @wp2[1],length(wp2),@wp3[1],length(wp3));
+    end
+  else
+    result:=SQLProcedures(StatementHandle,CatalogName,
+      NameLength1,SchemaName,NameLength2,ProcName,NameLength3)
+end;
+
+function SQLSetConnectAttr(ConnectionHandle: SQLHDBC; Attribute: SQLINTEGER;
+  Value: SQLPOINTER; StringLength: SQLINTEGER): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    if (Attribute in [SQL_ATTR_CURRENT_CATALOG,SQL_ATTR_TRACEFILE,SQL_ATTR_TRANSLATE_LIB])
+      and assigned(Value) then
+      begin
+      wp1:=pchar(Value);
+      result:=SQLSetConnectAttrW(ConnectionHandle,Attribute,
+        @wp1[1],length(wp1)*sizeof(widechar));
+      end
+    else
+      result:=SQLSetConnectAttrW(ConnectionHandle,Attribute,
+        Value, StringLength)
+    end
+  else
+    result:=SQLSetConnectAttrA(ConnectionHandle,Attribute,
+      Value, StringLength)
+end;
+
+function SQLSetCursorName(StatementHandle: SQLHSTMT; CursorName: PSQLCHAR;
+  NameLength: SQLSMALLINT): SQLRETURN;
+var
+  wp1:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CursorName;
+    result:=SQLSetCursorNameW(StatementHandle,@wp1[1],length(wp1));
+    end
+  else
+    result:=SQLSetCursorNameA(StatementHandle,CursorName,NameLength)
+end;
+
+function SQLSetDescField(DescriptorHandle: SQLHDESC; RecNumber: SQLSMALLINT;
+  FieldIdentifier: SQLSMALLINT; Value: SQLPOINTER; BufferLength: SQLINTEGER
+  ): SQLRETURN;
+var
+  wp1,wp2:widestring;
+begin
+  if IsUnicode then
+    begin
+    if (FieldIdentifier in [SQL_DIAG_DYNAMIC_FUNCTION,SQL_DIAG_CLASS_ORIGIN,
+        SQL_DIAG_SUBCLASS_ORIGIN,SQL_DIAG_CONNECTION_NAME,
+        SQL_DIAG_MESSAGE_TEXT,SQL_DIAG_SERVER_NAME,SQL_DIAG_SQLSTATE]) and
+       assigned(Value) then
+      begin
+      wp1:=pchar(Value);
+      result:=SQLSetDescField(DescriptorHandle,RecNumber,
+        FieldIdentifier,@wp1[1],length(wp1)*sizeof(widechar));
+      end
+    else
+      result:=SQLSetDescFieldW(DescriptorHandle,RecNumber,
+        FieldIdentifier,Value,BufferLength);
+    end
+  else
+    result:=SQLSetDescFieldA(DescriptorHandle,RecNumber,
+      FieldIdentifier,Value,BufferLength)
+end;
+
+function SQLSetStmtAttr(StatementHandle: SQLHSTMT; Attribute: SQLINTEGER;
+  Value: SQLPOINTER; StringLength: SQLINTEGER): SQLRETURN;
+begin
+  if IsUnicode then
+    begin
+    result:=SQLSetStmtAttrW(StatementHandle,Attribute,
+      Value,StringLength);
+    end
+  else
+    result:=SQLSetStmtAttrA(StatementHandle,Attribute,
+      Value,StringLength)
+end;
+
+function SQLSpecialColumns(StatementHandle: SQLHSTMT;
+  IdentifierType: SQLUSMALLINT; CatalogName: pchar; NameLength1: SQLSMALLINT;
+  SchemaName: pchar; NameLength2: SQLSMALLINT; TableName: pchar;
+  NameLength3: SQLSMALLINT; Scope: SQLUSMALLINT; Nullable: SQLUSMALLINT
+  ): SQLRETURN;
+var
+  wp1,wp2,wp3:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=TableName;
+    result:=SQLSpecialColumnsW(StatementHandle,IdentifierType,
+      @wp1[1],length(wp1),@wp2[1],length(wp2),
+      @wp3[1],length(wp3), Scope, Nullable)
+    end
+  else
+    result:=SQLSpecialColumnsA(StatementHandle,IdentifierType,
+      CatalogName,NameLength1,SchemaName, NameLength2,
+      TableName,NameLength3, Scope, Nullable)
+end;
+
+function SQLStatistics(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  TableName: pchar; NameLength3: SQLSMALLINT; Unique: SQLUSMALLINT;
+  Reserved: SQLUSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=TableName;
+    result:=SQLStatisticsW(StatementHandle,
+      @wp1[1],length(wp1),@wp2[1],length(wp2),
+      @wp3[1],length(wp3), Unique,Reserved)
+    end
+  else
+    result:=SQLStatisticsA(StatementHandle,CatalogName,
+      NameLength1,SchemaName,NameLength2,
+      TableName,NameLength3,Unique,Reserved)
+end;
+
+function SQLTables(StatementHandle: SQLHSTMT; CatalogName: pchar;
+  NameLength1: SQLSMALLINT; SchemaName: pchar; NameLength2: SQLSMALLINT;
+  TableName: pchar; NameLength3: SQLSMALLINT; TableType: pchar;
+  NameLength4: SQLSMALLINT): SQLRETURN;
+var
+  wp1,wp2,wp3,wp4:widestring;
+begin
+  if IsUnicode then
+    begin
+    wp1:=CatalogName;
+    wp2:=SchemaName;
+    wp3:=TableName;
+    wp4:=TableType;
+    result:=SQLTablesW(StatementHandle,
+      @wp1[1],length(wp1),@wp2[1],length(wp2),
+      @wp3[1],length(wp3),@wp4[1],length(wp4))
+    end
+  else
+    result:=SQLTablesA(StatementHandle,CatalogName,
+      NameLength1,SchemaName,NameLength2,
+      TableName,NameLength3,TableType,NameLength4)
+end;
+
+{$endif DYNLOADINGODBC}
+
+
 function DateStructToDateTime( b:PSQL_DATE_STRUCT):TDateTime;
 begin
   Result:=EncodeDate( b^.Year, b^.Month, b^.Day);
odbc.inc.diff (63,006 bytes)

Marco van de Voort

2013-08-11 14:58

manager   ~0069335

Last edited: 2013-08-11 15:17

View 2 revisions

I looked at the patch, and except for style issue (Contains hardtabs and repeated var and type keywords) the sqlgetinfo pointer -> var change might unnecessary break things. Some properties seem also have to slipped from under odbcv3 define, don't know if that is accident or intentional.

For the rest, I assume it can be committed.

LacaK

2013-08-13 10:20

developer   ~0069357

IMHO we does not need complicate header file and do conversions between ANSI and WIDE on "our" side (in header file).
According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms716540(v=vs.85).aspx

AFAIU odbc driver manager itself internaly performs conversion of string arguments between ANSI and Unicode
(depending on which version of API function is called "A" or "W" and if driver is unicode or ansi)

So IMHO it is sufficient add to header file "W" versions of API functions and if needed use these (for example in sqlDB/TODBCConnection)
Because odbc driver manager is unicode enabled internally, we can (always) use these "W" versions and let odbc driver manager perform conversion if needed.

But also in current implementation there are ODBC drivers (f.e. MS SQL, PostgreSQL Unicode, MySQL) which returns (some) character column data as SQL_W[VAR]CHAR which are mapped to ftWideString (or ftFixedWideChar). So I suppose that here does not occurs "character loss".

Jkey

2016-08-10 10:15

reporter   ~0094072

The fact is, that this patch does work, and I managed to get utf8 characters from an MS Access database on Win32, using FPC 3.0.0 (modified odbcsql.inc) and ODBC connection, without any further additional conversions because it calls the "W" functions directly.
What is the right method to get the same utf8 characters with current odbcsql.inc? I did read the link, and understood that ansi-utf8 conversions should be done automatically according to it, however, my experience is that I receive only ansi encoded strings without this patch.

LacaK

2019-08-12 14:32

developer   ~0117652

Last edited: 2019-08-17 12:49

View 2 revisions

I am resolving as I can not reproduce. Please feel free to reopen and attach more details about RDBMS.
For example in my case MS SQL Server returns for nchar/nvarchar columns SQL_WCHAR/SQL_WVARCHAR (so I do not need to call Wide API). Probably other drivers may behave differently.
As far as Ansi API is used TODBCConnection.CharSet must be set properly! So in case of Windows you must set your Ansi encoding (Windows-1250 for exampe).

Some RDBMS provides Ansi and Unicode versions of ODBC drivers (MySQL, PostgreSQL) and many provides "CharSet" connection settings (MySQL, PostgreSQL, Firebird).
So you can specify in ODBC DSN configuration (or directly in connection string) "CharSet=UTF-8" which in conjuction with "A"nsi ODBC API allows to read/write data without conversion between database (if database has UTF-8 encoding) and TField buffer. So in this case there is no need to call "W"ide ODBC API to get correct results as "A"nsi provide conversion-less straightforward solution.
Some drivers also provide additional options to specify how UNICODE data are mapped (Devart ODBC Driver for Firebird and PostgreSQL has "String Types" which tells if SQL_CHAR or SQL_WCHAR is returned so you can force WideStrings).

Issue History

Date Modified Username Field Change
2012-05-21 17:11 Ludo Brands New Issue
2012-05-21 17:11 Ludo Brands Status new => assigned
2012-05-21 17:11 Ludo Brands Assigned To => Joost van der Sluis
2012-05-21 17:11 Ludo Brands File Added: odbc.inc.diff
2013-07-16 10:43 Reinier Olislagers Relationship added related to 0012206
2013-08-11 14:58 Marco van de Voort Note Added: 0069335
2013-08-11 15:17 Marco van de Voort Note Edited: 0069335 View Revisions
2013-08-13 10:20 LacaK Note Added: 0069357
2014-03-10 11:01 Reinier Olislagers Tag Attached: odbc
2014-03-10 11:01 Reinier Olislagers Tag Attached: unicode
2014-03-10 11:01 Reinier Olislagers Tag Attached: unicodestring
2014-03-10 11:01 Reinier Olislagers Tag Attached: widestring
2016-08-10 10:15 Jkey Note Added: 0094072
2016-08-10 12:45 LacaK Assigned To Joost van der Sluis => LacaK
2019-08-12 14:32 LacaK Status assigned => resolved
2019-08-12 14:32 LacaK Resolution open => unable to reproduce
2019-08-12 14:32 LacaK FPCTarget => -
2019-08-12 14:32 LacaK Note Added: 0117652
2019-08-17 12:35 LacaK Status resolved => feedback
2019-08-17 12:35 LacaK Resolution unable to reproduce => reopened
2019-08-17 12:49 LacaK Note Edited: 0117652 View Revisions
2019-08-17 12:52 LacaK Status feedback => resolved
2019-08-17 12:52 LacaK Resolution reopened => unable to reproduce