proxyodbc.c 125 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2
/*
 * Win32 ODBC functions
3
 *
4
 * Copyright 1999 Xiang Li, Corel Corporation
Alexandre Julliard's avatar
Alexandre Julliard committed
5
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25
 *
 * NOTES:
 *   Proxy ODBC driver manager.  This manager delegates all ODBC 
 *   calls to a real ODBC driver manager named by the environment 
 *   variable LIB_ODBC_DRIVER_MANAGER, or to libodbc.so if the
 *   variable is not set.
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27
 */

28
#include "config.h"
29 30
#include "wine/port.h"

31
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
32 33 34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
35
#include <assert.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
36

37
#include "windef.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
38
#include "winbase.h"
39
#include "winreg.h"
40
#include "wine/debug.h"
41
#include "wine/unicode.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
42 43 44 45 46

#include "sql.h"
#include "sqltypes.h"
#include "sqlext.h"

47 48 49
static BOOL ODBC_LoadDriverManager(void);
static BOOL ODBC_LoadDMFunctions(void);

50
WINE_DEFAULT_DEBUG_CHANNEL(odbc);
51
WINE_DECLARE_DEBUG_CHANNEL(winediag);
Alexandre Julliard's avatar
Alexandre Julliard committed
52

53 54 55 56 57
static SQLRETURN (*pSQLAllocConnect)(SQLHENV,SQLHDBC*);
static SQLRETURN (*pSQLAllocEnv)(SQLHENV*);
static SQLRETURN (*pSQLAllocHandle)(SQLSMALLINT,SQLHANDLE,SQLHANDLE*);
static SQLRETURN (*pSQLAllocHandleStd)(SQLSMALLINT,SQLHANDLE,SQLHANDLE*);
static SQLRETURN (*pSQLAllocStmt)(SQLHDBC,SQLHSTMT*);
58 59 60
static SQLRETURN (*pSQLBindCol)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLPOINTER,SQLLEN,SQLLEN*);
static SQLRETURN (*pSQLBindParam)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLSMALLINT,SQLULEN,SQLSMALLINT,SQLPOINTER,SQLLEN*);
static SQLRETURN (*pSQLBindParameter)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLSMALLINT,SQLSMALLINT,SQLULEN,SQLSMALLINT,SQLPOINTER,SQLLEN,SQLLEN*);
61 62 63 64 65
static SQLRETURN (*pSQLBrowseConnect)(SQLHDBC,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLBrowseConnectW)(SQLHDBC,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLBulkOperations)(SQLHSTMT,SQLSMALLINT);
static SQLRETURN (*pSQLCancel)(SQLHSTMT);
static SQLRETURN (*pSQLCloseCursor)(SQLHSTMT);
66 67 68 69
static SQLRETURN (*pSQLColAttribute)(SQLHSTMT,SQLUSMALLINT,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*,SQLLEN*);
static SQLRETURN (*pSQLColAttributeW)(SQLHSTMT,SQLUSMALLINT,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*,SQLLEN*);
static SQLRETURN (*pSQLColAttributes)(SQLHSTMT,SQLUSMALLINT,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*,SQLLEN*);
static SQLRETURN (*pSQLColAttributesW)(SQLHSTMT,SQLUSMALLINT,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*,SQLLEN*);
70 71 72 73 74 75 76 77
static SQLRETURN (*pSQLColumnPrivileges)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLColumnPrivilegesW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLColumns)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLColumnsW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLConnect)(SQLHDBC,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLConnectW)(SQLHDBC,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLCopyDesc)(SQLHDESC,SQLHDESC);
static SQLRETURN (*pSQLDataSources)(SQLHENV,SQLUSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
78
static SQLRETURN (*pSQLDataSourcesA)(SQLHENV,SQLUSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
79
static SQLRETURN (*pSQLDataSourcesW)(SQLHENV,SQLUSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
80
static SQLRETURN (*pSQLDescribeCol)(SQLHSTMT,SQLUSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLSMALLINT*,SQLULEN*,SQLSMALLINT*,SQLSMALLINT*);
81
static SQLRETURN (*pSQLDescribeColW)(SQLHSTMT,SQLUSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLSMALLINT*,SQLULEN*,SQLSMALLINT*,SQLSMALLINT*);
82
static SQLRETURN (*pSQLDescribeParam)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT*,SQLULEN*,SQLSMALLINT*,SQLSMALLINT*);
83 84 85 86 87 88 89 90 91 92 93
static SQLRETURN (*pSQLDisconnect)(SQLHDBC);
static SQLRETURN (*pSQLDriverConnect)(SQLHDBC,SQLHWND,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLUSMALLINT);
static SQLRETURN (*pSQLDriverConnectW)(SQLHDBC,SQLHWND,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLUSMALLINT);
static SQLRETURN (*pSQLDrivers)(SQLHENV,SQLUSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLDriversW)(SQLHENV,SQLUSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLEndTran)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT);
static SQLRETURN (*pSQLError)(SQLHENV,SQLHDBC,SQLHSTMT,SQLCHAR*,SQLINTEGER*,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLErrorW)(SQLHENV,SQLHDBC,SQLHSTMT,SQLWCHAR*,SQLINTEGER*,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLExecDirect)(SQLHSTMT,SQLCHAR*,SQLINTEGER);
static SQLRETURN (*pSQLExecDirectW)(SQLHSTMT,SQLWCHAR*,SQLINTEGER);
static SQLRETURN (*pSQLExecute)(SQLHSTMT);
94
static SQLRETURN (*pSQLExtendedFetch)(SQLHSTMT,SQLUSMALLINT,SQLLEN,SQLULEN*,SQLUSMALLINT*);
95
static SQLRETURN (*pSQLFetch)(SQLHSTMT);
96
static SQLRETURN (*pSQLFetchScroll)(SQLHSTMT,SQLSMALLINT,SQLLEN);
97 98 99 100 101 102 103 104 105 106 107 108
static SQLRETURN (*pSQLForeignKeys)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLForeignKeysW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLFreeConnect)(SQLHDBC);
static SQLRETURN (*pSQLFreeEnv)(SQLHENV);
static SQLRETURN (*pSQLFreeHandle)(SQLSMALLINT,SQLHANDLE);
static SQLRETURN (*pSQLFreeStmt)(SQLHSTMT,SQLUSMALLINT);
static SQLRETURN (*pSQLGetConnectAttr)(SQLHDBC,SQLINTEGER,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetConnectAttrW)(SQLHDBC,SQLINTEGER,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetConnectOption)(SQLHDBC,SQLUSMALLINT,SQLPOINTER);
static SQLRETURN (*pSQLGetConnectOptionW)(SQLHDBC,SQLUSMALLINT,SQLPOINTER);
static SQLRETURN (*pSQLGetCursorName)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetCursorNameW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
109
static SQLRETURN (*pSQLGetData)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLPOINTER,SQLLEN,SQLLEN*);
110 111
static SQLRETURN (*pSQLGetDescField)(SQLHDESC,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetDescFieldW)(SQLHDESC,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
112
static SQLRETURN (*pSQLGetDescRec)(SQLHDESC,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLSMALLINT*,SQLSMALLINT*,SQLLEN*,SQLSMALLINT*,SQLSMALLINT*,SQLSMALLINT*);
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
static SQLRETURN (*pSQLGetDescRecW)(SQLHDESC,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*,SQLSMALLINT*,SQLSMALLINT*,SQLLEN*,SQLSMALLINT*,SQLSMALLINT*,SQLSMALLINT*);
static SQLRETURN (*pSQLGetDiagField)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetDiagFieldW)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetDiagRec)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT,SQLCHAR*,SQLINTEGER*,SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetDiagRecW)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT,SQLWCHAR*,SQLINTEGER*,SQLWCHAR*,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetEnvAttr)(SQLHENV,SQLINTEGER,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetFunctions)(SQLHDBC,SQLUSMALLINT,SQLUSMALLINT*);
static SQLRETURN (*pSQLGetInfo)(SQLHDBC,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetInfoW)(SQLHDBC,SQLUSMALLINT,SQLPOINTER,SQLSMALLINT,SQLSMALLINT*);
static SQLRETURN (*pSQLGetStmtAttr)(SQLHSTMT,SQLINTEGER,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetStmtAttrW)(SQLHSTMT,SQLINTEGER,SQLPOINTER,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLGetStmtOption)(SQLHSTMT,SQLUSMALLINT,SQLPOINTER);
static SQLRETURN (*pSQLGetTypeInfo)(SQLHSTMT,SQLSMALLINT);
static SQLRETURN (*pSQLGetTypeInfoW)(SQLHSTMT,SQLSMALLINT);
static SQLRETURN (*pSQLMoreResults)(SQLHSTMT);
static SQLRETURN (*pSQLNativeSql)(SQLHDBC,SQLCHAR*,SQLINTEGER,SQLCHAR*,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLNativeSqlW)(SQLHDBC,SQLWCHAR*,SQLINTEGER,SQLWCHAR*,SQLINTEGER,SQLINTEGER*);
static SQLRETURN (*pSQLNumParams)(SQLHSTMT,SQLSMALLINT*);
static SQLRETURN (*pSQLNumResultCols)(SQLHSTMT,SQLSMALLINT*);
static SQLRETURN (*pSQLParamData)(SQLHSTMT,SQLPOINTER*);
133
static SQLRETURN (*pSQLParamOptions)(SQLHSTMT,SQLULEN,SQLULEN*);
134 135 136 137 138 139 140 141
static SQLRETURN (*pSQLPrepare)(SQLHSTMT,SQLCHAR*,SQLINTEGER);
static SQLRETURN (*pSQLPrepareW)(SQLHSTMT,SQLWCHAR*,SQLINTEGER);
static SQLRETURN (*pSQLPrimaryKeys)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLPrimaryKeysW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLProcedureColumns)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLProcedureColumnsW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLProcedures)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLProceduresW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
142 143
static SQLRETURN (*pSQLPutData)(SQLHSTMT,SQLPOINTER,SQLLEN);
static SQLRETURN (*pSQLRowCount)(SQLHSTMT,SQLLEN*);
144 145
static SQLRETURN (*pSQLSetConnectAttr)(SQLHDBC,SQLINTEGER,SQLPOINTER,SQLINTEGER);
static SQLRETURN (*pSQLSetConnectAttrW)(SQLHDBC,SQLINTEGER,SQLPOINTER,SQLINTEGER);
146
static SQLRETURN (*pSQLSetConnectOption)(SQLHDBC,SQLUSMALLINT,SQLULEN);
147 148 149 150 151
static SQLRETURN (*pSQLSetConnectOptionW)(SQLHDBC,SQLUSMALLINT,SQLULEN);
static SQLRETURN (*pSQLSetCursorName)(SQLHSTMT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLSetCursorNameW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLSetDescField)(SQLHDESC,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLINTEGER);
static SQLRETURN (*pSQLSetDescFieldW)(SQLHDESC,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLINTEGER);
152
static SQLRETURN (*pSQLSetDescRec)(SQLHDESC,SQLSMALLINT,SQLSMALLINT,SQLSMALLINT,SQLLEN,SQLSMALLINT,SQLSMALLINT,SQLPOINTER,SQLLEN*,SQLLEN*);
153
static SQLRETURN (*pSQLSetEnvAttr)(SQLHENV,SQLINTEGER,SQLPOINTER,SQLINTEGER);
154 155 156
static SQLRETURN (*pSQLSetParam)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLSMALLINT,SQLULEN,SQLSMALLINT,SQLPOINTER,SQLLEN*);
static SQLRETURN (*pSQLSetPos)(SQLHSTMT,SQLSETPOSIROW,SQLUSMALLINT,SQLUSMALLINT);
static SQLRETURN (*pSQLSetScrollOptions)(SQLHSTMT,SQLUSMALLINT,SQLLEN,SQLUSMALLINT);
157 158
static SQLRETURN (*pSQLSetStmtAttr)(SQLHSTMT,SQLINTEGER,SQLPOINTER,SQLINTEGER);
static SQLRETURN (*pSQLSetStmtAttrW)(SQLHSTMT,SQLINTEGER,SQLPOINTER,SQLINTEGER);
159
static SQLRETURN (*pSQLSetStmtOption)(SQLHSTMT,SQLUSMALLINT,SQLULEN);
160 161 162 163 164 165 166 167 168
static SQLRETURN (*pSQLSpecialColumns)(SQLHSTMT,SQLUSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLUSMALLINT,SQLUSMALLINT);
static SQLRETURN (*pSQLSpecialColumnsW)(SQLHSTMT,SQLUSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLUSMALLINT,SQLUSMALLINT);
static SQLRETURN (*pSQLStatistics)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLUSMALLINT,SQLUSMALLINT);
static SQLRETURN (*pSQLStatisticsW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLUSMALLINT,SQLUSMALLINT);
static SQLRETURN (*pSQLTablePrivileges)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLTablePrivilegesW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLTables)(SQLHSTMT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT,SQLCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLTablesW)(SQLHSTMT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT,SQLWCHAR*,SQLSMALLINT);
static SQLRETURN (*pSQLTransact)(SQLHENV,SQLHDBC,SQLUSMALLINT);
169 170
static SQLRETURN (*pSQLGetDiagRecA)(SQLSMALLINT,SQLHANDLE,SQLSMALLINT,SQLCHAR*,SQLINTEGER*,
                                    SQLCHAR*,SQLSMALLINT,SQLSMALLINT*);
171 172 173 174 175 176 177

#define ERROR_FREE 0
#define ERROR_SQLERROR  1
#define ERROR_LIBRARY_NOT_FOUND 2

static void *dmHandle;
static int nErrorType;
Alexandre Julliard's avatar
Alexandre Julliard committed
178

179 180 181 182 183 184 185
SQLRETURN WINAPI ODBC32_SQLAllocEnv(SQLHENV *);
SQLRETURN WINAPI ODBC32_SQLFreeEnv(SQLHENV);
SQLRETURN WINAPI ODBC32_SQLDataSources(SQLHENV, SQLUSMALLINT, SQLCHAR *, SQLSMALLINT,
                                       SQLSMALLINT *, SQLCHAR *, SQLSMALLINT, SQLSMALLINT *);
SQLRETURN WINAPI ODBC32_SQLDrivers(SQLHENV, SQLUSMALLINT, SQLCHAR *, SQLSMALLINT, SQLSMALLINT *,
                                   SQLCHAR *, SQLSMALLINT, SQLSMALLINT *);

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
/***********************************************************************
 * ODBC_ReplicateODBCInstToRegistry
 *
 * PARAMS
 *
 * RETURNS
 *
 * Utility to ODBC_ReplicateToRegistry to replicate the drivers of the
 * ODBCINST.INI settings
 *
 * The driver settings are not replicated to the registry.  If we were to 
 * replicate them we would need to decide whether to replicate all settings
 * or to do some translation; whether to remove any entries present only in
 * the windows registry, etc.
 */

static void ODBC_ReplicateODBCInstToRegistry (SQLHENV hEnv)
{
    HKEY hODBCInst;
    LONG reg_ret;
206
    BOOL success;
207

208
    success = FALSE;
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    TRACE ("Driver settings are not currently replicated to the registry\n");
    if ((reg_ret = RegCreateKeyExA (HKEY_LOCAL_MACHINE,
            "Software\\ODBC\\ODBCINST.INI", 0, NULL,
            REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS /* a couple more than we need */, NULL,
            &hODBCInst, NULL)) == ERROR_SUCCESS)
    {
        HKEY hDrivers;
        if ((reg_ret = RegCreateKeyExA (hODBCInst, "ODBC Drivers", 0,
                NULL, REG_OPTION_NON_VOLATILE,
                KEY_ALL_ACCESS /* overkill */, NULL, &hDrivers, NULL))
                == ERROR_SUCCESS)
        {
            SQLRETURN sql_ret;
            SQLUSMALLINT dirn;
Mike McCormack's avatar
Mike McCormack committed
224
            CHAR desc [256];
225 226
            SQLSMALLINT sizedesc;

227
            success = TRUE;
228
            dirn = SQL_FETCH_FIRST;
229
            while ((sql_ret = ODBC32_SQLDrivers (hEnv, dirn, (SQLCHAR*)desc, sizeof(desc),
230 231 232 233 234
                    &sizedesc, NULL, 0, NULL)) == SQL_SUCCESS ||
                    sql_ret == SQL_SUCCESS_WITH_INFO)
            {
                /* FIXME Do some proper handling of the SUCCESS_WITH_INFO */
                dirn = SQL_FETCH_NEXT;
235
                if (sizedesc == lstrlenA(desc))
236 237 238 239 240 241
                {
                    HKEY hThis;
                    if ((reg_ret = RegQueryValueExA (hDrivers, desc, NULL,
                            NULL, NULL, NULL)) == ERROR_FILE_NOT_FOUND)
                    {
                        if ((reg_ret = RegSetValueExA (hDrivers, desc, 0,
242
                                REG_SZ, (const BYTE *)"Installed", 10)) != ERROR_SUCCESS)
243
                        {
244
                            TRACE ("Error %d replicating driver %s\n",
245
                                    reg_ret, desc);
246
                            success = FALSE;
247 248 249 250
                        }
                    }
                    else if (reg_ret != ERROR_SUCCESS)
                    {
251
                        TRACE ("Error %d checking for %s in drivers\n",
252
                                reg_ret, desc);
253
                        success = FALSE;
254 255 256 257 258 259 260 261 262 263 264 265 266 267
                    }
                    if ((reg_ret = RegCreateKeyExA (hODBCInst, desc, 0,
                            NULL, REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS, NULL, &hThis, NULL))
                            == ERROR_SUCCESS)
                    {
                        /* FIXME This is where the settings go.
                         * I suggest that if the disposition says it 
                         * exists then we leave it alone.  Alternatively
                         * include an extra value to flag that it is 
                         * a replication of the unixODBC/iODBC/...
                         */
                        if ((reg_ret = RegCloseKey (hThis)) !=
                                ERROR_SUCCESS)
268
                            TRACE ("Error %d closing %s key\n", reg_ret,
269 270 271 272
                                    desc);
                    }
                    else
                    {
273
                        TRACE ("Error %d ensuring driver key %s\n",
274
                                reg_ret, desc);
275
                        success = FALSE;
276 277 278 279 280 281
                    }
                }
                else
                {
                    WARN ("Unusually long driver name %s not replicated\n",
                            desc);
282
                    success = FALSE;
283 284 285 286 287
                }
            }
            if (sql_ret != SQL_NO_DATA)
            {
                TRACE ("Error %d enumerating drivers\n", (int)sql_ret);
288
                success = FALSE;
289 290 291
            }
            if ((reg_ret = RegCloseKey (hDrivers)) != ERROR_SUCCESS)
            {
292
                TRACE ("Error %d closing hDrivers\n", reg_ret);
293 294 295 296
            }
        }
        else
        {
297
            TRACE ("Error %d opening HKLM\\S\\O\\OI\\Drivers\n", reg_ret);
298 299 300
        }
        if ((reg_ret = RegCloseKey (hODBCInst)) != ERROR_SUCCESS)
        {
301
            TRACE ("Error %d closing HKLM\\S\\O\\ODBCINST.INI\n", reg_ret);
302 303 304 305
        }
    }
    else
    {
306
        TRACE ("Error %d opening HKLM\\S\\O\\ODBCINST.INI\n", reg_ret);
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    }
    if (!success)
    {
        WARN ("May not have replicated all ODBC drivers to the registry\n");
    }
}

