RETCODE SQL_API SQLGetInfoW(HDBC ConnectionHandle, SQLUSMALLINT InfoType, PTR InfoValue, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength) { CSTR func = "SQLGetInfoW"; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; RETCODE ret; ENTER_CONN_CS(conn); CC_set_in_unicode_driver(conn); CC_clear_error(conn); #if (ODBCVER >= 0x0300) mylog("[%s(30)]", func); if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength)) == SQL_ERROR) { if (conn->driver_version >= 0x0300) { CC_clear_error(conn); ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength); } } if (SQL_ERROR == ret) CC_log_error("SQLGetInfoW(30)", "", conn); #else mylog("[%s]", func); ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength); if (SQL_ERROR == ret) CC_log_error("SQLGetInfoW", "", conn); #endif LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLNativeSqlW(HDBC hdbc, SQLWCHAR *szSqlStrIn, SQLINTEGER cbSqlStrIn, SQLWCHAR *szSqlStr, SQLINTEGER cbSqlStrMax, SQLINTEGER *pcbSqlStr) { CSTR func = "SQLNativeSqlW"; RETCODE ret; char *szIn, *szOut = NULL, *szOutt = NULL; SQLLEN slen; SQLINTEGER buflen, olen; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[%s}", func); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); szIn = ucs2_to_utf8(szSqlStrIn, cbSqlStrIn, &slen, FALSE); buflen = 3 * cbSqlStrMax; if (buflen > 0) szOutt = malloc(buflen); for (;; buflen = olen + 1, szOutt = realloc(szOut, buflen)) { if (!szOutt) { CC_set_error(conn, CONN_NO_MEMORY_ERROR, "Could not allocate memory for output buffer", func); ret = SQL_ERROR; break; } szOut = szOutt; ret = PGAPI_NativeSql(hdbc, (SQLCHAR *) szIn, (SQLINTEGER) slen, (SQLCHAR *) szOut, buflen, &olen); if (SQL_SUCCESS_WITH_INFO != ret || olen < buflen) break; } if (szIn) free(szIn); if (SQL_SUCCEEDED(ret)) { SQLLEN szcount = olen; if (olen < buflen) szcount = utf8_to_ucs2(szOut, olen, szSqlStr, cbSqlStrMax); if (SQL_SUCCESS == ret && szcount > cbSqlStrMax) { ConnectionClass *conn = (ConnectionClass *) hdbc; ret = SQL_SUCCESS_WITH_INFO; CC_set_error(conn, CONN_TRUNCATED, "Sql string too large", func); } if (pcbSqlStr) *pcbSqlStr = (SQLINTEGER) szcount; } LEAVE_CONN_CS(conn); free(szOut); return ret; }
RETCODE SQL_API SQLConnectW(HDBC ConnectionHandle, SQLWCHAR *ServerName, SQLSMALLINT NameLength1, SQLWCHAR *UserName, SQLSMALLINT NameLength2, SQLWCHAR *Authentication, SQLSMALLINT NameLength3) { CSTR func = "SQLConnectW"; char *svName, *usName, *auth; SQLLEN nmlen1, nmlen2, nmlen3; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[%s]", func); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); svName = ucs2_to_utf8(ServerName, NameLength1, &nmlen1, FALSE); usName = ucs2_to_utf8(UserName, NameLength2, &nmlen2, FALSE); auth = ucs2_to_utf8(Authentication, NameLength3, &nmlen3, FALSE); ret = PGAPI_Connect(ConnectionHandle, (SQLCHAR *) svName, (SQLSMALLINT) nmlen1, (SQLCHAR *) usName, (SQLSMALLINT) nmlen2, (SQLCHAR *) auth, (SQLSMALLINT) nmlen3); LEAVE_CONN_CS(conn); if (svName) free(svName); if (usName) free(usName); if (auth) free(auth); return ret; }
RETCODE SQL_API SQLSetConnectOption(HDBC ConnectionHandle, SQLUSMALLINT Option, SQLULEN Value) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLSetConnectionOption]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_SetConnectOption(ConnectionHandle, Option, Value); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLAllocStmt(HDBC ConnectionHandle, HSTMT *StatementHandle) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLAllocStmt]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_AllocStmt(ConnectionHandle, StatementHandle); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLGetInfo(HDBC ConnectionHandle, SQLUSMALLINT InfoType, PTR InfoValue, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength) { CSTR func = "SQLGetInfo"; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); #if (ODBCVER >= 0x0300) mylog("[%s(30)]", func); if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength)) == SQL_ERROR) { if (conn->driver_version >= 0x0300) { CC_clear_error(conn); ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength); goto cleanup; } } if (SQL_ERROR == ret) CC_log_error("SQLGetInfo(30)", "", conn); #else mylog("[%s]", func); if (ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength), SQL_ERROR == ret) CC_log_error(func, "", conn); #endif cleanup: LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLGetConnectOption(HDBC ConnectionHandle, SQLUSMALLINT Option, PTR Value) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLGetConnectOption]"); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_GetConnectOption(ConnectionHandle, Option, Value, NULL, 64); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLAllocStmt(HDBC ConnectionHandle, HSTMT *StatementHandle) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLAllocStmt]"); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_AllocStmt(ConnectionHandle, StatementHandle, PODBC_EXTERNAL_STATEMENT | PODBC_INHERIT_CONNECT_OPTIONS); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLGetConnectAttrW(HDBC hdbc, SQLINTEGER fAttribute, PTR rgbValue, SQLINTEGER cbValueMax, SQLINTEGER *pcbValue) { CSTR func = "SQLGetConnectAttrW"; RETCODE ret; mylog("[%s]", func); ENTER_CONN_CS((ConnectionClass *) hdbc); CC_clear_error((ConnectionClass *) hdbc); ret = PGAPI_GetConnectAttr(hdbc, fAttribute, rgbValue, cbValueMax, pcbValue); LEAVE_CONN_CS((ConnectionClass *) hdbc); return ret; }
RETCODE SQL_API SQLConnect(HDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1, SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication, SQLSMALLINT NameLength3) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLConnect]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_Connect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLDisconnect(HDBC ConnectionHandle) { CSTR func = "SQLDisconnect"; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[%s for %p]", func, ConnectionHandle); #ifdef _HANDLE_ENLIST_IN_DTC_ CALL_DtcOnDisconnect(conn); /* must be called without holding the connection lock */ #endif /* _HANDLE_ENLIST_IN_DTC_ */ ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_Disconnect(ConnectionHandle); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLSetConnectAttrW(HDBC hdbc, SQLINTEGER fAttribute, PTR rgbValue, SQLINTEGER cbValue) { CSTR func = "SQLSetConnectAttrW"; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[%s]", func); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); ret = PGAPI_SetConnectAttr(hdbc, fAttribute, rgbValue, cbValue); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLDisconnect(HDBC ConnectionHandle) { CSTR func = "SQLDisconnect"; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[%s for %p]", func, ConnectionHandle); #ifdef _HANDLE_ENLIST_IN_DTC_ if (CC_is_in_global_trans(conn)) CALL_DtcOnDisconnect(conn); #endif /* _HANDLE_ENLIST_IN_DTC_ */ ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_Disconnect(ConnectionHandle); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLBrowseConnectW(HDBC hdbc, SQLWCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn, SQLWCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT *pcbConnStrOut) { CSTR func = "SQLBrowseConnectW"; char *szIn, *szOut; SQLLEN inlen; SQLUSMALLINT obuflen; SQLSMALLINT olen; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[%s]", func); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE); obuflen = cbConnStrOutMax + 1; szOut = malloc(obuflen); if (szOut) ret = PGAPI_BrowseConnect(hdbc, (SQLCHAR *) szIn, (SQLSMALLINT) inlen, (SQLCHAR *) szOut, cbConnStrOutMax, &olen); else { CC_set_error(conn, CONN_NO_MEMORY_ERROR, "Could not allocate memory for output buffer", func); ret = SQL_ERROR; } LEAVE_CONN_CS(conn); if (ret != SQL_ERROR) { SQLLEN outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax); if (pcbConnStrOut) *pcbConnStrOut = (SQLSMALLINT) outlen; } free(szOut); if (szIn) free(szIn); return ret; }
RETCODE SQL_API SQLBrowseConnect( HDBC hdbc, SQLCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn, SQLCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT *pcbConnStrOut) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[SQLBrowseConnect]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_BrowseConnect(hdbc, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLGetInfoW(HDBC ConnectionHandle, SQLUSMALLINT InfoType, PTR InfoValue, SQLSMALLINT BufferLength, SQLSMALLINT *StringLength) { CSTR func = "SQLGetInfoW"; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; RETCODE ret; CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_set_in_unicode_driver(conn); CC_clear_error(conn); mylog("[%s]", func); if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue, BufferLength, StringLength)) == SQL_ERROR) CC_log_error("SQLGetInfoW", "", conn); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLNativeSql( HDBC hdbc, SQLCHAR *szSqlStrIn, SQLINTEGER cbSqlStrIn, SQLCHAR *szSqlStr, SQLINTEGER cbSqlStrMax, SQLINTEGER *pcbSqlStr) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[SQLNativeSql]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_NativeSql(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr, cbSqlStrMax, pcbSqlStr); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLGetFunctions(HDBC ConnectionHandle, SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) ConnectionHandle; mylog("[SQLGetFunctions]"); ENTER_CONN_CS(conn); CC_clear_error(conn); #if (ODBCVER >= 0x0300) if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS) ret = PGAPI_GetFunctions30(ConnectionHandle, FunctionId, Supported); else #endif { ret = PGAPI_GetFunctions(ConnectionHandle, FunctionId, Supported); } LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLDriverConnect(HDBC hdbc, HWND hwnd, SQLCHAR FAR * szConnStrIn, SQLSMALLINT cbConnStrIn, SQLCHAR FAR * szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT FAR * pcbConnStrOut, SQLUSMALLINT fDriverCompletion) { RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[SQLDriverConnect]"); ENTER_CONN_CS(conn); CC_clear_error(conn); ret = PGAPI_DriverConnect(hdbc, hwnd, szConnStrIn, cbConnStrIn, szConnStrOut, cbConnStrOutMax, pcbConnStrOut, fDriverCompletion); LEAVE_CONN_CS(conn); return ret; }
RETCODE SQL_API SQLBrowseConnectW( HDBC hdbc, SQLWCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn, SQLWCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT *pcbConnStrOut) { CSTR func = "SQLBrowseConnectW"; char *szIn, *szOut; SQLLEN inlen; SQLUSMALLINT obuflen; SQLSMALLINT olen; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[%s]", func); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE); obuflen = cbConnStrOutMax + 1; szOut = malloc(obuflen); ret = PGAPI_BrowseConnect(hdbc, szIn, (SQLSMALLINT) inlen, szOut, cbConnStrOutMax, &olen); LEAVE_CONN_CS(conn); if (ret != SQL_ERROR) { SQLLEN outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax); if (pcbConnStrOut) *pcbConnStrOut = (SQLSMALLINT) outlen; } free(szOut); if (szIn) free(szIn); return ret; }
RETCODE SQL_API SQLDriverConnectW(HDBC hdbc, HWND hwnd, SQLWCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn, SQLWCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT *pcbConnStrOut, SQLUSMALLINT fDriverCompletion) { CSTR func = "SQLDriverConnectW"; char *szIn, *szOut = NULL; SQLSMALLINT maxlen, obuflen = 0; SQLLEN inlen; SQLSMALLINT olen, *pCSO; RETCODE ret; ConnectionClass *conn = (ConnectionClass *) hdbc; mylog("[%s]", func); CC_examine_global_transaction(conn); ENTER_CONN_CS(conn); CC_clear_error(conn); CC_set_in_unicode_driver(conn); szIn = ucs2_to_utf8(szConnStrIn, cbConnStrIn, &inlen, FALSE); maxlen = cbConnStrOutMax; pCSO = NULL; olen = 0; if (maxlen > 0) { obuflen = maxlen + 1; szOut = malloc(obuflen); if (!szOut) { CC_set_error(conn, CONN_NO_MEMORY_ERROR, "Could not allocate memory for output buffer", func); ret = SQL_ERROR; goto cleanup; } pCSO = &olen; } else if (pcbConnStrOut) pCSO = &olen; ret = PGAPI_DriverConnect(hdbc, hwnd, (SQLCHAR *) szIn, (SQLSMALLINT) inlen, (SQLCHAR *) szOut, maxlen, pCSO, fDriverCompletion); if (ret != SQL_ERROR && NULL != pCSO) { SQLLEN outlen = olen; if (olen < obuflen) outlen = utf8_to_ucs2(szOut, olen, szConnStrOut, cbConnStrOutMax); else utf8_to_ucs2(szOut, maxlen, szConnStrOut, cbConnStrOutMax); if (outlen >= cbConnStrOutMax && NULL != szConnStrOut && NULL != pcbConnStrOut) { inolog("cbConnstrOutMax=%d pcb=%p\n", cbConnStrOutMax, pcbConnStrOut); if (SQL_SUCCESS == ret) { CC_set_error(conn, CONN_TRUNCATED, "the ConnStrOut is too small", func); ret = SQL_SUCCESS_WITH_INFO; } } if (pcbConnStrOut) *pcbConnStrOut = (SQLSMALLINT) outlen; } cleanup: LEAVE_CONN_CS(conn); if (szOut) free(szOut); if (szIn) free(szIn); return ret; }