/***********************************************************************
 * ODBC_ReplicateODBCToRegistry
 *
 * PARAMS
 *
 * RETURNS
 *
 * Utility to ODBC_ReplicateToRegistry to replicate either the USER or 
 * SYSTEM dsns
 *
 * For now simply place the "Driver description" (as returned by SQLDataSources)
 * into the registry as the driver.  This is enough to satisfy Crystal's 
 * requirement that there be a driver entry.  (It doesn't seem to care what
 * the setting is).
 * A slightly more accurate setting would be to access the registry to find
 * the actual driver library for the given description (which appears to map
 * to one of the HKLM/Software/ODBC/ODBCINST.INI keys).  (If you do this note
 * that this will add a requirement that this function be called after
 * ODBC_ReplicateODBCInstToRegistry)
 */
334
static void ODBC_ReplicateODBCToRegistry (BOOL is_user, SQLHENV hEnv)
335 336 337 338 339
{
    HKEY hODBC;
    LONG reg_ret;
    SQLRETURN sql_ret;
    SQLUSMALLINT dirn;
Mike McCormack's avatar
Mike McCormack committed
340
    CHAR dsn [SQL_MAX_DSN_LENGTH + 1];
341
    SQLSMALLINT sizedsn;
Mike McCormack's avatar
Mike McCormack committed
342
    CHAR desc [256];
343
    SQLSMALLINT sizedesc;
344
    BOOL success;
345 346
    const char *which = is_user ? "user" : "system";

347
    success = FALSE;
348 349 350 351 352 353
    if ((reg_ret = RegCreateKeyExA (
            is_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
            "Software\\ODBC\\ODBC.INI", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS /* a couple more than we need */, NULL, &hODBC,
            NULL)) == ERROR_SUCCESS)
    {
354
        success = TRUE;
355
        dirn = is_user ? SQL_FETCH_FIRST_USER : SQL_FETCH_FIRST_SYSTEM;
356
        while ((sql_ret = ODBC32_SQLDataSources (hEnv, dirn,
Mike McCormack's avatar
Mike McCormack committed
357 358
                (SQLCHAR*)dsn, sizeof(dsn), &sizedsn,
                (SQLCHAR*)desc, sizeof(desc), &sizedesc)) == SQL_SUCCESS
359 360 361 362
                || sql_ret == SQL_SUCCESS_WITH_INFO)
        {
            /* FIXME Do some proper handling of the SUCCESS_WITH_INFO */
            dirn = SQL_FETCH_NEXT;
363
            if (sizedsn == lstrlenA(dsn) && sizedesc == lstrlenA(desc))
364 365 366 367 368 369 370
            {
                HKEY hDSN;
                if ((reg_ret = RegCreateKeyExA (hODBC, dsn, 0,
                        NULL, REG_OPTION_NON_VOLATILE,
                        KEY_ALL_ACCESS, NULL, &hDSN, NULL))
                        == ERROR_SUCCESS)
                {
371
                    static const char DRIVERKEY[] = "Driver";
372 373 374 375 376
                    if ((reg_ret = RegQueryValueExA (hDSN, DRIVERKEY,
                            NULL, NULL, NULL, NULL))
                            == ERROR_FILE_NOT_FOUND)
                    {
                        if ((reg_ret = RegSetValueExA (hDSN, DRIVERKEY, 0,
Mike McCormack's avatar
Mike McCormack committed
377
                                REG_SZ, (LPBYTE)desc, sizedesc)) != ERROR_SUCCESS)
378
                        {
379
                            TRACE ("Error %d replicating description of "
380
                                    "%s(%s)\n", reg_ret, dsn, desc);
381
                            success = FALSE;
382 383 384 385
                        }
                    }
                    else if (reg_ret != ERROR_SUCCESS)
                    {
386
                        TRACE ("Error %d checking for description of %s\n",
387
                                reg_ret, dsn);
388
                        success = FALSE;
389 390 391
                    }
                    if ((reg_ret = RegCloseKey (hDSN)) != ERROR_SUCCESS)
                    {
392
                        TRACE ("Error %d closing %s DSN key %s\n",
393 394 395 396 397
                                reg_ret, which, dsn);
                    }
                }
                else
                {
398
                    TRACE ("Error %d opening %s DSN key %s\n",
399
                            reg_ret, which, dsn);
400
                    success = FALSE;
401 402 403 404 405 406
                }
            }
            else
            {
                WARN ("Unusually long %s data source name %s (%s) not "
                        "replicated\n", which, dsn, desc);
407
                success = FALSE;
408 409 410 411 412 413
            }
        }
        if (sql_ret != SQL_NO_DATA)
        {
            TRACE ("Error %d enumerating %s datasources\n",
                    (int)sql_ret, which);
414
            success = FALSE;
415 416 417
        }
        if ((reg_ret = RegCloseKey (hODBC)) != ERROR_SUCCESS)
        {
418
            TRACE ("Error %d closing %s ODBC.INI registry key\n", reg_ret,
419 420 421 422 423
                    which);
        }
    }
    else
    {
424
        TRACE ("Error %d creating/opening %s ODBC.INI registry key\n",
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
                reg_ret, which);
    }
    if (!success)
    {
        WARN ("May not have replicated all %s ODBC DSNs to the registry\n",
                which);
    }
}

/***********************************************************************
 * ODBC_ReplicateToRegistry
 *
 * PARAMS
 *
 * RETURNS
 *
 * Unfortunately some of the functions that Windows documents as being part
 * of the ODBC API it implements directly during compilation or something
 * in terms of registry access functions.
 * e.g. SQLGetInstalledDrivers queries the list at
 * HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\ODBC Drivers
 *
 * This function is called when the driver manager is loaded and is used
 * to replicate the appropriate details into the Wine registry
 */

static void ODBC_ReplicateToRegistry (void)
{
    SQLRETURN sql_ret;
    SQLHENV hEnv;

456
    if ((sql_ret = ODBC32_SQLAllocEnv (&hEnv)) == SQL_SUCCESS)
457 458
    {
        ODBC_ReplicateODBCInstToRegistry (hEnv);
459 460
        ODBC_ReplicateODBCToRegistry (FALSE /* system dsns */, hEnv);
        ODBC_ReplicateODBCToRegistry (TRUE /* user dsns */, hEnv);
461

462
        if ((sql_ret = ODBC32_SQLFreeEnv (hEnv)) != SQL_SUCCESS)
463 464 465 466 467 468 469 470 471 472 473 474
        {
            TRACE ("Error %d freeing the SQL environment.\n", (int)sql_ret);
        }
    }
    else
    {
        TRACE ("Error %d opening an SQL environment.\n", (int)sql_ret);
        WARN ("The external ODBC settings have not been replicated to the"
                " Wine registry\n");
    }
}

Alexandre Julliard's avatar
Alexandre Julliard committed
475
/***********************************************************************
476
 * DllMain [Internal] Initializes the internal 'ODBC32.DLL'.
Alexandre Julliard's avatar
Alexandre Julliard committed
477
 */
478
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID reserved)
Alexandre Julliard's avatar
Alexandre Julliard committed
479
{
480
    TRACE("proxy ODBC: %p,%x,%p\n", hinstDLL, reason, reserved);
Alexandre Julliard's avatar
Alexandre Julliard committed
481

482
    switch (reason)
Alexandre Julliard's avatar
Alexandre Julliard committed
483
    {
484
    case DLL_PROCESS_ATTACH:
485
       DisableThreadLibraryCalls(hinstDLL);
Alexandre Julliard's avatar
Alexandre Julliard committed
486
       if (ODBC_LoadDriverManager())
487
       {
Alexandre Julliard's avatar
Alexandre Julliard committed
488
          ODBC_LoadDMFunctions();
489 490
          ODBC_ReplicateToRegistry();
       }
491 492 493 494
       break;

    case DLL_PROCESS_DETACH:
      if (reserved) break;
495
      if (dmHandle) dlclose(dmHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
    }

    return TRUE;
}

/***********************************************************************
 * ODBC_LoadDriverManager [Internal] Load ODBC library.
 *
 * PARAMS
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */

511
static BOOL ODBC_LoadDriverManager(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
512
{
513
   const char *s = getenv("LIB_ODBC_DRIVER_MANAGER");
Alexandre Julliard's avatar
Alexandre Julliard committed
514

515 516 517 518
#ifdef SONAME_LIBODBC
   if (!s || !s[0]) s = SONAME_LIBODBC;
#endif
   if (!s || !s[0]) goto failed;
Alexandre Julliard's avatar
Alexandre Julliard committed
519

520
   dmHandle = dlopen( s, RTLD_LAZY | RTLD_GLOBAL );
Alexandre Julliard's avatar
Alexandre Julliard committed
521

522
   if (dmHandle != NULL)
Alexandre Julliard's avatar
Alexandre Julliard committed
523
   {
524
      TRACE("Opened library %s\n", s);
525
      nErrorType = ERROR_FREE;
Alexandre Julliard's avatar
Alexandre Julliard committed
526 527
      return TRUE;
   }
528
failed:
529
   ERR_(winediag)("failed to open library %s: %s\n", debugstr_a(s), dlerror());
530
   nErrorType = ERROR_LIBRARY_NOT_FOUND;
531
   return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
532 533 534 535 536 537 538 539 540 541 542 543 544
}


/***********************************************************************
 * ODBC_LoadDMFunctions [Internal] Populate function table.
 *
 * PARAMS
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */

545
static BOOL ODBC_LoadDMFunctions(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
546
{
547
    if (dmHandle == NULL)
Alexandre Julliard's avatar
Alexandre Julliard committed
548 549
        return FALSE;

550
#define LOAD_FUNC(name) \
551 552
    if ((p##name = dlsym( dmHandle, #name ))); \
    else WARN( "Failed to load %s: %s\n", #name, dlerror() )
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578

    LOAD_FUNC(SQLAllocConnect);
    LOAD_FUNC(SQLAllocEnv);
    LOAD_FUNC(SQLAllocHandle);
    LOAD_FUNC(SQLAllocHandleStd);
    LOAD_FUNC(SQLAllocStmt);
    LOAD_FUNC(SQLBindCol);
    LOAD_FUNC(SQLBindParam);
    LOAD_FUNC(SQLBindParameter);
    LOAD_FUNC(SQLBrowseConnect);
    LOAD_FUNC(SQLBrowseConnectW);
    LOAD_FUNC(SQLBulkOperations);
    LOAD_FUNC(SQLCancel);
    LOAD_FUNC(SQLCloseCursor);
    LOAD_FUNC(SQLColAttribute);
    LOAD_FUNC(SQLColAttributeW);
    LOAD_FUNC(SQLColAttributes);
    LOAD_FUNC(SQLColAttributesW);
    LOAD_FUNC(SQLColumnPrivileges);
    LOAD_FUNC(SQLColumnPrivilegesW);
    LOAD_FUNC(SQLColumns);
    LOAD_FUNC(SQLColumnsW);
    LOAD_FUNC(SQLConnect);
    LOAD_FUNC(SQLConnectW);
    LOAD_FUNC(SQLCopyDesc);
    LOAD_FUNC(SQLDataSources);
579
    LOAD_FUNC(SQLDataSourcesA);
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
    LOAD_FUNC(SQLDataSourcesW);
    LOAD_FUNC(SQLDescribeCol);
    LOAD_FUNC(SQLDescribeColW);
    LOAD_FUNC(SQLDescribeParam);
    LOAD_FUNC(SQLDisconnect);
    LOAD_FUNC(SQLDriverConnect);
    LOAD_FUNC(SQLDriverConnectW);
    LOAD_FUNC(SQLDrivers);
    LOAD_FUNC(SQLDriversW);
    LOAD_FUNC(SQLEndTran);
    LOAD_FUNC(SQLError);
    LOAD_FUNC(SQLErrorW);
    LOAD_FUNC(SQLExecDirect);
    LOAD_FUNC(SQLExecDirectW);
    LOAD_FUNC(SQLExecute);
    LOAD_FUNC(SQLExtendedFetch);
    LOAD_FUNC(SQLFetch);
    LOAD_FUNC(SQLFetchScroll);
    LOAD_FUNC(SQLForeignKeys);
    LOAD_FUNC(SQLForeignKeysW);
    LOAD_FUNC(SQLFreeConnect);
    LOAD_FUNC(SQLFreeEnv);
    LOAD_FUNC(SQLFreeHandle);
    LOAD_FUNC(SQLFreeStmt);
    LOAD_FUNC(SQLGetConnectAttr);
    LOAD_FUNC(SQLGetConnectAttrW);
    LOAD_FUNC(SQLGetConnectOption);
    LOAD_FUNC(SQLGetConnectOptionW);
    LOAD_FUNC(SQLGetCursorName);
    LOAD_FUNC(SQLGetCursorNameW);
    LOAD_FUNC(SQLGetData);
    LOAD_FUNC(SQLGetDescField);
    LOAD_FUNC(SQLGetDescFieldW);
    LOAD_FUNC(SQLGetDescRec);
    LOAD_FUNC(SQLGetDescRecW);
    LOAD_FUNC(SQLGetDiagField);
    LOAD_FUNC(SQLGetDiagFieldW);
    LOAD_FUNC(SQLGetDiagRec);
618
    LOAD_FUNC(SQLGetDiagRecA);
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
    LOAD_FUNC(SQLGetDiagRecW);
    LOAD_FUNC(SQLGetEnvAttr);
    LOAD_FUNC(SQLGetFunctions);
    LOAD_FUNC(SQLGetInfo);
    LOAD_FUNC(SQLGetInfoW);
    LOAD_FUNC(SQLGetStmtAttr);
    LOAD_FUNC(SQLGetStmtAttrW);
    LOAD_FUNC(SQLGetStmtOption);
    LOAD_FUNC(SQLGetTypeInfo);
    LOAD_FUNC(SQLGetTypeInfoW);
    LOAD_FUNC(SQLMoreResults);
    LOAD_FUNC(SQLNativeSql);
    LOAD_FUNC(SQLNativeSqlW);
    LOAD_FUNC(SQLNumParams);
    LOAD_FUNC(SQLNumResultCols);
    LOAD_FUNC(SQLParamData);
    LOAD_FUNC(SQLParamOptions);
    LOAD_FUNC(SQLPrepare);
    LOAD_FUNC(SQLPrepareW);
    LOAD_FUNC(SQLPrimaryKeys);
    LOAD_FUNC(SQLPrimaryKeysW);
    LOAD_FUNC(SQLProcedureColumns);
    LOAD_FUNC(SQLProcedureColumnsW);
    LOAD_FUNC(SQLProcedures);
    LOAD_FUNC(SQLProceduresW);
    LOAD_FUNC(SQLPutData);
    LOAD_FUNC(SQLRowCount);
    LOAD_FUNC(SQLSetConnectAttr);
    LOAD_FUNC(SQLSetConnectAttrW);
    LOAD_FUNC(SQLSetConnectOption);
    LOAD_FUNC(SQLSetConnectOptionW);
    LOAD_FUNC(SQLSetCursorName);
    LOAD_FUNC(SQLSetCursorNameW);
    LOAD_FUNC(SQLSetDescField);
    LOAD_FUNC(SQLSetDescFieldW);
    LOAD_FUNC(SQLSetDescRec);
    LOAD_FUNC(SQLSetEnvAttr);
    LOAD_FUNC(SQLSetParam);
    LOAD_FUNC(SQLSetPos);
    LOAD_FUNC(SQLSetScrollOptions);
    LOAD_FUNC(SQLSetStmtAttr);
    LOAD_FUNC(SQLSetStmtAttrW);
    LOAD_FUNC(SQLSetStmtOption);
    LOAD_FUNC(SQLSpecialColumns);
    LOAD_FUNC(SQLSpecialColumnsW);
    LOAD_FUNC(SQLStatistics);
    LOAD_FUNC(SQLStatisticsW);
    LOAD_FUNC(SQLTablePrivileges);
    LOAD_FUNC(SQLTablePrivilegesW);
    LOAD_FUNC(SQLTables);
    LOAD_FUNC(SQLTablesW);
    LOAD_FUNC(SQLTransact);
#undef LOAD_FUNC
Alexandre Julliard's avatar
Alexandre Julliard committed
672 673 674 675 676 677 678

    return TRUE;
}

/*************************************************************************
 *				SQLAllocConnect           [ODBC32.001]
 */
679
SQLRETURN WINAPI ODBC32_SQLAllocConnect(SQLHENV EnvironmentHandle, SQLHDBC *ConnectionHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
680
{
681
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
682

683
    TRACE("(EnvironmentHandle %p, ConnectionHandle %p)\n", EnvironmentHandle, ConnectionHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
684

685 686 687 688 689 690
    if (!pSQLAllocConnect)
    {
        *ConnectionHandle = SQL_NULL_HDBC;
        TRACE("Not ready\n");
        return SQL_ERROR;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
691

692 693 694 695
    ret = pSQLAllocConnect(EnvironmentHandle, ConnectionHandle);
    TRACE("Returning %d, ConnectionHandle %p\n", ret, *ConnectionHandle);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
696 697 698 699

/*************************************************************************
 *				SQLAllocEnv           [ODBC32.002]
 */
700
SQLRETURN WINAPI ODBC32_SQLAllocEnv(SQLHENV *EnvironmentHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
701
{
702
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
703

704
    TRACE("(EnvironmentHandle %p)\n", EnvironmentHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
705

706 707 708 709 710 711
    if (!pSQLAllocEnv)
    {
        *EnvironmentHandle = SQL_NULL_HENV;
        TRACE("Not ready\n");
        return SQL_ERROR;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
712

713 714 715 716
    ret = pSQLAllocEnv(EnvironmentHandle);
    TRACE("Returning %d, EnvironmentHandle %p\n", ret, *EnvironmentHandle);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
717 718 719 720

/*************************************************************************
 *				SQLAllocHandle           [ODBC32.024]
 */
721
SQLRETURN WINAPI ODBC32_SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
722
{
723
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
724

725
    TRACE("(HandleType %d, InputHandle %p, OutputHandle %p)\n", HandleType, InputHandle, OutputHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
726

727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
    if (!pSQLAllocHandle)
    {
        if (nErrorType == ERROR_LIBRARY_NOT_FOUND)
            WARN("ProxyODBC: Cannot load ODBC driver manager library.\n");

        if (HandleType == SQL_HANDLE_ENV)
            *OutputHandle = SQL_NULL_HENV;
        else if (HandleType == SQL_HANDLE_DBC)
            *OutputHandle = SQL_NULL_HDBC;
        else if (HandleType == SQL_HANDLE_STMT)
            *OutputHandle = SQL_NULL_HSTMT;
        else if (HandleType == SQL_HANDLE_DESC)
            *OutputHandle = SQL_NULL_HDESC;

        TRACE ("Not ready\n");
        return SQL_ERROR;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
744

745 746 747 748
    ret = pSQLAllocHandle(HandleType, InputHandle, OutputHandle);
    TRACE("Returning %d, Handle %p\n", ret, *OutputHandle);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
749 750 751 752

/*************************************************************************
 *				SQLAllocStmt           [ODBC32.003]
 */
753
SQLRETURN WINAPI ODBC32_SQLAllocStmt(SQLHDBC ConnectionHandle, SQLHSTMT *StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
754
{
755
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
756

757
    TRACE("(ConnectionHandle %p, StatementHandle %p)\n", ConnectionHandle, StatementHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
758

759 760 761 762 763 764
    if (!pSQLAllocStmt)
    {
        *StatementHandle = SQL_NULL_HSTMT;
        TRACE("Not ready\n");
        return SQL_ERROR;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
765

766 767 768
    ret = pSQLAllocStmt(ConnectionHandle, StatementHandle);
    TRACE ("Returning %d, StatementHandle %p\n", ret, *StatementHandle);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
769 770 771 772 773
}

/*************************************************************************
 *				SQLAllocHandleStd           [ODBC32.077]
 */
774
SQLRETURN WINAPI ODBC32_SQLAllocHandleStd(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
775
{
776
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
777

778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
    TRACE("(HandleType %d, InputHandle %p, OutputHandle %p)\n", HandleType, InputHandle, OutputHandle);

    if (!pSQLAllocHandleStd)
    {
        if (nErrorType == ERROR_LIBRARY_NOT_FOUND)
            WARN("ProxyODBC: Cannot load ODBC driver manager library.\n");

        if (HandleType == SQL_HANDLE_ENV)
            *OutputHandle = SQL_NULL_HENV;
        else if (HandleType == SQL_HANDLE_DBC)
            *OutputHandle = SQL_NULL_HDBC;
        else if (HandleType == SQL_HANDLE_STMT)
            *OutputHandle = SQL_NULL_HSTMT;
        else if (HandleType == SQL_HANDLE_DESC)
            *OutputHandle = SQL_NULL_HDESC;
Alexandre Julliard's avatar
Alexandre Julliard committed
793

794 795 796 797 798 799
        return SQL_ERROR;
    }

    ret = pSQLAllocHandleStd(HandleType, InputHandle, OutputHandle);
    TRACE ("Returning %d, OutputHandle %p\n", ret, *OutputHandle);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
800 801
}

802 803 804 805 806 807 808 809
static const char *debugstr_sqllen( SQLLEN len )
{
#ifdef _WIN64
    return wine_dbg_sprintf( "%ld", len );
#else
    return wine_dbg_sprintf( "%d", len );
#endif
}
Alexandre Julliard's avatar
Alexandre Julliard committed
810 811 812 813

/*************************************************************************
 *				SQLBindCol           [ODBC32.004]
 */
814 815
SQLRETURN WINAPI ODBC32_SQLBindCol(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
                                   SQLPOINTER TargetValue, SQLLEN BufferLength, SQLLEN *StrLen_or_Ind)
Alexandre Julliard's avatar
Alexandre Julliard committed
816
{
817
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
818

819 820 821 822 823 824 825 826
    TRACE("(StatementHandle %p, ColumnNumber %d, TargetType %d, TargetValue %p, BufferLength %s, StrLen_or_Ind %p)\n",
          StatementHandle, ColumnNumber, TargetType, TargetValue, debugstr_sqllen(BufferLength), StrLen_or_Ind);

    if (!pSQLBindCol)
    {
        TRACE("Not ready\n");
        return SQL_ERROR;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
827

828 829 830
    ret = pSQLBindCol(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind);
    TRACE ("Returning %d\n", ret);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
831 832
}

833 834 835 836 837 838 839 840
static const char *debugstr_sqlulen( SQLULEN len )
{
#ifdef _WIN64
    return wine_dbg_sprintf( "%lu", len );
#else
    return wine_dbg_sprintf( "%u", len );
#endif
}
Alexandre Julliard's avatar
Alexandre Julliard committed
841 842 843 844

/*************************************************************************
 *				SQLBindParam           [ODBC32.025]
 */
845 846 847
SQLRETURN WINAPI ODBC32_SQLBindParam(SQLHSTMT StatementHandle, SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
                                     SQLSMALLINT ParameterType, SQLULEN LengthPrecision, SQLSMALLINT ParameterScale,
                                     SQLPOINTER ParameterValue, SQLLEN *StrLen_or_Ind)
Alexandre Julliard's avatar
Alexandre Julliard committed
848
{
849
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
850

851 852 853
    TRACE("(StatementHandle %p, ParameterNumber %d, ValueType %d, ParameterType %d, LengthPrecision %s,"
          " ParameterScale %d, ParameterValue %p, StrLen_or_Ind %p)\n", StatementHandle, ParameterNumber, ValueType,
          ParameterType, debugstr_sqlulen(LengthPrecision), ParameterScale, ParameterValue, StrLen_or_Ind);
Alexandre Julliard's avatar
Alexandre Julliard committed
854

855 856 857 858 859 860 861
    if (!pSQLBindParam) return SQL_ERROR;

    ret = pSQLBindParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision, ParameterScale,
                        ParameterValue, StrLen_or_Ind);
    TRACE ("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
862 863 864 865

/*************************************************************************
 *				SQLCancel           [ODBC32.005]
 */
866
SQLRETURN WINAPI ODBC32_SQLCancel(SQLHSTMT StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
867
{
868
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
869

870 871 872
    TRACE("(StatementHandle %p)\n", StatementHandle);

    if (!pSQLCancel) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
873

874 875 876 877
    ret = pSQLCancel(StatementHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
878 879 880 881

/*************************************************************************
 *				SQLCloseCursor           [ODBC32.026]
 */
882
SQLRETURN WINAPI ODBC32_SQLCloseCursor(SQLHSTMT StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
883
{
884
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
885

886
    TRACE("(StatementHandle %p)\n", StatementHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
887

888
    if (!pSQLCloseCursor) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
889

890 891 892 893
    ret = pSQLCloseCursor(StatementHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
894 895 896 897

/*************************************************************************
 *				SQLColAttribute           [ODBC32.027]
 */
898 899 900 901
SQLRETURN WINAPI ODBC32_SQLColAttribute(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber,
                                        SQLUSMALLINT FieldIdentifier, SQLPOINTER CharacterAttribute,
                                        SQLSMALLINT BufferLength, SQLSMALLINT *StringLength,
                                        SQLLEN *NumericAttribute)
Alexandre Julliard's avatar
Alexandre Julliard committed
902
{
903
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
904

905 906 907
    TRACE("(StatementHandle %p, ColumnNumber %d, FieldIdentifier %d, CharacterAttribute %p, BufferLength %d,"
          " StringLength %p, NumericAttribute %p)\n", StatementHandle, ColumnNumber, FieldIdentifier,
          CharacterAttribute, BufferLength, StringLength, NumericAttribute);
Alexandre Julliard's avatar
Alexandre Julliard committed
908

909 910 911 912 913 914 915
    if (!pSQLColAttribute) return SQL_ERROR;

    ret = pSQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength,
                           StringLength, NumericAttribute);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
916 917 918 919

/*************************************************************************
 *				SQLColumns           [ODBC32.040]
 */
920 921 922
SQLRETURN WINAPI ODBC32_SQLColumns(SQLHSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
                                   SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName,
                                   SQLSMALLINT NameLength3, SQLCHAR *ColumnName, SQLSMALLINT NameLength4)
Alexandre Julliard's avatar
Alexandre Julliard committed
923
{
924
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
925

926 927 928 929 930 931 932 933
    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d, TableName %s,"
          " NameLength3 %d, ColumnName %s, NameLength4 %d)\n", StatementHandle,
          debugstr_an((const char *)CatalogName, NameLength1), NameLength1,
          debugstr_an((const char *)SchemaName, NameLength2), NameLength2,
          debugstr_an((const char *)TableName, NameLength3), NameLength3,
          debugstr_an((const char *)ColumnName, NameLength4), NameLength4);

    if (!pSQLColumns) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
934

935 936 937 938 939
    ret = pSQLColumns(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName,
                      NameLength3, ColumnName, NameLength4);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
940 941 942 943

/*************************************************************************
 *				SQLConnect           [ODBC32.007]
 */
944 945 946
SQLRETURN WINAPI ODBC32_SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1,
                                   SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication,
                                   SQLSMALLINT NameLength3)
Alexandre Julliard's avatar
Alexandre Julliard committed
947
{
948
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
949

950
    TRACE("(ConnectionHandle %p, ServerName %s, NameLength1 %d, UserName %s, NameLength2 %d, Authentication %s,"
951 952 953 954
          " NameLength3 %d)\n", ConnectionHandle,
          debugstr_an((const char *)ServerName, NameLength1), NameLength1,
          debugstr_an((const char *)UserName, NameLength2), NameLength2,
          debugstr_an((const char *)Authentication, NameLength3), NameLength3);
Alexandre Julliard's avatar
Alexandre Julliard committed
955

956
    if (!pSQLConnect) return SQL_ERROR;
957

958 959 960
    ret = pSQLConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3);
    TRACE("Returning %d\n", ret);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
961 962 963 964 965
}

/*************************************************************************
 *				SQLCopyDesc           [ODBC32.028]
 */
966
SQLRETURN WINAPI ODBC32_SQLCopyDesc(SQLHDESC SourceDescHandle, SQLHDESC TargetDescHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
967
{
968
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
969

970 971 972
    TRACE("(SourceDescHandle %p, TargetDescHandle %p)\n", SourceDescHandle, TargetDescHandle);

    if (!pSQLCopyDesc) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
973

974 975 976 977
    ret = pSQLCopyDesc(SourceDescHandle, TargetDescHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
978 979 980 981

/*************************************************************************
 *				SQLDataSources           [ODBC32.057]
 */
982 983 984
SQLRETURN WINAPI ODBC32_SQLDataSources(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, SQLCHAR *ServerName,
                                       SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, SQLCHAR *Description,
                                       SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2)
Alexandre Julliard's avatar
Alexandre Julliard committed
985
{
986
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
987

988 989 990
    TRACE("(EnvironmentHandle %p, Direction %d, ServerName %p, BufferLength1 %d, NameLength1 %p, Description %p,"
          " BufferLength2 %d, NameLength2 %p)\n", EnvironmentHandle, Direction, ServerName, BufferLength1,
          NameLength1, Description, BufferLength2, NameLength2);
Alexandre Julliard's avatar
Alexandre Julliard committed
991

992
    if (!pSQLDataSources) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
993

994 995 996 997 998 999 1000 1001 1002 1003
    ret = pSQLDataSources(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1, Description,
                          BufferLength2, NameLength2);
    if (ret >= 0 && TRACE_ON(odbc))
    {
        if (ServerName && NameLength1 && *NameLength1 > 0)
            TRACE(" DataSource %s", debugstr_an((const char *)ServerName, *NameLength1));
        if (Description && NameLength2 && *NameLength2 > 0)
            TRACE(" Description %s", debugstr_an((const char *)Description, *NameLength2));
        TRACE("\n");
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1004

1005 1006
    TRACE("Returning %d\n", ret);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1007 1008
}

1009 1010 1011
SQLRETURN WINAPI ODBC32_SQLDataSourcesA(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, SQLCHAR *ServerName,
                                        SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, SQLCHAR *Description,
                                        SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2)
1012 1013 1014
{
    SQLRETURN ret;

1015 1016 1017
    TRACE("(EnvironmentHandle %p, Direction %d, ServerName %p, BufferLength1 %d, NameLength1 %p, Description %p,"
          " BufferLength2 %d, NameLength2 %p)\n", EnvironmentHandle, Direction, ServerName, BufferLength1,
          NameLength1, Description, BufferLength2, NameLength2);
1018 1019 1020

    if (!pSQLDataSourcesA) return SQL_ERROR;

1021 1022
    ret = pSQLDataSourcesA(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1, Description,
                           BufferLength2, NameLength2);
1023 1024
    if (TRACE_ON(odbc))
    {
1025 1026 1027 1028
       if (ServerName && NameLength1 && *NameLength1 > 0)
            TRACE(" DataSource %s", debugstr_an((const char *)ServerName, *NameLength1));
       if (Description && NameLength2 && *NameLength2 > 0)
            TRACE(" Description %s", debugstr_an((const char *)Description, *NameLength2));
1029 1030 1031
       TRACE("\n");
    }

1032
    TRACE("Returning %d\n", ret);
1033 1034
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1035 1036 1037 1038

/*************************************************************************
 *				SQLDescribeCol           [ODBC32.008]
 */
1039 1040 1041
SQLRETURN WINAPI ODBC32_SQLDescribeCol(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
                                       SQLSMALLINT BufferLength, SQLSMALLINT *NameLength, SQLSMALLINT *DataType,
                                       SQLULEN *ColumnSize, SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
Alexandre Julliard's avatar
Alexandre Julliard committed
1042
{
1043
    SQLSMALLINT dummy;
1044
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1045

1046 1047 1048
    TRACE("(StatementHandle %p, ColumnNumber %d, ColumnName %p, BufferLength %d, NameLength %p, DataType %p,"
          " ColumnSize %p, DecimalDigits %p, Nullable %p)\n", StatementHandle, ColumnNumber, ColumnName,
          BufferLength, NameLength, DataType, ColumnSize, DecimalDigits, Nullable);
Alexandre Julliard's avatar
Alexandre Julliard committed
1049

1050
    if (!pSQLDescribeCol) return SQL_ERROR;
1051
    if (!NameLength) NameLength = &dummy; /* workaround for drivers that don't accept NULL NameLength */
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066

    ret = pSQLDescribeCol(StatementHandle, ColumnNumber, ColumnName, BufferLength, NameLength, DataType, ColumnSize,
                          DecimalDigits, Nullable);
    if (ret >= 0)
    {
        if (ColumnName && NameLength) TRACE(" ColumnName %s\n", debugstr_an((const char *)ColumnName, *NameLength));
        if (DataType) TRACE(" DataType %d\n", *DataType);
        if (ColumnSize) TRACE(" ColumnSize %s\n", debugstr_sqlulen(*ColumnSize));
        if (DecimalDigits) TRACE(" DecimalDigits %d\n", *DecimalDigits);
        if (Nullable) TRACE(" Nullable %d\n", *Nullable);
    }

    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1067 1068 1069 1070

/*************************************************************************
 *				SQLDisconnect           [ODBC32.009]
 */
1071
SQLRETURN WINAPI ODBC32_SQLDisconnect(SQLHDBC ConnectionHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1072
{
1073
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1074

1075
    TRACE("(ConnectionHandle %p)\n", ConnectionHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1076

1077
    if (!pSQLDisconnect) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1078

1079 1080 1081 1082
    ret = pSQLDisconnect(ConnectionHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1083 1084 1085 1086

/*************************************************************************
 *				SQLEndTran           [ODBC32.029]
 */
1087
SQLRETURN WINAPI ODBC32_SQLEndTran(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT CompletionType)
Alexandre Julliard's avatar
Alexandre Julliard committed
1088
{
1089
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1090

1091
    TRACE("(HandleType %d, Handle %p, CompletionType %d)\n", HandleType, Handle, CompletionType);
Alexandre Julliard's avatar
Alexandre Julliard committed
1092

1093 1094 1095 1096 1097 1098
    if (!pSQLEndTran) return SQL_ERROR;

    ret = pSQLEndTran(HandleType, Handle, CompletionType);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1099 1100 1101 1102

/*************************************************************************
 *				SQLError           [ODBC32.010]
 */
1103 1104 1105
SQLRETURN WINAPI ODBC32_SQLError(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle,
                                 SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText,
                                 SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1106
{
1107
    SQLRETURN ret;
1108

1109 1110 1111
    TRACE("(EnvironmentHandle %p, ConnectionHandle %p, StatementHandle %p, Sqlstate %p, NativeError %p,"
          " MessageText %p, BufferLength %d, TextLength %p)\n", EnvironmentHandle, ConnectionHandle,
          StatementHandle, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1112

1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
    if (!pSQLError) return SQL_ERROR;

    ret = pSQLError(EnvironmentHandle, ConnectionHandle, StatementHandle, Sqlstate, NativeError, MessageText,
                    BufferLength, TextLength);

    if (ret == SQL_SUCCESS)
    {
        TRACE(" SQLState %s\n", debugstr_an((const char *)Sqlstate, 5));
        TRACE(" Error %d\n", *NativeError);
        TRACE(" MessageText %s\n", debugstr_an((const char *)MessageText, *TextLength));
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1124

1125 1126 1127
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1128 1129 1130 1131

/*************************************************************************
 *				SQLExecDirect           [ODBC32.011]
 */
1132
SQLRETURN WINAPI ODBC32_SQLExecDirect(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1133
{
1134
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1135

1136 1137 1138 1139
    TRACE("(StatementHandle %p, StatementText %s, TextLength %d)\n", StatementHandle,
          debugstr_an((const char *)StatementText, TextLength), TextLength);

    if (!pSQLExecDirect) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1140

1141 1142 1143 1144
    ret = pSQLExecDirect(StatementHandle, StatementText, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1145 1146 1147 1148

/*************************************************************************
 *				SQLExecute           [ODBC32.012]
 */
1149
SQLRETURN WINAPI ODBC32_SQLExecute(SQLHSTMT StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1150
{
1151
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1152

1153 1154 1155
    TRACE("(StatementHandle %p)\n", StatementHandle);

    if (!pSQLExecute) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1156

1157 1158 1159 1160
    ret = pSQLExecute(StatementHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1161 1162 1163 1164

/*************************************************************************
 *				SQLFetch           [ODBC32.013]
 */
1165
SQLRETURN WINAPI ODBC32_SQLFetch(SQLHSTMT StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1166
{
1167
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1168

1169
    TRACE("(StatementHandle %p)\n", StatementHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1170

1171 1172 1173 1174 1175 1176
    if (!pSQLFetch) return SQL_ERROR;

    ret = pSQLFetch(StatementHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1177 1178 1179 1180

/*************************************************************************
 *				SQLFetchScroll          [ODBC32.030]
 */
1181
SQLRETURN WINAPI ODBC32_SQLFetchScroll(SQLHSTMT StatementHandle, SQLSMALLINT FetchOrientation, SQLLEN FetchOffset)
Alexandre Julliard's avatar
Alexandre Julliard committed
1182
{
1183
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1184

1185 1186
    TRACE("(StatementHandle %p, FetchOrientation %d, FetchOffset %s)\n", StatementHandle, FetchOrientation,
          debugstr_sqllen(FetchOffset));
Alexandre Julliard's avatar
Alexandre Julliard committed
1187

1188 1189 1190 1191 1192 1193
    if (!pSQLFetchScroll) return SQL_ERROR;

    ret = pSQLFetchScroll(StatementHandle, FetchOrientation, FetchOffset);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1194 1195 1196 1197

/*************************************************************************
 *				SQLFreeConnect           [ODBC32.014]
 */
1198
SQLRETURN WINAPI ODBC32_SQLFreeConnect(SQLHDBC ConnectionHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1199
{
1200
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1201

1202
    TRACE("(ConnectionHandle %p)\n", ConnectionHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1203

1204
    if (!pSQLFreeConnect) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1205

1206 1207 1208 1209
    ret = pSQLFreeConnect(ConnectionHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1210 1211 1212 1213

/*************************************************************************
 *				SQLFreeEnv           [ODBC32.015]
 */
1214
SQLRETURN WINAPI ODBC32_SQLFreeEnv(SQLHENV EnvironmentHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1215
{
1216
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1217

1218
    TRACE("(EnvironmentHandle %p)\n", EnvironmentHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1219

1220
    if (!pSQLFreeEnv) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1221

1222 1223 1224 1225
    ret = pSQLFreeEnv(EnvironmentHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1226 1227 1228 1229

/*************************************************************************
 *				SQLFreeHandle           [ODBC32.031]
 */
1230
SQLRETURN WINAPI ODBC32_SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
Alexandre Julliard's avatar
Alexandre Julliard committed
1231
{
1232
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1233

1234
    TRACE("(HandleType %d, Handle %p)\n", HandleType, Handle);
Alexandre Julliard's avatar
Alexandre Julliard committed
1235

1236
    if (!pSQLFreeHandle) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1237

1238 1239 1240 1241
    ret = pSQLFreeHandle(HandleType, Handle);
    TRACE ("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1242 1243 1244 1245

/*************************************************************************
 *				SQLFreeStmt           [ODBC32.016]
 */
1246
SQLRETURN WINAPI ODBC32_SQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
Alexandre Julliard's avatar
Alexandre Julliard committed
1247
{
1248
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1249

1250
    TRACE("(StatementHandle %p, Option %d)\n", StatementHandle, Option);
Alexandre Julliard's avatar
Alexandre Julliard committed
1251

1252
    if (!pSQLFreeStmt) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1253

1254 1255 1256 1257
    ret = pSQLFreeStmt(StatementHandle, Option);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1258 1259 1260 1261

/*************************************************************************
 *				SQLGetConnectAttr           [ODBC32.032]
 */
1262 1263
SQLRETURN WINAPI ODBC32_SQLGetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                          SQLINTEGER BufferLength, SQLINTEGER *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1264
{
1265
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1266

1267 1268
    TRACE("(ConnectionHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", ConnectionHandle,
          Attribute, Value, BufferLength, StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1269

1270 1271 1272 1273 1274 1275
    if (!pSQLGetConnectAttr) return SQL_ERROR;

    ret = pSQLGetConnectAttr(ConnectionHandle, Attribute, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1276 1277 1278 1279

/*************************************************************************
 *				SQLGetConnectOption       [ODBC32.042]
 */
1280
SQLRETURN WINAPI ODBC32_SQLGetConnectOption(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER Value)
Alexandre Julliard's avatar
Alexandre Julliard committed
1281
{
1282
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1283

1284
    TRACE("(ConnectionHandle %p, Option %d, Value %p)\n", ConnectionHandle, Option, Value);
Alexandre Julliard's avatar
Alexandre Julliard committed
1285

1286 1287 1288 1289 1290 1291
    if (!pSQLGetConnectOption) return SQL_ERROR;

    ret = pSQLGetConnectOption(ConnectionHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1292 1293 1294 1295

/*************************************************************************
 *				SQLGetCursorName           [ODBC32.017]
 */
1296 1297
SQLRETURN WINAPI ODBC32_SQLGetCursorName(SQLHSTMT StatementHandle, SQLCHAR *CursorName, SQLSMALLINT BufferLength,
                                         SQLSMALLINT *NameLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1298
{
1299
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1300

1301 1302 1303 1304
    TRACE("(StatementHandle %p, CursorName %p, BufferLength %d, NameLength %p)\n", StatementHandle, CursorName,
          BufferLength, NameLength);

    if (!pSQLGetCursorName) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1305

1306 1307 1308 1309
    ret = pSQLGetCursorName(StatementHandle, CursorName, BufferLength, NameLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1310 1311 1312 1313

/*************************************************************************
 *				SQLGetData           [ODBC32.043]
 */
1314 1315
SQLRETURN WINAPI ODBC32_SQLGetData(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
                                   SQLPOINTER TargetValue, SQLLEN BufferLength, SQLLEN *StrLen_or_Ind)
Alexandre Julliard's avatar
Alexandre Julliard committed
1316
{
1317
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1318

1319 1320
    TRACE("(StatementHandle %p, ColumnNumber %d, TargetType %d, TargetValue %p, BufferLength %s, StrLen_or_Ind %p)\n",
          StatementHandle, ColumnNumber, TargetType, TargetValue, debugstr_sqllen(BufferLength), StrLen_or_Ind);
Alexandre Julliard's avatar
Alexandre Julliard committed
1321

1322 1323 1324 1325 1326 1327
    if (!pSQLGetData) return SQL_ERROR;

    ret = pSQLGetData(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1328 1329 1330 1331

/*************************************************************************
 *				SQLGetDescField           [ODBC32.033]
 */
1332 1333
SQLRETURN WINAPI ODBC32_SQLGetDescField(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
                                        SQLPOINTER Value, SQLINTEGER BufferLength, SQLINTEGER *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1334
{
1335
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1336

1337 1338
    TRACE("(DescriptorHandle %p, RecNumber %d, FieldIdentifier %d, Value %p, BufferLength %d, StringLength %p)\n",
          DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength, StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1339

1340 1341 1342 1343 1344 1345
    if (!pSQLGetDescField) return SQL_ERROR;

    ret = pSQLGetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1346 1347 1348 1349

/*************************************************************************
 *				SQLGetDescRec           [ODBC32.034]
 */
1350 1351 1352 1353
SQLRETURN WINAPI ODBC32_SQLGetDescRec(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLCHAR *Name,
                                      SQLSMALLINT BufferLength, SQLSMALLINT *StringLength, SQLSMALLINT *Type,
                                      SQLSMALLINT *SubType, SQLLEN *Length, SQLSMALLINT *Precision,
                                      SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
Alexandre Julliard's avatar
Alexandre Julliard committed
1354
{
1355
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1356

1357 1358 1359
    TRACE("(DescriptorHandle %p, RecNumber %d, Name %p, BufferLength %d, StringLength %p, Type %p, SubType %p,"
          " Length %p, Precision %p, Scale %p, Nullable %p)\n", DescriptorHandle, RecNumber, Name, BufferLength,
          StringLength, Type, SubType, Length, Precision, Scale, Nullable);
Alexandre Julliard's avatar
Alexandre Julliard committed
1360

1361 1362 1363 1364 1365 1366 1367
    if (!pSQLGetDescRec) return SQL_ERROR;

    ret = pSQLGetDescRec(DescriptorHandle, RecNumber, Name, BufferLength, StringLength, Type, SubType, Length,
                         Precision, Scale, Nullable);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1368 1369 1370 1371

/*************************************************************************
 *				SQLGetDiagField           [ODBC32.035]
 */
1372 1373 1374
SQLRETURN WINAPI ODBC32_SQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber,
                                        SQLSMALLINT DiagIdentifier, SQLPOINTER DiagInfo, SQLSMALLINT BufferLength,
                                        SQLSMALLINT *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1375
{
1376
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1377

1378 1379
    TRACE("(HandleType %d, Handle %p, RecNumber %d, DiagIdentifier %d, DiagInfo %p, BufferLength %d,"
          " StringLength %p)\n", HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1380

1381 1382 1383 1384 1385 1386
    if (!pSQLGetDiagField) return SQL_ERROR;

    ret = pSQLGetDiagField(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1387 1388 1389 1390

/*************************************************************************
 *				SQLGetDiagRec           [ODBC32.036]
 */
1391 1392 1393
SQLRETURN WINAPI ODBC32_SQLGetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber,
                                      SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText,
                                      SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1394
{
1395
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1396

1397 1398 1399
    TRACE("(HandleType %d, Handle %p, RecNumber %d, Sqlstate %p, NativeError %p, MessageText %p, BufferLength %d,"
          " TextLength %p)\n", HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength,
          TextLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1400

1401 1402 1403 1404 1405 1406
    if (!pSQLGetDiagRec) return SQL_ERROR;

    ret = pSQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1407 1408 1409 1410

/*************************************************************************
 *				SQLGetEnvAttr           [ODBC32.037]
 */
1411 1412
SQLRETURN WINAPI ODBC32_SQLGetEnvAttr(SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                      SQLINTEGER BufferLength, SQLINTEGER *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1413
{
1414
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1415

1416 1417 1418 1419
    TRACE("(EnvironmentHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n",
          EnvironmentHandle, Attribute, Value, BufferLength, StringLength);

    if (!pSQLGetEnvAttr) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1420

1421 1422 1423 1424
    ret = pSQLGetEnvAttr(EnvironmentHandle, Attribute, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1425 1426 1427 1428

/*************************************************************************
 *				SQLGetFunctions           [ODBC32.044]
 */
1429
SQLRETURN WINAPI ODBC32_SQLGetFunctions(SQLHDBC ConnectionHandle, SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported)
Alexandre Julliard's avatar
Alexandre Julliard committed
1430
{
1431
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1432

1433
    TRACE("(ConnectionHandle %p, FunctionId %d, Supported %p)\n", ConnectionHandle, FunctionId, Supported);
Alexandre Julliard's avatar
Alexandre Julliard committed
1434

1435 1436 1437 1438 1439 1440
    if (!pSQLGetFunctions) return SQL_ERROR;

    ret = pSQLGetFunctions(ConnectionHandle, FunctionId, Supported);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1441 1442 1443 1444

/*************************************************************************
 *				SQLGetInfo           [ODBC32.045]
 */
1445 1446
SQLRETURN WINAPI ODBC32_SQLGetInfo(SQLHDBC ConnectionHandle, SQLUSMALLINT InfoType, SQLPOINTER InfoValue,
                                   SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1447
{
1448
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1449

1450 1451
    TRACE("(ConnectionHandle, %p, InfoType %d, InfoValue %p, BufferLength %d, StringLength %p)\n", ConnectionHandle,
          InfoType, InfoValue, BufferLength, StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1452

1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
    if (!InfoValue)
    {
        WARN("Unexpected NULL InfoValue address\n");
        return SQL_ERROR;
    }

    if (!pSQLGetInfo) return SQL_ERROR;

    ret = pSQLGetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1465 1466

/*************************************************************************
1467
 *				SQLGetStmtAttr           [ODBC32.038]
Alexandre Julliard's avatar
Alexandre Julliard committed
1468
 */
1469 1470
SQLRETURN WINAPI ODBC32_SQLGetStmtAttr(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                       SQLINTEGER BufferLength, SQLINTEGER *StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1471
{
1472
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1473

1474 1475
    TRACE("(StatementHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", StatementHandle,
          Attribute, Value, BufferLength, StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1476

1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
    if (!Value)
    {
        WARN("Unexpected NULL Value return address\n");
        return SQL_ERROR;
    }

    if (!pSQLGetStmtAttr) return SQL_ERROR;

    ret = pSQLGetStmtAttr(StatementHandle, Attribute, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1489 1490 1491 1492

/*************************************************************************
 *				SQLGetStmtOption           [ODBC32.046]
 */
1493
SQLRETURN WINAPI ODBC32_SQLGetStmtOption(SQLHSTMT StatementHandle, SQLUSMALLINT Option, SQLPOINTER Value)
Alexandre Julliard's avatar
Alexandre Julliard committed
1494
{
1495
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1496

1497
    TRACE("(StatementHandle %p, Option %d, Value %p)\n", StatementHandle, Option, Value);
Alexandre Julliard's avatar
Alexandre Julliard committed
1498

1499 1500 1501 1502 1503 1504
    if (!pSQLGetStmtOption) return SQL_ERROR;

    ret = pSQLGetStmtOption(StatementHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1505 1506

/*************************************************************************
1507
 *				SQLGetTypeInfo           [ODBC32.047]
Alexandre Julliard's avatar
Alexandre Julliard committed
1508
 */
1509
SQLRETURN WINAPI ODBC32_SQLGetTypeInfo(SQLHSTMT StatementHandle, SQLSMALLINT DataType)
Alexandre Julliard's avatar
Alexandre Julliard committed
1510
{
1511
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1512

1513
    TRACE("(StatementHandle %p, DataType %d)\n", StatementHandle, DataType);
Alexandre Julliard's avatar
Alexandre Julliard committed
1514

1515 1516 1517 1518 1519 1520
    if (!pSQLGetTypeInfo) return SQL_ERROR;

    ret = pSQLGetTypeInfo(StatementHandle, DataType);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1521 1522 1523 1524

/*************************************************************************
 *				SQLNumResultCols           [ODBC32.018]
 */
1525
SQLRETURN WINAPI ODBC32_SQLNumResultCols(SQLHSTMT StatementHandle, SQLSMALLINT *ColumnCount)
Alexandre Julliard's avatar
Alexandre Julliard committed
1526
{
1527
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1528

1529
    TRACE("(StatementHandle %p, ColumnCount %p)\n", StatementHandle, ColumnCount);
Alexandre Julliard's avatar
Alexandre Julliard committed
1530

1531 1532 1533 1534 1535 1536
    if (!pSQLNumResultCols) return SQL_ERROR;

    ret = pSQLNumResultCols(StatementHandle, ColumnCount);
    TRACE("Returning %d ColumnCount %d\n", ret, *ColumnCount);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1537 1538 1539 1540

/*************************************************************************
 *				SQLParamData           [ODBC32.048]
 */
1541
SQLRETURN WINAPI ODBC32_SQLParamData(SQLHSTMT StatementHandle, SQLPOINTER *Value)
Alexandre Julliard's avatar
Alexandre Julliard committed
1542
{
1543
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1544

1545 1546 1547
    TRACE("(StatementHandle %p, Value %p)\n", StatementHandle, Value);

    if (!pSQLParamData) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1548

1549 1550 1551 1552
    ret = pSQLParamData(StatementHandle, Value);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1553 1554 1555 1556

/*************************************************************************
 *				SQLPrepare           [ODBC32.019]
 */
1557
SQLRETURN WINAPI ODBC32_SQLPrepare(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1558
{
1559
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1560

1561 1562
    TRACE("(StatementHandle %p, StatementText %s, TextLength %d)\n", StatementHandle,
          debugstr_an((const char *)StatementText, TextLength), TextLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1563

1564 1565 1566 1567 1568 1569
    if (!pSQLPrepare) return SQL_ERROR;

    ret = pSQLPrepare(StatementHandle, StatementText, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1570 1571 1572 1573

/*************************************************************************
 *				SQLPutData           [ODBC32.049]
 */
1574
SQLRETURN WINAPI ODBC32_SQLPutData(SQLHSTMT StatementHandle, SQLPOINTER Data, SQLLEN StrLen_or_Ind)
Alexandre Julliard's avatar
Alexandre Julliard committed
1575
{
1576
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1577

1578 1579 1580
    TRACE("(StatementHandle %p, Data %p, StrLen_or_Ind %s)\n", StatementHandle, Data, debugstr_sqllen(StrLen_or_Ind));

    if (!pSQLPutData) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1581

1582 1583 1584 1585
    ret = pSQLPutData(StatementHandle, Data, StrLen_or_Ind);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1586 1587 1588 1589

/*************************************************************************
 *				SQLRowCount           [ODBC32.020]
 */
1590
SQLRETURN WINAPI ODBC32_SQLRowCount(SQLHSTMT StatementHandle, SQLLEN *RowCount)
Alexandre Julliard's avatar
Alexandre Julliard committed
1591
{
1592
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1593

1594 1595 1596
    TRACE("(StatementHandle %p, RowCount %p)\n", StatementHandle, RowCount);

    if (!pSQLRowCount) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1597

1598 1599 1600 1601 1602
    ret = pSQLRowCount(StatementHandle, RowCount);
    if (ret == SQL_SUCCESS && RowCount) TRACE(" RowCount %s\n", debugstr_sqllen(*RowCount));
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1603 1604 1605 1606

/*************************************************************************
 *				SQLSetConnectAttr           [ODBC32.039]
 */
1607 1608
SQLRETURN WINAPI ODBC32_SQLSetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                          SQLINTEGER StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1609
{
1610
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1611

1612 1613
    TRACE("(ConnectionHandle %p, Attribute %d, Value %p, StringLength %d)\n", ConnectionHandle, Attribute, Value,
          StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1614

1615 1616 1617 1618 1619 1620
    if (!pSQLSetConnectAttr) return SQL_ERROR;

    ret = pSQLSetConnectAttr(ConnectionHandle, Attribute, Value, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1621 1622 1623 1624

/*************************************************************************
 *				SQLSetConnectOption           [ODBC32.050]
 */
1625
SQLRETURN WINAPI ODBC32_SQLSetConnectOption(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLULEN Value)
Alexandre Julliard's avatar
Alexandre Julliard committed
1626
{
1627
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1628

1629
    TRACE("(ConnectionHandle %p, Option %d, Value %s)\n", ConnectionHandle, Option, debugstr_sqlulen(Value));
Alexandre Julliard's avatar
Alexandre Julliard committed
1630

1631 1632 1633 1634 1635 1636
    if (!pSQLSetConnectOption) return SQL_ERROR;

    ret = pSQLSetConnectOption(ConnectionHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1637 1638 1639 1640

/*************************************************************************
 *				SQLSetCursorName           [ODBC32.021]
 */
1641
SQLRETURN WINAPI ODBC32_SQLSetCursorName(SQLHSTMT StatementHandle, SQLCHAR *CursorName, SQLSMALLINT NameLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1642
{
1643
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1644

1645 1646 1647 1648
    TRACE("(StatementHandle %p, CursorName %s, NameLength %d)\n", StatementHandle,
          debugstr_an((const char *)CursorName, NameLength), NameLength);

    if (!pSQLSetCursorName) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1649

1650 1651 1652 1653
    ret = pSQLSetCursorName(StatementHandle, CursorName, NameLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1654 1655 1656 1657

/*************************************************************************
 *				SQLSetDescField           [ODBC32.073]
 */
1658 1659
SQLRETURN WINAPI ODBC32_SQLSetDescField(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
                                        SQLPOINTER Value, SQLINTEGER BufferLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1660
{
1661
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1662

1663 1664 1665 1666
    TRACE("(DescriptorHandle %p, RecNumber %d, FieldIdentifier %d, Value %p, BufferLength %d)\n", DescriptorHandle,
          RecNumber, FieldIdentifier, Value, BufferLength);

    if (!pSQLSetDescField) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1667

1668 1669 1670 1671
    ret = pSQLSetDescField(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1672 1673 1674 1675

/*************************************************************************
 *				SQLSetDescRec           [ODBC32.074]
 */
1676 1677 1678
SQLRETURN WINAPI ODBC32_SQLSetDescRec(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT Type,
                                      SQLSMALLINT SubType, SQLLEN Length, SQLSMALLINT Precision, SQLSMALLINT Scale,
                                      SQLPOINTER Data, SQLLEN *StringLength, SQLLEN *Indicator)
Alexandre Julliard's avatar
Alexandre Julliard committed
1679
{
1680
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1681

1682 1683 1684 1685 1686
    TRACE("(DescriptorHandle %p, RecNumber %d, Type %d, SubType %d, Length %s, Precision %d, Scale %d, Data %p,"
          " StringLength %p, Indicator %p)\n", DescriptorHandle, RecNumber, Type, SubType, debugstr_sqllen(Length),
          Precision, Scale, Data, StringLength, Indicator);

    if (!pSQLSetDescRec) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1687

1688 1689 1690 1691 1692
    ret = pSQLSetDescRec(DescriptorHandle, RecNumber, Type, SubType, Length, Precision, Scale, Data,
                         StringLength, Indicator);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1693 1694 1695 1696

/*************************************************************************
 *				SQLSetEnvAttr           [ODBC32.075]
 */
1697 1698
SQLRETURN WINAPI ODBC32_SQLSetEnvAttr(SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                      SQLINTEGER StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1699
{
1700
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1701

1702 1703
    TRACE("(EnvironmentHandle %p, Attribute %d, Value %p, StringLength %d)\n", EnvironmentHandle, Attribute, Value,
          StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1704

1705 1706 1707 1708 1709 1710
    if (!pSQLSetEnvAttr) return SQL_ERROR;

    ret = pSQLSetEnvAttr(EnvironmentHandle, Attribute, Value, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1711 1712 1713 1714

/*************************************************************************
 *				SQLSetParam           [ODBC32.022]
 */
1715 1716 1717
SQLRETURN WINAPI ODBC32_SQLSetParam(SQLHSTMT StatementHandle, SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
                                    SQLSMALLINT ParameterType, SQLULEN LengthPrecision, SQLSMALLINT ParameterScale,
                                    SQLPOINTER ParameterValue, SQLLEN *StrLen_or_Ind)
Alexandre Julliard's avatar
Alexandre Julliard committed
1718
{
1719
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1720

1721 1722 1723 1724 1725
    TRACE("(StatementHandle %p, ParameterNumber %d, ValueType %d, ParameterType %d, LengthPrecision %s,"
          " ParameterScale %d, ParameterValue %p, StrLen_or_Ind %p)\n", StatementHandle, ParameterNumber, ValueType,
          ParameterType, debugstr_sqlulen(LengthPrecision), ParameterScale, ParameterValue, StrLen_or_Ind);

    if (!pSQLSetParam) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1726

1727 1728 1729 1730 1731
    ret = pSQLSetParam(StatementHandle, ParameterNumber, ValueType, ParameterType, LengthPrecision,
                       ParameterScale, ParameterValue, StrLen_or_Ind);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1732 1733 1734 1735

/*************************************************************************
 *				SQLSetStmtAttr           [ODBC32.076]
 */
1736 1737
SQLRETURN WINAPI ODBC32_SQLSetStmtAttr(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                       SQLINTEGER StringLength)
Alexandre Julliard's avatar
Alexandre Julliard committed
1738
{
1739
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1740

1741 1742
    TRACE("(StatementHandle %p, Attribute %d, Value %p, StringLength %d)\n", StatementHandle, Attribute, Value,
          StringLength);
Alexandre Julliard's avatar
Alexandre Julliard committed
1743

1744 1745 1746 1747 1748 1749
    if (!pSQLSetStmtAttr) return SQL_ERROR;

    ret = pSQLSetStmtAttr(StatementHandle, Attribute, Value, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1750 1751 1752 1753

/*************************************************************************
 *				SQLSetStmtOption           [ODBC32.051]
 */
1754
SQLRETURN WINAPI ODBC32_SQLSetStmtOption(SQLHSTMT StatementHandle, SQLUSMALLINT Option, SQLULEN Value)
Alexandre Julliard's avatar
Alexandre Julliard committed
1755
{
1756
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1757

1758 1759 1760
    TRACE("(StatementHandle %p, Option %d, Value %s)\n", StatementHandle, Option, debugstr_sqlulen(Value));

    if (!pSQLSetStmtOption) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1761

1762 1763 1764 1765
    ret = pSQLSetStmtOption(StatementHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1766 1767 1768 1769

/*************************************************************************
 *				SQLSpecialColumns           [ODBC32.052]
 */
1770 1771 1772 1773
SQLRETURN WINAPI ODBC32_SQLSpecialColumns(SQLHSTMT StatementHandle, SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName,
                                          SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
                                          SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
                                          SQLUSMALLINT Nullable)
Alexandre Julliard's avatar
Alexandre Julliard committed
1774
{
1775
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1776

1777 1778 1779 1780 1781
    TRACE("(StatementHandle %p, IdentifierType %d, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d,"
          " TableName %s, NameLength3 %d, Scope %d, Nullable %d)\n", StatementHandle, IdentifierType,
          debugstr_an((const char *)CatalogName, NameLength1), NameLength1,
          debugstr_an((const char *)SchemaName, NameLength2), NameLength2,
          debugstr_an((const char *)TableName, NameLength3), NameLength3, Scope, Nullable);
Alexandre Julliard's avatar
Alexandre Julliard committed
1782

1783 1784 1785 1786 1787 1788 1789
    if (!pSQLSpecialColumns) return SQL_ERROR;

    ret = pSQLSpecialColumns(StatementHandle, IdentifierType, CatalogName, NameLength1, SchemaName,
                             NameLength2, TableName, NameLength3, Scope, Nullable);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1790 1791

/*************************************************************************
1792
 *				SQLStatistics           [ODBC32.053]
Alexandre Julliard's avatar
Alexandre Julliard committed
1793
 */
1794 1795 1796
SQLRETURN WINAPI ODBC32_SQLStatistics(SQLHSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
                                      SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName,
                                      SQLSMALLINT NameLength3, SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
Alexandre Julliard's avatar
Alexandre Julliard committed
1797
{
1798
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1799

1800 1801 1802 1803 1804
    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d SchemaName %s, NameLength2 %d, TableName %s"
          " NameLength3 %d, Unique %d, Reserved %d)\n", StatementHandle,
          debugstr_an((const char *)CatalogName, NameLength1), NameLength1,
          debugstr_an((const char *)SchemaName, NameLength2), NameLength2,
          debugstr_an((const char *)TableName, NameLength3), NameLength3, Unique, Reserved);
Alexandre Julliard's avatar
Alexandre Julliard committed
1805

1806 1807 1808 1809 1810 1811 1812
    if (!pSQLStatistics) return SQL_ERROR;

    ret = pSQLStatistics(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName,
                         NameLength3, Unique, Reserved);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1813 1814 1815 1816

/*************************************************************************
 *				SQLTables           [ODBC32.054]
 */
1817 1818 1819
SQLRETURN WINAPI ODBC32_SQLTables(SQLHSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
                                  SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName,
                                  SQLSMALLINT NameLength3, SQLCHAR *TableType, SQLSMALLINT NameLength4)
Alexandre Julliard's avatar
Alexandre Julliard committed
1820
{
1821
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1822

1823 1824 1825 1826 1827 1828 1829 1830
    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d, TableName %s,"
          " NameLength3 %d, TableType %s, NameLength4 %d)\n", StatementHandle,
          debugstr_an((const char *)CatalogName, NameLength1), NameLength1,
          debugstr_an((const char *)SchemaName, NameLength2), NameLength2,
          debugstr_an((const char *)TableName, NameLength3), NameLength3,
          debugstr_an((const char *)TableType, NameLength4), NameLength4);

    if (!pSQLTables) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1831

1832 1833 1834 1835 1836
    ret = pSQLTables(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3,
                     TableType, NameLength4);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1837 1838 1839 1840

/*************************************************************************
 *				SQLTransact           [ODBC32.023]
 */
1841
SQLRETURN WINAPI ODBC32_SQLTransact(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLUSMALLINT CompletionType)
Alexandre Julliard's avatar
Alexandre Julliard committed
1842
{
1843
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1844

1845 1846 1847 1848
    TRACE("(EnvironmentHandle %p, ConnectionHandle %p, CompletionType %d)\n", EnvironmentHandle, ConnectionHandle,
          CompletionType);

    if (!pSQLTransact) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1849

1850 1851 1852 1853
    ret = pSQLTransact(EnvironmentHandle, ConnectionHandle, CompletionType);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1854 1855 1856 1857

/*************************************************************************
 *				SQLBrowseConnect           [ODBC32.055]
 */
1858 1859 1860
SQLRETURN WINAPI ODBC32_SQLBrowseConnect(SQLHDBC hdbc, SQLCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn,
                                         SQLCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax,
                                         SQLSMALLINT *pcbConnStrOut)
Alexandre Julliard's avatar
Alexandre Julliard committed
1861
{
1862
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1863

1864 1865 1866
    TRACE("(hdbc %p, szConnStrIn %s, cbConnStrIn %d, szConnStrOut %p, cbConnStrOutMax %d, pcbConnStrOut %p)\n",
          hdbc, debugstr_an((const char *)szConnStrIn, cbConnStrIn), cbConnStrIn, szConnStrOut, cbConnStrOutMax,
          pcbConnStrOut);
Alexandre Julliard's avatar
Alexandre Julliard committed
1867

1868 1869 1870 1871 1872 1873
    if (!pSQLBrowseConnect) return SQL_ERROR;

    ret = pSQLBrowseConnect(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1874 1875 1876 1877

/*************************************************************************
 *				SQLBulkOperations           [ODBC32.078]
 */
1878
SQLRETURN WINAPI ODBC32_SQLBulkOperations(SQLHSTMT StatementHandle, SQLSMALLINT Operation)
Alexandre Julliard's avatar
Alexandre Julliard committed
1879
{
1880
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1881

1882 1883 1884
    TRACE("(StatementHandle %p, Operation %d)\n", StatementHandle, Operation);

    if (!pSQLBulkOperations) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1885

1886 1887 1888 1889
    ret = pSQLBulkOperations(StatementHandle, Operation);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1890 1891 1892 1893

/*************************************************************************
 *				SQLColAttributes           [ODBC32.006]
 */
1894 1895 1896
SQLRETURN WINAPI ODBC32_SQLColAttributes(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLUSMALLINT fDescType,
                                         SQLPOINTER rgbDesc, SQLSMALLINT cbDescMax, SQLSMALLINT *pcbDesc,
                                         SQLLEN *pfDesc)
Alexandre Julliard's avatar
Alexandre Julliard committed
1897
{
1898
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1899

1900 1901
    TRACE("(hstmt %p, icol %d, fDescType %d, rgbDesc %p, cbDescMax %d, pcbDesc %p, pfDesc %p)\n", hstmt, icol,
          fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc);
Alexandre Julliard's avatar
Alexandre Julliard committed
1902

1903 1904 1905 1906 1907 1908
    if (!pSQLColAttributes) return SQL_ERROR;

    ret = pSQLColAttributes(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1909 1910 1911 1912

/*************************************************************************
 *				SQLColumnPrivileges           [ODBC32.056]
 */
1913 1914 1915
SQLRETURN WINAPI ODBC32_SQLColumnPrivileges(SQLHSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                            SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szTableName,
                                            SQLSMALLINT cbTableName, SQLCHAR *szColumnName, SQLSMALLINT cbColumnName)
Alexandre Julliard's avatar
Alexandre Julliard committed
1916
{
1917
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1918

1919 1920 1921 1922 1923 1924 1925 1926
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d, szColumnName %s, cbColumnName %d)\n", hstmt,
          debugstr_an((const char *)szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_an((const char *)szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_an((const char *)szTableName, cbTableName), cbTableName,
          debugstr_an((const char *)szColumnName, cbColumnName), cbColumnName);

    if (!pSQLColumnPrivileges) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
1927

1928 1929 1930 1931 1932
    ret = pSQLColumnPrivileges(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName,
                               szTableName, cbTableName, szColumnName, cbColumnName);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1933 1934 1935 1936

/*************************************************************************
 *				SQLDescribeParam          [ODBC32.058]
 */
1937 1938
SQLRETURN WINAPI ODBC32_SQLDescribeParam(SQLHSTMT hstmt, SQLUSMALLINT ipar, SQLSMALLINT *pfSqlType,
                                         SQLULEN *pcbParamDef, SQLSMALLINT *pibScale, SQLSMALLINT *pfNullable)
Alexandre Julliard's avatar
Alexandre Julliard committed
1939
{
1940
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1941

1942 1943
    TRACE("(hstmt %p, ipar %d, pfSqlType %p, pcbParamDef %p, pibScale %p, pfNullable %p)\n", hstmt, ipar,
          pfSqlType, pcbParamDef, pibScale, pfNullable);
Alexandre Julliard's avatar
Alexandre Julliard committed
1944

1945 1946 1947 1948 1949 1950
    if (!pSQLDescribeParam) return SQL_ERROR;

    ret = pSQLDescribeParam(hstmt, ipar, pfSqlType, pcbParamDef, pibScale, pfNullable);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1951 1952 1953 1954

/*************************************************************************
 *				SQLExtendedFetch           [ODBC32.059]
 */
1955 1956
SQLRETURN WINAPI ODBC32_SQLExtendedFetch(SQLHSTMT hstmt, SQLUSMALLINT fFetchType, SQLLEN irow, SQLULEN *pcrow,
                                         SQLUSMALLINT *rgfRowStatus)
Alexandre Julliard's avatar
Alexandre Julliard committed
1957
{
1958
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1959

1960 1961
    TRACE("(hstmt %p, fFetchType %d, irow %s, pcrow %p, rgfRowStatus %p)\n", hstmt, fFetchType, debugstr_sqllen(irow),
          pcrow, rgfRowStatus);
Alexandre Julliard's avatar
Alexandre Julliard committed
1962

1963 1964 1965 1966 1967 1968
    if (!pSQLExtendedFetch) return SQL_ERROR;

    ret = pSQLExtendedFetch(hstmt, fFetchType, irow, pcrow, rgfRowStatus);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1969 1970 1971 1972

/*************************************************************************
 *				SQLForeignKeys           [ODBC32.060]
 */
1973 1974 1975 1976 1977
SQLRETURN WINAPI ODBC32_SQLForeignKeys(SQLHSTMT hstmt, SQLCHAR *szPkCatalogName, SQLSMALLINT cbPkCatalogName,
                                       SQLCHAR *szPkSchemaName, SQLSMALLINT cbPkSchemaName, SQLCHAR *szPkTableName,
                                       SQLSMALLINT cbPkTableName, SQLCHAR *szFkCatalogName,
                                       SQLSMALLINT cbFkCatalogName, SQLCHAR *szFkSchemaName,
                                       SQLSMALLINT cbFkSchemaName, SQLCHAR *szFkTableName, SQLSMALLINT cbFkTableName)
Alexandre Julliard's avatar
Alexandre Julliard committed
1978
{
1979
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1980

1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
    TRACE("(hstmt %p, szPkCatalogName %s, cbPkCatalogName %d, szPkSchemaName %s, cbPkSchemaName %d,"
          " szPkTableName %s, cbPkTableName %d, szFkCatalogName %s, cbFkCatalogName %d, szFkSchemaName %s,"
          " cbFkSchemaName %d, szFkTableName %s, cbFkTableName %d)\n", hstmt,
          debugstr_an((const char *)szPkCatalogName, cbPkCatalogName), cbPkCatalogName,
          debugstr_an((const char *)szPkSchemaName, cbPkSchemaName), cbPkSchemaName,
          debugstr_an((const char *)szPkTableName, cbPkTableName), cbPkTableName,
          debugstr_an((const char *)szFkCatalogName, cbFkCatalogName), cbFkCatalogName,
          debugstr_an((const char *)szFkSchemaName, cbFkSchemaName), cbFkSchemaName,
          debugstr_an((const char *)szFkTableName, cbFkTableName), cbFkTableName);

    if (!pSQLForeignKeys) return SQL_ERROR;

    ret = pSQLForeignKeys(hstmt, szPkCatalogName, cbPkCatalogName, szPkSchemaName, cbPkSchemaName, szPkTableName,
                          cbPkTableName, szFkCatalogName, cbFkCatalogName, szFkSchemaName, cbFkSchemaName,
                          szFkTableName, cbFkTableName);
    TRACE("Returning %d\n", ret);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1998 1999 2000 2001 2002
}

/*************************************************************************
 *				SQLMoreResults           [ODBC32.061]
 */
2003
SQLRETURN WINAPI ODBC32_SQLMoreResults(SQLHSTMT StatementHandle)
Alexandre Julliard's avatar
Alexandre Julliard committed
2004
{
2005
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2006

2007
    TRACE("(%p)\n", StatementHandle);
Alexandre Julliard's avatar
Alexandre Julliard committed
2008

2009 2010 2011 2012 2013 2014
    if (!pSQLMoreResults) return SQL_ERROR;

    ret = pSQLMoreResults(StatementHandle);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2015 2016 2017 2018

/*************************************************************************
 *				SQLNativeSql           [ODBC32.062]
 */
2019 2020
SQLRETURN WINAPI ODBC32_SQLNativeSql(SQLHDBC hdbc, SQLCHAR *szSqlStrIn, SQLINTEGER cbSqlStrIn, SQLCHAR *szSqlStr,
                                     SQLINTEGER cbSqlStrMax, SQLINTEGER *pcbSqlStr)
Alexandre Julliard's avatar
Alexandre Julliard committed
2021
{
2022
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2023

2024 2025
    TRACE("(hdbc %p, szSqlStrIn %s, cbSqlStrIn %d, szSqlStr %p, cbSqlStrMax %d, pcbSqlStr %p)\n", hdbc,
          debugstr_an((const char *)szSqlStrIn, cbSqlStrIn), cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
2026

2027 2028 2029 2030 2031 2032
    if (!pSQLNativeSql) return SQL_ERROR;

    ret = pSQLNativeSql(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2033 2034 2035 2036

/*************************************************************************
 *				SQLNumParams           [ODBC32.063]
 */
2037
SQLRETURN WINAPI ODBC32_SQLNumParams(SQLHSTMT hstmt, SQLSMALLINT *pcpar)
Alexandre Julliard's avatar
Alexandre Julliard committed
2038
{
2039
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2040

2041 2042 2043
    TRACE("(hstmt %p, pcpar %p)\n", hstmt, pcpar);

    if (!pSQLNumParams) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
2044

2045 2046 2047 2048
    ret = pSQLNumParams(hstmt, pcpar);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2049 2050 2051 2052

/*************************************************************************
 *				SQLParamOptions           [ODBC32.064]
 */
2053
SQLRETURN WINAPI ODBC32_SQLParamOptions(SQLHSTMT hstmt, SQLULEN crow, SQLULEN *pirow)
Alexandre Julliard's avatar
Alexandre Julliard committed
2054
{
2055
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2056

2057
    TRACE("(hstmt %p, crow %s, pirow %p)\n", hstmt, debugstr_sqlulen(crow), pirow);
Alexandre Julliard's avatar
Alexandre Julliard committed
2058

2059 2060 2061 2062 2063 2064
    if (!pSQLParamOptions) return SQL_ERROR;

    ret = pSQLParamOptions(hstmt, crow, pirow);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2065 2066 2067 2068

/*************************************************************************
 *				SQLPrimaryKeys           [ODBC32.065]
 */
2069 2070 2071
SQLRETURN WINAPI ODBC32_SQLPrimaryKeys(SQLHSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                       SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szTableName,
                                       SQLSMALLINT cbTableName)
Alexandre Julliard's avatar
Alexandre Julliard committed
2072
{
2073
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2074

2075 2076 2077 2078 2079
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d)\n", hstmt,
          debugstr_an((const char *)szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_an((const char *)szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_an((const char *)szTableName, cbTableName), cbTableName);
Alexandre Julliard's avatar
Alexandre Julliard committed
2080

2081 2082 2083 2084 2085 2086
    if (!pSQLPrimaryKeys) return SQL_ERROR;

    ret = pSQLPrimaryKeys(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szTableName, cbTableName);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2087 2088 2089 2090

/*************************************************************************
 *				SQLProcedureColumns           [ODBC32.066]
 */
2091 2092 2093
SQLRETURN WINAPI ODBC32_SQLProcedureColumns(SQLHSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                            SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szProcName,
                                            SQLSMALLINT cbProcName, SQLCHAR *szColumnName, SQLSMALLINT cbColumnName)
Alexandre Julliard's avatar
Alexandre Julliard committed
2094
{
2095
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2096

2097 2098 2099 2100 2101 2102 2103 2104
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szProcName %s,"
          " cbProcName %d, szColumnName %s, cbColumnName %d)\n", hstmt,
          debugstr_an((const char *)szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_an((const char *)szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_an((const char *)szProcName, cbProcName), cbProcName,
          debugstr_an((const char *)szColumnName, cbColumnName), cbColumnName);

    if (!pSQLProcedureColumns) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
2105

2106 2107 2108 2109 2110
    ret = pSQLProcedureColumns(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szProcName,
                               cbProcName, szColumnName, cbColumnName);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2111 2112 2113 2114

/*************************************************************************
 *				SQLProcedures           [ODBC32.067]
 */
2115 2116 2117
SQLRETURN WINAPI ODBC32_SQLProcedures(SQLHSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                      SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szProcName,
                                      SQLSMALLINT cbProcName)
Alexandre Julliard's avatar
Alexandre Julliard committed
2118
{
2119
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2120

2121 2122 2123 2124 2125
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szProcName %s,"
          " cbProcName %d)\n", hstmt,
          debugstr_an((const char *)szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_an((const char *)szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_an((const char *)szProcName, cbProcName), cbProcName);
Alexandre Julliard's avatar
Alexandre Julliard committed
2126

2127 2128 2129 2130 2131 2132
    if (!pSQLProcedures) return SQL_ERROR;

    ret = pSQLProcedures(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szProcName, cbProcName);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2133 2134 2135 2136

/*************************************************************************
 *				SQLSetPos           [ODBC32.068]
 */
2137
SQLRETURN WINAPI ODBC32_SQLSetPos(SQLHSTMT hstmt, SQLSETPOSIROW irow, SQLUSMALLINT fOption, SQLUSMALLINT fLock)
Alexandre Julliard's avatar
Alexandre Julliard committed
2138
{
2139
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2140

2141 2142 2143
    TRACE("(hstmt %p, irow %s, fOption %d, fLock %d)\n", hstmt, debugstr_sqlulen(irow), fOption, fLock);

    if (!pSQLSetPos) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
2144

2145 2146 2147 2148
    ret = pSQLSetPos(hstmt, irow, fOption, fLock);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2149 2150 2151 2152

/*************************************************************************
 *				SQLTablePrivileges           [ODBC32.070]
 */
2153 2154 2155
SQLRETURN WINAPI ODBC32_SQLTablePrivileges(SQLHSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                           SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szTableName,
                                           SQLSMALLINT cbTableName)
Alexandre Julliard's avatar
Alexandre Julliard committed
2156
{
2157
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2158

2159 2160 2161 2162 2163
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d)\n", hstmt,
          debugstr_an((const char *)szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_an((const char *)szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_an((const char *)szTableName, cbTableName), cbTableName);
Alexandre Julliard's avatar
Alexandre Julliard committed
2164

2165 2166 2167 2168 2169 2170 2171
    if (!pSQLTablePrivileges) return SQL_ERROR;

    ret = pSQLTablePrivileges(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szTableName,
                              cbTableName);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2172 2173 2174 2175

/*************************************************************************
 *				SQLDrivers           [ODBC32.071]
 */
2176 2177 2178 2179
SQLRETURN WINAPI ODBC32_SQLDrivers(SQLHENV EnvironmentHandle, SQLUSMALLINT fDirection, SQLCHAR *szDriverDesc,
                                   SQLSMALLINT cbDriverDescMax, SQLSMALLINT *pcbDriverDesc,
                                   SQLCHAR *szDriverAttributes, SQLSMALLINT cbDriverAttrMax,
                                   SQLSMALLINT *pcbDriverAttr)
Alexandre Julliard's avatar
Alexandre Julliard committed
2180
{
2181
    SQLRETURN ret;
2182

2183 2184 2185
    TRACE("(EnvironmentHandle %p, Direction %d, szDriverDesc %p, cbDriverDescMax %d, pcbDriverDesc %p,"
          " DriverAttributes %p, cbDriverAttrMax %d, pcbDriverAttr %p)\n", EnvironmentHandle, fDirection,
          szDriverDesc, cbDriverDescMax, pcbDriverDesc, szDriverAttributes, cbDriverAttrMax, pcbDriverAttr);
Alexandre Julliard's avatar
Alexandre Julliard committed
2186

2187
    if (!pSQLDrivers) return SQL_ERROR;
2188

2189 2190
    ret = pSQLDrivers(EnvironmentHandle, fDirection, szDriverDesc, cbDriverDescMax, pcbDriverDesc,
                      szDriverAttributes, cbDriverAttrMax, pcbDriverAttr);
2191

2192 2193
    if (ret == SQL_NO_DATA && fDirection == SQL_FETCH_FIRST)
        ERR_(winediag)("No ODBC drivers could be found. Check the settings for your libodbc provider.\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
2194

2195 2196 2197
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2198 2199 2200 2201

/*************************************************************************
 *				SQLBindParameter           [ODBC32.072]
 */
2202 2203 2204 2205
SQLRETURN WINAPI ODBC32_SQLBindParameter(SQLHSTMT hstmt, SQLUSMALLINT ipar, SQLSMALLINT fParamType,
                                         SQLSMALLINT fCType, SQLSMALLINT fSqlType, SQLULEN cbColDef,
                                         SQLSMALLINT ibScale, SQLPOINTER rgbValue, SQLLEN cbValueMax,
                                         SQLLEN *pcbValue)
Alexandre Julliard's avatar
Alexandre Julliard committed
2206
{
2207
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2208

2209 2210 2211 2212 2213
    TRACE("(hstmt %p, ipar %d, fParamType %d, fCType %d, fSqlType %d, cbColDef %s, ibScale %d, rgbValue %p,"
          " cbValueMax %s, pcbValue %p)\n", hstmt, ipar, fParamType, fCType, fSqlType, debugstr_sqlulen(cbColDef),
          ibScale, rgbValue, debugstr_sqllen(cbValueMax), pcbValue);

    if (!pSQLBindParameter) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
2214

2215 2216 2217 2218 2219
    ret = pSQLBindParameter(hstmt, ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax,
                            pcbValue);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2220 2221 2222 2223

/*************************************************************************
 *				SQLDriverConnect           [ODBC32.041]
 */
2224 2225 2226
SQLRETURN WINAPI ODBC32_SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR *ConnectionString, SQLSMALLINT Length,
                                         SQLCHAR *conn_str_out, SQLSMALLINT conn_str_out_max,
                                         SQLSMALLINT *ptr_conn_str_out, SQLUSMALLINT driver_completion)
Alexandre Julliard's avatar
Alexandre Julliard committed
2227
{
2228
    SQLRETURN ret;
2229

2230 2231 2232 2233
    TRACE("(hdbc %p, hwnd %p, ConnectionString %s, Length %d, conn_str_out %p, conn_str_out_max %d,"
          " ptr_conn_str_out %p, driver_completion %d)\n", hdbc, hwnd,
          debugstr_an((const char *)ConnectionString, Length), Length, conn_str_out, conn_str_out_max,
          ptr_conn_str_out, driver_completion);
Alexandre Julliard's avatar
Alexandre Julliard committed
2234

2235
    if (!pSQLDriverConnect) return SQL_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
2236

2237 2238 2239 2240 2241
    ret = pSQLDriverConnect(hdbc, hwnd, ConnectionString, Length, conn_str_out, conn_str_out_max,
                            ptr_conn_str_out, driver_completion);
    TRACE("Returning %d\n", ret);
    return ret;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
2242 2243 2244 2245

/*************************************************************************
 *				SQLSetScrollOptions           [ODBC32.069]
 */
2246 2247
SQLRETURN WINAPI ODBC32_SQLSetScrollOptions(SQLHSTMT statement_handle, SQLUSMALLINT f_concurrency, SQLLEN crow_keyset,
                                            SQLUSMALLINT crow_rowset)
Alexandre Julliard's avatar
Alexandre Julliard committed
2248
{
2249
    SQLRETURN ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2250

2251 2252 2253 2254 2255 2256 2257 2258
    TRACE("(statement_handle %p, f_concurrency %d, crow_keyset %s, crow_rowset %d)\n", statement_handle,
          f_concurrency, debugstr_sqllen(crow_keyset), crow_rowset);

    if (!pSQLSetScrollOptions) return SQL_ERROR;

    ret = pSQLSetScrollOptions(statement_handle, f_concurrency, crow_keyset, crow_rowset);
    TRACE("Returning %d\n", ret);
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
2259 2260
}

2261
static BOOL SQLColAttributes_KnownStringAttribute(SQLUSMALLINT fDescType)
2262
{
2263
    static const SQLUSMALLINT attrList[] =
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
    {
        SQL_COLUMN_OWNER_NAME,
        SQL_COLUMN_QUALIFIER_NAME,
        SQL_COLUMN_LABEL,
        SQL_COLUMN_NAME,
        SQL_COLUMN_TABLE_NAME,
        SQL_COLUMN_TYPE_NAME,
        SQL_DESC_BASE_COLUMN_NAME,
        SQL_DESC_BASE_TABLE_NAME,
        SQL_DESC_CATALOG_NAME,
        SQL_DESC_LABEL,
        SQL_DESC_LITERAL_PREFIX,
        SQL_DESC_LITERAL_SUFFIX,
        SQL_DESC_LOCAL_TYPE_NAME,
        SQL_DESC_NAME,
        SQL_DESC_SCHEMA_NAME,
        SQL_DESC_TABLE_NAME,
        SQL_DESC_TYPE_NAME,
    };
    unsigned int i;

2285
    for (i = 0; i < ARRAY_SIZE(attrList); i++) {
2286
        if (attrList[i] == fDescType) return TRUE;
2287
    }
2288
    return FALSE;
2289 2290 2291 2292 2293
}

/*************************************************************************
 *				SQLColAttributesW          [ODBC32.106]
 */
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
SQLRETURN WINAPI ODBC32_SQLColAttributesW(SQLHSTMT hstmt, SQLUSMALLINT icol, SQLUSMALLINT fDescType,
                                          SQLPOINTER rgbDesc, SQLSMALLINT cbDescMax, SQLSMALLINT *pcbDesc,
                                          SQLLEN *pfDesc)
{
    SQLRETURN ret;

    TRACE("(hstmt %p, icol %d, fDescType %d, rgbDesc %p, cbDescMax %d, pcbDesc %p, pfDesc %p)\n", hstmt, icol,
          fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc);

    if (!pSQLColAttributesW) return SQL_ERROR;

    ret = pSQLColAttributesW(hstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc);

    if (ret == SQL_SUCCESS && SQLColAttributes_KnownStringAttribute(fDescType) && rgbDesc && pcbDesc &&
        *pcbDesc != lstrlenW(rgbDesc) * 2)
    {
        TRACE("CHEAT: resetting name length for ADO\n");
        *pcbDesc = lstrlenW(rgbDesc) * 2;
    }

    TRACE("Returning %d\n", ret);
    return ret;
2316 2317 2318 2319 2320
}

/*************************************************************************
 *				SQLConnectW          [ODBC32.107]
 */
2321 2322 2323
SQLRETURN WINAPI ODBC32_SQLConnectW(SQLHDBC ConnectionHandle, WCHAR *ServerName, SQLSMALLINT NameLength1,
                                    WCHAR *UserName, SQLSMALLINT NameLength2, WCHAR *Authentication,
                                    SQLSMALLINT NameLength3)
2324
{
2325
    SQLRETURN ret;
2326

2327
    TRACE("(ConnectionHandle %p, ServerName %s, NameLength1 %d, UserName %s, NameLength2 %d, Authentication %s,"
2328 2329
          " NameLength3 %d)\n", ConnectionHandle, debugstr_wn(ServerName, NameLength1), NameLength1,
          debugstr_wn(UserName, NameLength2), NameLength2, debugstr_wn(Authentication, NameLength3), NameLength3);
2330

2331
    if (!pSQLConnectW) return SQL_ERROR;
2332

2333 2334 2335
    ret = pSQLConnectW(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3);
    TRACE("Returning %d\n", ret);
    return ret;
2336 2337 2338 2339 2340
}

/*************************************************************************
 *				SQLDescribeColW          [ODBC32.108]
 */
2341 2342 2343
SQLRETURN WINAPI ODBC32_SQLDescribeColW(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, WCHAR *ColumnName,
                                        SQLSMALLINT BufferLength, SQLSMALLINT *NameLength, SQLSMALLINT *DataType,
                                        SQLULEN *ColumnSize, SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
2344
{
2345
    SQLSMALLINT dummy;
2346
    SQLRETURN ret;
2347

2348 2349 2350
    TRACE("(StatementHandle %p, ColumnNumber %d, ColumnName %p, BufferLength %d, NameLength %p, DataType %p,"
          " ColumnSize %p, DecimalDigits %p, Nullable %p)\n", StatementHandle, ColumnNumber, ColumnName,
          BufferLength, NameLength, DataType, ColumnSize, DecimalDigits, Nullable);
2351

2352
    if (!pSQLDescribeColW) return SQL_ERROR;
2353
    if (!NameLength) NameLength = &dummy; /* workaround for drivers that don't accept NULL NameLength */
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367

    ret = pSQLDescribeColW(StatementHandle, ColumnNumber, ColumnName, BufferLength, NameLength, DataType, ColumnSize,
                           DecimalDigits, Nullable);
    if (ret >= 0)
    {
        if (ColumnName && NameLength) TRACE("ColumnName %s\n", debugstr_wn(ColumnName, *NameLength));
        if (DataType) TRACE("DataType %d\n", *DataType);
        if (ColumnSize) TRACE("ColumnSize %s\n", debugstr_sqlulen(*ColumnSize));
        if (DecimalDigits) TRACE("DecimalDigits %d\n", *DecimalDigits);
        if (Nullable) TRACE("Nullable %d\n", *Nullable);
    }

    TRACE("Returning %d\n", ret);
    return ret;
2368 2369 2370 2371 2372
}

/*************************************************************************
 *				SQLErrorW          [ODBC32.110]
 */
2373 2374 2375
SQLRETURN WINAPI ODBC32_SQLErrorW(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle,
                                  WCHAR *Sqlstate, SQLINTEGER *NativeError, WCHAR *MessageText,
                                  SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
2376
{
2377
    SQLRETURN ret;
2378

2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
    TRACE("(EnvironmentHandle %p, ConnectionHandle %p, StatementHandle %p, Sqlstate %p, NativeError %p,"
          " MessageText %p, BufferLength %d, TextLength %p)\n", EnvironmentHandle, ConnectionHandle,
          StatementHandle, Sqlstate, NativeError, MessageText, BufferLength, TextLength);

    if (!pSQLErrorW) return SQL_ERROR;

    ret = pSQLErrorW(EnvironmentHandle, ConnectionHandle, StatementHandle, Sqlstate, NativeError, MessageText,
                     BufferLength, TextLength);

    if (ret == SQL_SUCCESS)
    {
        TRACE(" SQLState %s\n", debugstr_wn(Sqlstate, 5));
        TRACE(" Error %d\n", *NativeError);
        TRACE(" MessageText %s\n", debugstr_wn(MessageText, *TextLength));
    }

    TRACE("Returning %d\n", ret);
    return ret;
2397 2398 2399 2400 2401
}

/*************************************************************************
 *				SQLExecDirectW          [ODBC32.111]
 */
2402
SQLRETURN WINAPI ODBC32_SQLExecDirectW(SQLHSTMT StatementHandle, WCHAR *StatementText, SQLINTEGER TextLength)
2403
{
2404
    SQLRETURN ret;
2405

2406 2407 2408 2409 2410 2411 2412 2413
    TRACE("(StatementHandle %p, StatementText %s, TextLength %d)\n", StatementHandle,
          debugstr_wn(StatementText, TextLength), TextLength);

    if (!pSQLExecDirectW) return SQL_ERROR;

    ret = pSQLExecDirectW(StatementHandle, StatementText, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
2414 2415 2416 2417 2418
}

/*************************************************************************
 *				SQLGetCursorNameW          [ODBC32.117]
 */
2419 2420
SQLRETURN WINAPI ODBC32_SQLGetCursorNameW(SQLHSTMT StatementHandle, WCHAR *CursorName, SQLSMALLINT BufferLength,
                                          SQLSMALLINT *NameLength)
2421
{
2422 2423 2424 2425 2426 2427
    SQLRETURN ret;

    TRACE("(StatementHandle %p, CursorName %p, BufferLength %d, NameLength %p)\n", StatementHandle, CursorName,
          BufferLength, NameLength);

    if (!pSQLGetCursorNameW) return SQL_ERROR;
2428

2429 2430 2431
    ret = pSQLGetCursorNameW(StatementHandle, CursorName, BufferLength, NameLength);
    TRACE("Returning %d\n", ret);
    return ret;
2432 2433 2434 2435 2436
}

/*************************************************************************
 *				SQLPrepareW          [ODBC32.119]
 */
2437
SQLRETURN WINAPI ODBC32_SQLPrepareW(SQLHSTMT StatementHandle, WCHAR *StatementText, SQLINTEGER TextLength)
2438
{
2439
    SQLRETURN ret;
2440

2441 2442 2443 2444 2445 2446 2447 2448
    TRACE("(StatementHandle %p, StatementText %s, TextLength %d)\n", StatementHandle,
          debugstr_wn(StatementText, TextLength), TextLength);

    if (!pSQLPrepareW) return SQL_ERROR;

    ret = pSQLPrepareW(StatementHandle, StatementText, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
2449 2450 2451 2452 2453
}

/*************************************************************************
 *				SQLSetCursorNameW          [ODBC32.121]
 */
2454
SQLRETURN WINAPI ODBC32_SQLSetCursorNameW(SQLHSTMT StatementHandle, WCHAR *CursorName, SQLSMALLINT NameLength)
2455
{
2456
    SQLRETURN ret;
2457

2458 2459 2460 2461 2462 2463 2464 2465
    TRACE("(StatementHandle %p, CursorName %s, NameLength %d)\n", StatementHandle,
          debugstr_wn(CursorName, NameLength), NameLength);

    if (!pSQLSetCursorNameW) return SQL_ERROR;

    ret = pSQLSetCursorNameW(StatementHandle, CursorName, NameLength);
    TRACE("Returning %d\n", ret);
    return ret;
2466 2467 2468 2469 2470
}

/*************************************************************************
 *				SQLColAttributeW          [ODBC32.127]
 */
2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495
SQLRETURN WINAPI ODBC32_SQLColAttributeW(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber,
                                         SQLUSMALLINT FieldIdentifier, SQLPOINTER CharacterAttribute,
                                         SQLSMALLINT BufferLength, SQLSMALLINT *StringLength,
                                         SQLLEN *NumericAttribute)
{
    SQLRETURN ret;

    TRACE("StatementHandle %p ColumnNumber %d FieldIdentifier %d CharacterAttribute %p BufferLength %d"
          " StringLength %p NumericAttribute %p\n", StatementHandle, ColumnNumber, FieldIdentifier,
          CharacterAttribute, BufferLength, StringLength, NumericAttribute);

    if (!pSQLColAttributeW) return SQL_ERROR;

    ret = pSQLColAttributeW(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength,
                            StringLength, NumericAttribute);

    if (ret == SQL_SUCCESS && CharacterAttribute != NULL && SQLColAttributes_KnownStringAttribute(FieldIdentifier) &&
        StringLength && *StringLength != lstrlenW(CharacterAttribute) * 2)
    {
        TRACE("CHEAT: resetting name length for ADO\n");
        *StringLength = lstrlenW(CharacterAttribute) * 2;
    }

    TRACE("Returning %d\n", ret);
    return ret;
2496 2497 2498 2499 2500
}

/*************************************************************************
 *				SQLGetConnectAttrW          [ODBC32.132]
 */
2501 2502
SQLRETURN WINAPI ODBC32_SQLGetConnectAttrW(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                           SQLINTEGER BufferLength, SQLINTEGER *StringLength)
2503
{
2504 2505 2506 2507
    SQLRETURN ret;

    TRACE("(ConnectionHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", ConnectionHandle,
          Attribute, Value, BufferLength, StringLength);
2508

2509 2510 2511 2512 2513
    if (!pSQLGetConnectAttrW) return SQL_ERROR;

    ret = pSQLGetConnectAttrW(ConnectionHandle, Attribute, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2514 2515 2516 2517 2518
}

/*************************************************************************
 *				SQLGetDescFieldW          [ODBC32.133]
 */
2519 2520
SQLRETURN WINAPI ODBC32_SQLGetDescFieldW(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
                                         SQLPOINTER Value, SQLINTEGER BufferLength, SQLINTEGER *StringLength)
2521
{
2522 2523 2524 2525
    SQLRETURN ret;

    TRACE("(DescriptorHandle %p, RecNumber %d, FieldIdentifier %d, Value %p, BufferLength %d, StringLength %p)\n",
          DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength, StringLength);
2526

2527 2528 2529 2530 2531
    if (!pSQLGetDescFieldW) return SQL_ERROR;

    ret = pSQLGetDescFieldW(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2532 2533 2534 2535 2536
}

/*************************************************************************
 *				SQLGetDescRecW          [ODBC32.134]
 */
2537 2538 2539 2540
SQLRETURN WINAPI ODBC32_SQLGetDescRecW(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, WCHAR *Name,
                                       SQLSMALLINT BufferLength, SQLSMALLINT *StringLength, SQLSMALLINT *Type,
                                       SQLSMALLINT *SubType, SQLLEN *Length, SQLSMALLINT *Precision,
                                       SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
2541
{
2542 2543 2544 2545 2546
    SQLRETURN ret;

    TRACE("(DescriptorHandle %p, RecNumber %d, Name %p, BufferLength %d, StringLength %p, Type %p, SubType %p,"
          " Length %p, Precision %p, Scale %p, Nullable %p)\n", DescriptorHandle, RecNumber, Name, BufferLength,
          StringLength, Type, SubType, Length, Precision, Scale, Nullable);
2547

2548 2549 2550 2551 2552 2553
    if (!pSQLGetDescRecW) return SQL_ERROR;

    ret = pSQLGetDescRecW(DescriptorHandle, RecNumber, Name, BufferLength, StringLength, Type, SubType, Length,
                          Precision, Scale, Nullable);
    TRACE("Returning %d\n", ret);
    return ret;
2554 2555 2556 2557 2558
}

/*************************************************************************
 *				SQLGetDiagFieldW          [ODBC32.135]
 */
2559 2560 2561
SQLRETURN WINAPI ODBC32_SQLGetDiagFieldW(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber,
                                         SQLSMALLINT DiagIdentifier, SQLPOINTER DiagInfo, SQLSMALLINT BufferLength,
                                         SQLSMALLINT *StringLength)
2562
{
2563
    SQLRETURN ret;
2564

2565 2566 2567 2568 2569 2570 2571 2572
    TRACE("(HandleType %d, Handle %p, RecNumber %d, DiagIdentifier %d, DiagInfo %p, BufferLength %d,"
          " StringLength %p)\n", HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength);

    if (!pSQLGetDiagFieldW) return SQL_ERROR;

    ret = pSQLGetDiagFieldW(HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2573 2574 2575 2576 2577
}

/*************************************************************************
 *				SQLGetDiagRecW           [ODBC32.136]
 */
2578 2579 2580
SQLRETURN WINAPI ODBC32_SQLGetDiagRecW(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber,
                                       WCHAR *Sqlstate, SQLINTEGER *NativeError, WCHAR *MessageText,
                                       SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
2581
{
2582 2583 2584 2585 2586
    SQLRETURN ret;

    TRACE("(HandleType %d, Handle %p, RecNumber %d, Sqlstate %p, NativeError %p, MessageText %p, BufferLength %d,"
          " TextLength %p)\n", HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength,
          TextLength);
2587

2588 2589 2590 2591 2592
    if (!pSQLGetDiagRecW) return SQL_ERROR;

    ret = pSQLGetDiagRecW(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
2593 2594 2595 2596 2597
}

/*************************************************************************
 *				SQLGetStmtAttrW          [ODBC32.138]
 */
2598 2599
SQLRETURN WINAPI ODBC32_SQLGetStmtAttrW(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                        SQLINTEGER BufferLength, SQLINTEGER *StringLength)
2600
{
2601
    SQLRETURN ret;
2602

2603 2604
    TRACE("(StatementHandle %p, Attribute %d, Value %p, BufferLength %d, StringLength %p)\n", StatementHandle,
          Attribute, Value, BufferLength, StringLength);
2605

2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616
    if (!Value)
    {
        WARN("Unexpected NULL Value return address\n");
        return SQL_ERROR;
    }

    if (!pSQLGetStmtAttrW) return SQL_ERROR;

    ret = pSQLGetStmtAttrW(StatementHandle, Attribute, Value, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2617 2618 2619 2620 2621
}

/*************************************************************************
 *				SQLSetConnectAttrW          [ODBC32.139]
 */
2622 2623
SQLRETURN WINAPI ODBC32_SQLSetConnectAttrW(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                           SQLINTEGER StringLength)
2624
{
2625 2626 2627 2628
    SQLRETURN ret;

    TRACE("(ConnectionHandle %p, Attribute %d, Value %p, StringLength %d)\n", ConnectionHandle, Attribute, Value,
          StringLength);
2629

2630 2631 2632 2633 2634
    if (!pSQLSetConnectAttrW) return SQL_ERROR;

    ret = pSQLSetConnectAttrW(ConnectionHandle, Attribute, Value, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2635 2636 2637 2638 2639
}

/*************************************************************************
 *				SQLColumnsW          [ODBC32.140]
 */
2640 2641 2642
SQLRETURN WINAPI ODBC32_SQLColumnsW(SQLHSTMT StatementHandle, WCHAR *CatalogName, SQLSMALLINT NameLength1,
                                    WCHAR *SchemaName, SQLSMALLINT NameLength2, WCHAR *TableName,
                                    SQLSMALLINT NameLength3, WCHAR *ColumnName, SQLSMALLINT NameLength4)
2643
{
2644 2645 2646 2647 2648 2649
    SQLRETURN ret;

    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d, TableName %s,"
          " NameLength3 %d, ColumnName %s, NameLength4 %d)\n", StatementHandle,
          debugstr_wn(CatalogName, NameLength1), NameLength1, debugstr_wn(SchemaName, NameLength2), NameLength2,
          debugstr_wn(TableName, NameLength3), NameLength3, debugstr_wn(ColumnName, NameLength4), NameLength4);
2650

2651 2652 2653 2654 2655 2656
    if (!pSQLColumnsW) return SQL_ERROR;

    ret = pSQLColumnsW(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3,
                       ColumnName, NameLength4);
    TRACE("Returning %d\n", ret);
    return ret;
2657 2658 2659 2660 2661
}

/*************************************************************************
 *				SQLDriverConnectW          [ODBC32.141]
 */
2662 2663 2664
SQLRETURN WINAPI ODBC32_SQLDriverConnectW(SQLHDBC ConnectionHandle, SQLHWND WindowHandle, WCHAR *InConnectionString,
                                          SQLSMALLINT Length, WCHAR *OutConnectionString, SQLSMALLINT BufferLength,
                                          SQLSMALLINT *Length2, SQLUSMALLINT DriverCompletion)
2665
{
2666
    SQLRETURN ret;
2667

2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678
    TRACE("(ConnectionHandle %p, WindowHandle %p, InConnectionString %s, Length %d, OutConnectionString %p,"
          " BufferLength %d, Length2 %p, DriverCompletion %d)\n", ConnectionHandle, WindowHandle,
          debugstr_wn(InConnectionString, Length), Length, OutConnectionString, BufferLength, Length2,
          DriverCompletion);

    if (!pSQLDriverConnectW) return SQL_ERROR;

    ret = pSQLDriverConnectW(ConnectionHandle, WindowHandle, InConnectionString, Length, OutConnectionString,
                             BufferLength, Length2, DriverCompletion);
    TRACE("Returning %d\n", ret);
    return ret;
2679 2680 2681 2682 2683
}

/*************************************************************************
 *				SQLGetConnectOptionW      [ODBC32.142]
 */
2684
SQLRETURN WINAPI ODBC32_SQLGetConnectOptionW(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLPOINTER Value)
2685
{
2686 2687 2688
    SQLRETURN ret;

    TRACE("(ConnectionHandle %p, Option %d, Value %p)\n", ConnectionHandle, Option, Value);
2689

2690 2691 2692 2693 2694
    if (!pSQLGetConnectOptionW) return SQL_ERROR;

    ret = pSQLGetConnectOptionW(ConnectionHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
2695 2696 2697 2698 2699
}

/*************************************************************************
 *				SQLGetInfoW          [ODBC32.145]
 */
2700 2701
SQLRETURN WINAPI ODBC32_SQLGetInfoW(SQLHDBC ConnectionHandle, SQLUSMALLINT InfoType, SQLPOINTER InfoValue,
                                    SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
2702
{
2703
    SQLRETURN ret;
2704

2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718
    TRACE("(ConnectionHandle, %p, InfoType %d, InfoValue %p, BufferLength %d, StringLength %p)\n", ConnectionHandle,
          InfoType, InfoValue, BufferLength, StringLength);

    if (!InfoValue)
    {
        WARN("Unexpected NULL InfoValue address\n");
        return SQL_ERROR;
    }

    if (!pSQLGetInfoW) return SQL_ERROR;

    ret = pSQLGetInfoW(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength);
    TRACE("Returning %d\n", ret);
    return ret;
2719 2720 2721 2722 2723
}

/*************************************************************************
 *				SQLGetTypeInfoW          [ODBC32.147]
 */
2724
SQLRETURN WINAPI ODBC32_SQLGetTypeInfoW(SQLHSTMT StatementHandle, SQLSMALLINT DataType)
2725
{
2726 2727 2728
    SQLRETURN ret;

    TRACE("(StatementHandle %p, DataType %d)\n", StatementHandle, DataType);
2729

2730 2731 2732 2733 2734
    if (!pSQLGetTypeInfoW) return SQL_ERROR;

    ret = pSQLGetTypeInfoW(StatementHandle, DataType);
    TRACE("Returning %d\n", ret);
    return ret;
2735 2736 2737 2738 2739
}

/*************************************************************************
 *				SQLSetConnectOptionW          [ODBC32.150]
 */
2740
SQLRETURN WINAPI ODBC32_SQLSetConnectOptionW(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLLEN Value)
2741
{
2742 2743 2744
    SQLRETURN ret;

    TRACE("(ConnectionHandle %p, Option %d, Value %s)\n", ConnectionHandle, Option, debugstr_sqllen(Value));
2745

2746 2747 2748 2749 2750
    if (!pSQLSetConnectOptionW) return SQL_ERROR;

    ret = pSQLSetConnectOptionW(ConnectionHandle, Option, Value);
    TRACE("Returning %d\n", ret);
    return ret;
2751 2752 2753 2754 2755
}

/*************************************************************************
 *				SQLSpecialColumnsW          [ODBC32.152]
 */
2756 2757 2758 2759
SQLRETURN WINAPI ODBC32_SQLSpecialColumnsW(SQLHSTMT StatementHandle, SQLUSMALLINT IdentifierType,
                                           SQLWCHAR *CatalogName, SQLSMALLINT NameLength1, SQLWCHAR *SchemaName,
                                           SQLSMALLINT NameLength2, SQLWCHAR *TableName, SQLSMALLINT NameLength3,
                                           SQLUSMALLINT Scope, SQLUSMALLINT Nullable)
2760
{
2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773
    SQLRETURN ret;

    TRACE("(StatementHandle %p, IdentifierType %d, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d,"
          " TableName %s, NameLength3 %d, Scope %d, Nullable %d)\n", StatementHandle, IdentifierType,
          debugstr_wn(CatalogName, NameLength1), NameLength1, debugstr_wn(SchemaName, NameLength2), NameLength2,
          debugstr_wn(TableName, NameLength3), NameLength3, Scope, Nullable);

    if (!pSQLSpecialColumnsW) return SQL_ERROR;

    ret = pSQLSpecialColumnsW(StatementHandle, IdentifierType, CatalogName, NameLength1, SchemaName,
                              NameLength2, TableName, NameLength3, Scope, Nullable);
    TRACE("Returning %d\n", ret);
    return ret;
2774 2775 2776 2777 2778
}

/*************************************************************************
 *				SQLStatisticsW          [ODBC32.153]
 */
2779 2780 2781
SQLRETURN WINAPI ODBC32_SQLStatisticsW(SQLHSTMT StatementHandle, SQLWCHAR *CatalogName, SQLSMALLINT NameLength1,
                                       SQLWCHAR *SchemaName, SQLSMALLINT NameLength2, SQLWCHAR *TableName,
                                       SQLSMALLINT NameLength3, SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
2782
{
2783 2784 2785 2786 2787 2788
    SQLRETURN ret;

    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d SchemaName %s, NameLength2 %d, TableName %s"
          " NameLength3 %d, Unique %d, Reserved %d)\n", StatementHandle,
          debugstr_wn(CatalogName, NameLength1), NameLength1, debugstr_wn(SchemaName, NameLength2), NameLength2,
          debugstr_wn(TableName, NameLength3), NameLength3, Unique, Reserved);
2789

2790 2791 2792 2793 2794 2795
    if (!pSQLStatisticsW) return SQL_ERROR;

    ret = pSQLStatisticsW(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName,
                          NameLength3, Unique, Reserved);
    TRACE("Returning %d\n", ret);
    return ret;
2796 2797 2798 2799 2800
}

/*************************************************************************
 *				SQLTablesW          [ODBC32.154]
 */
2801 2802 2803
SQLRETURN WINAPI ODBC32_SQLTablesW(SQLHSTMT StatementHandle, SQLWCHAR *CatalogName, SQLSMALLINT NameLength1,
                                   SQLWCHAR *SchemaName, SQLSMALLINT NameLength2, SQLWCHAR *TableName,
                                   SQLSMALLINT NameLength3, SQLWCHAR *TableType, SQLSMALLINT NameLength4)
2804
{
2805 2806 2807 2808 2809 2810
    SQLRETURN ret;

    TRACE("(StatementHandle %p, CatalogName %s, NameLength1 %d, SchemaName %s, NameLength2 %d, TableName %s,"
          " NameLength3 %d, TableType %s, NameLength4 %d)\n", StatementHandle,
          debugstr_wn(CatalogName, NameLength1), NameLength1, debugstr_wn(SchemaName, NameLength2), NameLength2,
          debugstr_wn(TableName, NameLength3), NameLength3, debugstr_wn(TableType, NameLength4), NameLength4);
2811

2812 2813 2814 2815 2816 2817
    if (!pSQLTablesW) return SQL_ERROR;

    ret = pSQLTablesW(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3,
                      TableType, NameLength4);
    TRACE("Returning %d\n", ret);
    return ret;
2818 2819 2820 2821 2822
}

/*************************************************************************
 *				SQLBrowseConnectW          [ODBC32.155]
 */
2823 2824 2825
SQLRETURN WINAPI ODBC32_SQLBrowseConnectW(SQLHDBC hdbc, SQLWCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn,
                                          SQLWCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax,
                                          SQLSMALLINT *pcbConnStrOut)
2826
{
2827 2828 2829 2830 2831 2832
    SQLRETURN ret;

    TRACE("(hdbc %p, szConnStrIn %s, cbConnStrIn %d, szConnStrOut %p, cbConnStrOutMax %d, pcbConnStrOut %p)\n",
          hdbc, debugstr_wn(szConnStrIn, cbConnStrIn), cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut);

    if (!pSQLBrowseConnectW) return SQL_ERROR;
2833

2834 2835 2836
    ret = pSQLBrowseConnectW(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut);
    TRACE("Returning %d\n", ret);
    return ret;
2837 2838 2839 2840 2841
}

/*************************************************************************
 *				SQLColumnPrivilegesW          [ODBC32.156]
 */
2842 2843 2844
SQLRETURN WINAPI ODBC32_SQLColumnPrivilegesW(SQLHSTMT hstmt, SQLWCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                             SQLWCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLWCHAR *szTableName,
                                             SQLSMALLINT cbTableName, SQLWCHAR *szColumnName, SQLSMALLINT cbColumnName)
2845
{
2846
    SQLRETURN ret;
2847

2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d, szColumnName %s, cbColumnName %d)\n", hstmt,
          debugstr_wn(szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_wn(szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_wn(szTableName, cbTableName), cbTableName,
          debugstr_wn(szColumnName, cbColumnName), cbColumnName);

    if (!pSQLColumnPrivilegesW) return SQL_ERROR;

    ret = pSQLColumnPrivilegesW(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szTableName,
                                cbTableName, szColumnName, cbColumnName);
    TRACE("Returning %d\n", ret);
    return ret;
2861 2862 2863 2864 2865
}

/*************************************************************************
 *				SQLDataSourcesW          [ODBC32.157]
 */
2866 2867 2868
SQLRETURN WINAPI ODBC32_SQLDataSourcesW(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, WCHAR *ServerName,
                                        SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1, WCHAR *Description,
                                        SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2)
2869
{
2870
    SQLRETURN ret;
2871

2872 2873 2874
    TRACE("(EnvironmentHandle %p, Direction %d, ServerName %p, BufferLength1 %d, NameLength1 %p, Description %p,"
          " BufferLength2 %d, NameLength2 %p)\n", EnvironmentHandle, Direction, ServerName, BufferLength1,
          NameLength1, Description, BufferLength2, NameLength2);
2875

2876
    if (!pSQLDataSourcesW) return SQL_ERROR;
2877

2878 2879
    ret = pSQLDataSourcesW(EnvironmentHandle, Direction, ServerName, BufferLength1, NameLength1, Description,
                           BufferLength2, NameLength2);
2880

2881 2882 2883 2884 2885 2886 2887 2888
    if (ret >= 0 && TRACE_ON(odbc))
    {
        if (ServerName && NameLength1 && *NameLength1 > 0)
            TRACE(" DataSource %s", debugstr_wn(ServerName, *NameLength1));
        if (Description && NameLength2 && *NameLength2 > 0)
            TRACE(" Description %s", debugstr_wn(Description, *NameLength2));
        TRACE("\n");
    }
2889

2890 2891
    TRACE("Returning %d\n", ret);
    return ret;
2892 2893 2894 2895 2896
}

/*************************************************************************
 *				SQLForeignKeysW          [ODBC32.160]
 */
2897 2898 2899 2900 2901
SQLRETURN WINAPI ODBC32_SQLForeignKeysW(SQLHSTMT hstmt, SQLWCHAR *szPkCatalogName, SQLSMALLINT cbPkCatalogName,
                                        SQLWCHAR *szPkSchemaName, SQLSMALLINT cbPkSchemaName, SQLWCHAR *szPkTableName,
                                        SQLSMALLINT cbPkTableName, SQLWCHAR *szFkCatalogName,
                                        SQLSMALLINT cbFkCatalogName, SQLWCHAR *szFkSchemaName,
                                        SQLSMALLINT cbFkSchemaName, SQLWCHAR *szFkTableName, SQLSMALLINT cbFkTableName)
2902
{
2903
    SQLRETURN ret;
2904

2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
    TRACE("(hstmt %p, szPkCatalogName %s, cbPkCatalogName %d, szPkSchemaName %s, cbPkSchemaName %d,"
          " szPkTableName %s, cbPkTableName %d, szFkCatalogName %s, cbFkCatalogName %d, szFkSchemaName %s,"
          " cbFkSchemaName %d, szFkTableName %s, cbFkTableName %d)\n", hstmt,
          debugstr_wn(szPkCatalogName, cbPkCatalogName), cbPkCatalogName,
          debugstr_wn(szPkSchemaName, cbPkSchemaName), cbPkSchemaName,
          debugstr_wn(szPkTableName, cbPkTableName), cbPkTableName,
          debugstr_wn(szFkCatalogName, cbFkCatalogName), cbFkCatalogName,
          debugstr_wn(szFkSchemaName, cbFkSchemaName), cbFkSchemaName,
          debugstr_wn(szFkTableName, cbFkTableName), cbFkTableName);

    if (!pSQLForeignKeysW) return SQL_ERROR;

    ret = pSQLForeignKeysW(hstmt, szPkCatalogName, cbPkCatalogName, szPkSchemaName, cbPkSchemaName, szPkTableName,
                           cbPkTableName, szFkCatalogName, cbFkCatalogName, szFkSchemaName, cbFkSchemaName,
                           szFkTableName, cbFkTableName);
    TRACE("Returning %d\n", ret);
    return ret;
2922 2923 2924 2925 2926
}

/*************************************************************************
 *				SQLNativeSqlW          [ODBC32.162]
 */
2927 2928
SQLRETURN WINAPI ODBC32_SQLNativeSqlW(SQLHDBC hdbc, SQLWCHAR *szSqlStrIn, SQLINTEGER cbSqlStrIn, SQLWCHAR *szSqlStr,
                                      SQLINTEGER cbSqlStrMax, SQLINTEGER *pcbSqlStr)
2929
{
2930 2931 2932 2933 2934 2935
    SQLRETURN ret;

    TRACE("(hdbc %p, szSqlStrIn %s, cbSqlStrIn %d, szSqlStr %p, cbSqlStrMax %d, pcbSqlStr %p)\n", hdbc,
          debugstr_wn(szSqlStrIn, cbSqlStrIn), cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr);

    if (!pSQLNativeSqlW) return SQL_ERROR;
2936

2937 2938 2939
    ret = pSQLNativeSqlW(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr);
    TRACE("Returning %d\n", ret);
    return ret;
2940 2941 2942 2943 2944
}

/*************************************************************************
 *				SQLPrimaryKeysW          [ODBC32.165]
 */
2945 2946 2947
SQLRETURN WINAPI ODBC32_SQLPrimaryKeysW(SQLHSTMT hstmt, SQLWCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                        SQLWCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLWCHAR *szTableName,
                                        SQLSMALLINT cbTableName)
2948
{
2949
    SQLRETURN ret;
2950

2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d)\n", hstmt,
          debugstr_wn(szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_wn(szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_wn(szTableName, cbTableName), cbTableName);

    if (!pSQLPrimaryKeysW) return SQL_ERROR;

    ret = pSQLPrimaryKeysW(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szTableName, cbTableName);
    TRACE("Returning %d\n", ret);
    return ret;
2962 2963 2964 2965 2966
}

/*************************************************************************
 *				SQLProcedureColumnsW          [ODBC32.166]
 */
2967 2968 2969
SQLRETURN WINAPI ODBC32_SQLProcedureColumnsW(SQLHSTMT hstmt, SQLWCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                             SQLWCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLWCHAR *szProcName,
                                             SQLSMALLINT cbProcName, SQLWCHAR *szColumnName, SQLSMALLINT cbColumnName)
2970
{
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980
    SQLRETURN ret;

    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szProcName %s,"
          " cbProcName %d, szColumnName %s, cbColumnName %d)\n", hstmt,
          debugstr_wn(szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_wn(szSchemaName, cbSchemaName), cbSchemaName,
          debugstr_wn(szProcName, cbProcName), cbProcName,
          debugstr_wn(szColumnName, cbColumnName), cbColumnName);

    if (!pSQLProcedureColumnsW) return SQL_ERROR;
2981

2982 2983 2984 2985
    ret = pSQLProcedureColumnsW(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szProcName,
                                cbProcName, szColumnName, cbColumnName);
    TRACE("Returning %d\n", ret);
    return ret;
2986 2987 2988 2989 2990
}

/*************************************************************************
 *				SQLProceduresW          [ODBC32.167]
 */
2991 2992 2993
SQLRETURN WINAPI ODBC32_SQLProceduresW(SQLHSTMT hstmt, SQLWCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                       SQLWCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLWCHAR *szProcName,
                                       SQLSMALLINT cbProcName)
2994
{
2995
    SQLRETURN ret;
2996

2997 2998 2999 3000 3001 3002 3003 3004 3005
    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szProcName %s,"
          " cbProcName %d)\n", hstmt, debugstr_wn(szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_wn(szSchemaName, cbSchemaName), cbSchemaName, debugstr_wn(szProcName, cbProcName), cbProcName);

    if (!pSQLProceduresW) return SQL_ERROR;

    ret = pSQLProceduresW(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szProcName, cbProcName);
    TRACE("Returning %d\n", ret);
    return ret;
3006 3007 3008 3009 3010
}

/*************************************************************************
 *				SQLTablePrivilegesW          [ODBC32.170]
 */
3011 3012 3013
SQLRETURN WINAPI ODBC32_SQLTablePrivilegesW(SQLHSTMT hstmt, SQLWCHAR *szCatalogName, SQLSMALLINT cbCatalogName,
                                            SQLWCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLWCHAR *szTableName,
                                            SQLSMALLINT cbTableName)
3014
{
3015 3016 3017 3018 3019 3020 3021
    SQLRETURN ret;

    TRACE("(hstmt %p, szCatalogName %s, cbCatalogName %d, szSchemaName %s, cbSchemaName %d, szTableName %s,"
          " cbTableName %d)\n", hstmt, debugstr_wn(szCatalogName, cbCatalogName), cbCatalogName,
          debugstr_wn(szSchemaName, cbSchemaName), cbSchemaName, debugstr_wn(szTableName, cbTableName), cbTableName);

    if (!pSQLTablePrivilegesW) return SQL_ERROR;
3022

3023 3024 3025 3026
    ret = pSQLTablePrivilegesW(hstmt, szCatalogName, cbCatalogName, szSchemaName, cbSchemaName, szTableName,
                               cbTableName);
    TRACE("Returning %d\n", ret);
    return ret;
3027 3028 3029 3030 3031
}

/*************************************************************************
 *				SQLDriversW          [ODBC32.171]
 */
3032 3033 3034 3035
SQLRETURN WINAPI ODBC32_SQLDriversW(SQLHENV EnvironmentHandle, SQLUSMALLINT fDirection, SQLWCHAR *szDriverDesc,
                                    SQLSMALLINT cbDriverDescMax, SQLSMALLINT *pcbDriverDesc,
                                    SQLWCHAR *szDriverAttributes, SQLSMALLINT cbDriverAttrMax,
                                    SQLSMALLINT *pcbDriverAttr)
3036
{
3037 3038 3039 3040 3041
    SQLRETURN ret;

    TRACE("(EnvironmentHandle %p, Direction %d, szDriverDesc %p, cbDriverDescMax %d, pcbDriverDesc %p,"
          " DriverAttributes %p, cbDriverAttrMax %d, pcbDriverAttr %p)\n", EnvironmentHandle, fDirection,
          szDriverDesc, cbDriverDescMax, pcbDriverDesc, szDriverAttributes, cbDriverAttrMax, pcbDriverAttr);
3042

3043
    if (!pSQLDriversW) return SQL_ERROR;
3044

3045 3046
    ret = pSQLDriversW(EnvironmentHandle, fDirection, szDriverDesc, cbDriverDescMax, pcbDriverDesc,
                       szDriverAttributes, cbDriverAttrMax, pcbDriverAttr);
3047

3048 3049
    if (ret == SQL_NO_DATA && fDirection == SQL_FETCH_FIRST)
        ERR_(winediag)("No ODBC drivers could be found. Check the settings for your libodbc provider.\n");
3050

3051 3052
    TRACE("Returning %d\n", ret);
    return ret;
3053 3054 3055 3056 3057
}

/*************************************************************************
 *				SQLSetDescFieldW          [ODBC32.173]
 */
3058 3059
SQLRETURN WINAPI ODBC32_SQLSetDescFieldW(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
                                         SQLPOINTER Value, SQLINTEGER BufferLength)
3060
{
3061 3062 3063 3064
    SQLRETURN ret;

    TRACE("(DescriptorHandle %p, RecNumber %d, FieldIdentifier %d, Value %p, BufferLength %d)\n", DescriptorHandle,
          RecNumber, FieldIdentifier, Value, BufferLength);
3065

3066 3067 3068 3069 3070
    if (!pSQLSetDescFieldW) return SQL_ERROR;

    ret = pSQLSetDescFieldW(DescriptorHandle, RecNumber, FieldIdentifier, Value, BufferLength);
    TRACE("Returning %d\n", ret);
    return ret;
3071 3072 3073 3074 3075
}

/*************************************************************************
 *				SQLSetStmtAttrW          [ODBC32.176]
 */
3076 3077
SQLRETURN WINAPI ODBC32_SQLSetStmtAttrW(SQLHSTMT StatementHandle, SQLINTEGER Attribute, SQLPOINTER Value,
                                        SQLINTEGER StringLength)
3078
{
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094
    SQLRETURN ret;

    TRACE("(StatementHandle %p, Attribute %d, Value %p, StringLength %d)\n", StatementHandle, Attribute, Value,
          StringLength);

    if (!pSQLSetStmtAttrW) return SQL_ERROR;

    ret = pSQLSetStmtAttrW(StatementHandle, Attribute, Value, StringLength);
    if (ret == SQL_ERROR && (Attribute == SQL_ROWSET_SIZE || Attribute == SQL_ATTR_ROW_ARRAY_SIZE))
    {
        TRACE("CHEAT: returning SQL_SUCCESS to ADO\n");
        return SQL_SUCCESS;
    }

    TRACE("Returning %d\n", ret);
    return ret;
3095 3096
}

3097 3098 3099
/*************************************************************************
 *				SQLGetDiagRecA           [ODBC32.236]
 */
3100 3101 3102
SQLRETURN WINAPI ODBC32_SQLGetDiagRecA(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT RecNumber,
                                       SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText,
                                       SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
3103
{
3104 3105 3106 3107 3108
    SQLRETURN ret;

    TRACE("(HandleType %d, Handle %p, RecNumber %d, Sqlstate %p, NativeError %p, MessageText %p, BufferLength %d,"
          " TextLength %p)\n", HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength,
          TextLength);
3109 3110

    if (!pSQLGetDiagRecA) return SQL_ERROR;
3111 3112 3113 3114

    ret = pSQLGetDiagRecA(HandleType, Handle, RecNumber, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
    TRACE("Returning %d\n", ret);
    return ret;
3115
}