RETCODE SQL_API SQLConnect ( SQLHDBC pConn, SQLCHAR* pServerName, SQLSMALLINT pServerNameLen, SQLCHAR* pUserName, SQLSMALLINT pUserNameLen, SQLCHAR* pPassword, SQLSMALLINT pPasswordLen ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLConnect called" ) ); __CHK_HANDLE ( pConn, SQL_HANDLE_DBC, SQL_ERROR ); __ODBCPOPMSG ( _ODBCPopMsg ( "SQLConnect - not implemented, use SQLDriverConnect" ) ); return SQL_ERROR; _SQLFreeDiag ( _DIAGCONN ( pConn ) ); return ( SQL_SUCCESS ); }
SQLRETURN SQL_API SQLConnectW ( SQLHDBC hdbc, SQLWCHAR* szDSN, SQLSMALLINT cchDSN, SQLWCHAR* szUID, SQLSMALLINT cchUID, SQLWCHAR* szAuthStr, SQLSMALLINT cchAuthStr ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLConnectW called" ) ); __CHK_HANDLE ( hdbc, SQL_HANDLE_DBC, SQL_ERROR ); __ODBCPOPMSG ( _ODBCPopMsg ( "SQLConnectW - not implemented, use SQLDriverConnectW" ) ); return SQL_ERROR; _SQLFreeDiag ( _DIAGCONN ( hdbc ) ); return ( SQL_SUCCESS ); }
RETCODE SQL_API SQLGetConnectAttr ( SQLHDBC pConn, SQLINTEGER pAttr, SQLPOINTER pDataPtr, SQLINTEGER pDataSize, SQLINTEGER* pDataSizePtr ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetConnectAttr, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr, pDataSize ) ); __CHK_HANDLE ( pConn, SQL_HANDLE_DBC, SQL_ERROR ); _SQLFreeDiag ( _DIAGCONN ( pConn ) ); switch ( pAttr ) { case SQL_ATTR_ACCESS_MODE : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> AccessMode; break; case SQL_ATTR_ASYNC_ENABLE : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> AsyncEnable; break; case SQL_ATTR_AUTO_IPD : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> AutoIPD; break; case SQL_ATTR_AUTOCOMMIT : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> AutoCommit; break; case SQL_ATTR_CONNECTION_DEAD : * ( ( ULong* ) pDataPtr ) = SQL_CD_TRUE ; break; case SQL_ATTR_CONNECTION_TIMEOUT : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> TimeOut; break; case SQL_ATTR_CURRENT_CATALOG : // current database return _SQLCopyCharData ( _DIAGCONN ( pConn ), pDataPtr, pDataSize, pDataSizePtr, 32, "default", -1 ); case SQL_ATTR_LOGIN_TIMEOUT : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> LoginTimeOut; break; case SQL_ATTR_METADATA_ID : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> MetaDataID; break; case SQL_ATTR_ODBC_CURSORS : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> ODBCCursors; break; case SQL_ATTR_PACKET_SIZE : return SQL_ERROR; // not a typical option case SQL_ATTR_QUIET_MODE : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> Window; break; case SQL_ATTR_TRACE : // basically for driver manager break; case SQL_ATTR_TRACEFILE : // basically for driver manager break; case SQL_ATTR_TRANSLATE_LIB : // not implemented break; case SQL_ATTR_TRANSLATE_OPTION : // not implemented break; case SQL_ATTR_TXN_ISOLATION : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> TxnIsolation; break; case SQL_ATTR_MAX_ROWS : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> MaxRows; break; case SQL_ATTR_QUERY_TIMEOUT : * ( ( ULong* ) pDataPtr ) = ( ( pODBCConn ) pConn ) -> QueryTimeout; break; default : __ODBCPOPMSG ( _ODBCPopMsg ( "SQLGetConnectAttr not recognized, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr, pDataSize ) ); return SQL_SUCCESS; } return SQL_SUCCESS; }
RETCODE SQL_API SQLDriverConnect ( SQLHDBC pConn, SQLHWND pWndHandle, SQLCHAR* pInConnStr, SQLSMALLINT pInConnStrLen, SQLCHAR* pOutConnStr, SQLSMALLINT pOutConnStrLen, SQLSMALLINT* pOutConnStrLenPtr, SQLUSMALLINT pDriverCompletion ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The window handle is %d, the driver completion flag is %d", pWndHandle, pDriverCompletion ) ); pODBCConn pgConn = ( pODBCConn ) pConn; bool f; bool flgDriver, flgDSN; // flags for knowing if these key present in string bool flgServer, flgPort, flgUID, flgPWD, flgProj; // flags for knowing if these key present in string Word i, n; Word iKVInputPairs; // no of key value pairs as input Word iDriverPos, iDSNPos; // ??? can be eliminated by optimization of code Word iServerPos, iPortPos, iUIDPos, iPWDPos, iProjPos; // ??? can be eliminated by optimization of code struct ODBCKV* KVInput; // key value as input via function param struct ODBCKV* KV; // generic, temp if ( !pInConnStr ) { __ODBCPOPMSG ( _ODBCPopMsg ( "SQLDriverConnect: pInConnStr is required" ) ); return SQL_ERROR; } else { //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,"The passed-in Connection Str is %s",(char*)pInConnStr)); } __CHK_HANDLE ( pConn, SQL_HANDLE_DBC, SQL_ERROR ); _SQLFreeDiag ( _DIAGCONN ( pConn ) ); // caller safe if ( pOutConnStr ) { *pOutConnStr = 0; } if ( pOutConnStrLenPtr ) { *pOutConnStrLenPtr = 0; } // initializations KVInput = NULL; flgServer = FALSE; flgPort = FALSE; flgUID = FALSE; flgPWD = FALSE; flgProj = FALSE; // check if an in-string has been specified if ( pInConnStr ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "Parsing the in str" ) ); // split into key-value pairs if ( CvtStrToKeyValues ( ( StrPtr ) pInConnStr, pInConnStrLen, &iKVInputPairs, &KVInput ) != GOOD ) { return SQL_ERROR; } // first check if dsn keyword is present flgDSN = FindInKeyValues ( "DSN", NULL, KVInput, iKVInputPairs, &iDSNPos ); // look for driver only if DSN is absent else Driver is always ignored flgDriver = ( flgDSN ) ? FALSE : FindInKeyValues ( "DRIVER", NULL, KVInput, iKVInputPairs, &iDriverPos ); // if DSN is to be used, fetch its set of key values if ( flgDSN ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The in str is a dsn string" ) ); //connect by dsn SetCurrentDSN ( ( char* ) pInConnStr, "SQLDriverConnect" ); if ( LoadODBCINIDataToConn ( pgConn ) != GOOD ) { return SQL_ERROR; } } else if ( flgDriver ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The in str is a driver string" ) ); /************* debug for ( i = 0, n = iKVInputPairs, KV = KVInput; i < n; i++ ) fprintf ( stderr, "Index: %d, Key: %s, Value: %s\n", i, KV[i].key ? KV[i].key : "(nokey)", KV[i].value ? KV[i].value : "(no value)" ); *********/ // loop to parse both input key-values and DSN key-values & feed into struct for ( i = 0, n = iKVInputPairs, KV = KVInput; i < n; i++ ) { if ( !flgServer ) { flgServer = FindInKeyValues ( "SERVER", NULL, KV, n, &iServerPos ); if ( flgServer ) { CreateAndSetConnProp ( ( pODBCConn ) pConn, CONN_PROP_SERVER, KV[iServerPos].value ); } } if ( !flgPort ) { flgPort = FindInKeyValues ( "PORT", NULL, KV, n, &iPortPos ); if ( flgPort ) { CreateAndSetConnProp ( ( pODBCConn ) pConn, CONN_PROP_PORT, KV[iPortPos].value ); } } if ( !flgUID ) { flgUID = FindInKeyValues ( "UID", NULL, KV, n, &iUIDPos ); if ( flgUID ) { CreateAndSetConnProp ( ( pODBCConn ) pConn, CONN_PROP_UID, KV[iUIDPos].value ); __ODBCLOG ( _ODBCLogMsg ( LogLevel_INFO, "Log in as User : %s ", KV[iUIDPos].value ) ); } } if ( !flgPWD ) { flgPWD = FindInKeyValues ( "PWD", NULL, KV, n, &iPWDPos ); if ( flgPWD ) { CreateAndSetConnProp ( ( pODBCConn ) pConn, CONN_PROP_PWD, KV[iPWDPos].value ); } } if ( !flgProj ) { flgProj = FindInKeyValues ( "PROJECT", NULL, KV, n, &iProjPos ); if ( flgProj ) { CreateAndSetConnProp ( ( pODBCConn ) pConn, CONN_PROP_PROJECT, KV[iProjPos].value ); } } } } else { _SQLPutDiagRow ( SQL_HANDLE_DBC, pConn, "SQLDriverConnectW", "HY000", 1045, "Only DSN or driver connect is allowed" ); __ODBCPOPMSG ( _ODBCPopMsg ( "Only DSN or driver connect is allowed, instead of %s", pInConnStr ) ); return SQL_ERROR; } FreeGenODBCKeyValues ( KVInput, iKVInputPairs ); delete[] KVInput; } else if ( pDriverCompletion == SQL_DRIVER_NOPROMPT ) { // check if no-prompt forced __ODBCPOPMSG ( _ODBCPopMsg ( "No connection string && no prompt specified" ) ); _SQLPutDiagRow ( SQL_HANDLE_DBC, pConn, "SQLDriverConnectW", "HY000", 1045, "Access denied. (using UID: NO , using password: NO)" ); return SQL_ERROR; } RETCODE ret; // check if prompt required ie any info is missing if ( flgDriver && ( !flgServer || !flgPort || !flgUID || !flgPWD || !flgProj ) ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_INFO, "Connection info imcomplete, prompt for input..." ) ); if ( flgUID && !flgPWD && pDriverCompletion == SQL_DRIVER_NOPROMPT ) { _SQLPutDiagRow ( SQL_HANDLE_DBC, pConn, "SQLDriverConnectW", "HY000", 1045, "Access denied for user 'root'@'kylin-tableau-clean.com' (using password: NO)" ); __ODBCLOG ( _ODBCLogMsg ( LogLevel_ERROR, "UID present but PWD absent, guessing it's on Tableau Server, return SQL ERROR" ) ); return SQL_ERROR; } //connect by driver // fetch entire connection information thru dialogs switch ( PromptForConnInfo ( pConn ) ) { case 0: // user-cancelled return SQL_NO_DATA_FOUND; default: break; } ret = SQL_SUCCESS; } else { ret = TryFetchMetadata ( pgConn ) ; if ( ret == SQL_ERROR ) { return ret; } } // OUT CONN STRING // build the out-connection string if required if ( pOutConnStr && pOutConnStrLen > 0 && pOutConnStrLenPtr ) { if ( flgDriver ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "Building out str..." ) ); // build the out conn string using key value pairs f = BuildConnStr ( ( StrPtr ) pOutConnStr, pOutConnStrLen, ( pODBCConn ) pConn, NULL, 0, NULL, 0 ); if ( !f ) { _SQLPutDiagRow ( SQL_HANDLE_DBC, pConn, "SQLDriverConnectW", "HY000", 1045, "Out connection string not complete" ); } } else { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "Copy in str to out str" ) ); strcpy ( ( char* ) pOutConnStr, ( char* ) pInConnStr ); } *pOutConnStrLenPtr = strlen ( ( StrPtr ) pOutConnStr ); __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The Length of Out Conn Str is %d", *pOutConnStrLenPtr ) ); } else { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "skip writing to the out put string" ) ); } return ret; }
RETCODE SQL_API SQLSetConnectAttr ( SQLHDBC pConn, SQLINTEGER pAttr, SQLPOINTER pDataPtr, SQLINTEGER pDataSize ) { __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLSetConnectAttr, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr, pDataSize ) ); __CHK_HANDLE ( pConn, SQL_HANDLE_DBC, SQL_ERROR ); _SQLFreeDiag ( _DIAGCONN ( pConn ) ); switch ( pAttr ) { case SQL_ATTR_ANSI_APP : return SQL_ERROR; case SQL_ATTR_ACCESS_MODE : ( ( pODBCConn ) pConn ) -> AccessMode = ( ULong ) pDataPtr; break; case SQL_ATTR_ASYNC_ENABLE : ( ( pODBCConn ) pConn ) -> AsyncEnable = ( ULong ) pDataPtr; break; //case SQL_ATTR_AUTO_IPD: read-only case SQL_ATTR_AUTOCOMMIT : ( ( pODBCConn ) pConn ) -> AutoCommit = ( ULong ) pDataPtr; break; case SQL_ATTR_CONNECTION_DEAD : // (( pODBCConn )pConn)->AutoCommit = ( ULong )pDataPtr; break; case SQL_ATTR_CONNECTION_TIMEOUT : //(( pODBCConn )pConn)->TimeOut = *(( ULong* )pDataPtr ); break; case SQL_ATTR_CURRENT_CATALOG : // current database // assumes that current database is what it should be // return _SQLCopyCharData ( _DIAGCONN(pConn), (( pODBCConn )pConn)->CurrDB, 32, NULL, 16, pDataPtr, pDataSize ); break; case SQL_ATTR_LOGIN_TIMEOUT : // (( pODBCConn )pConn)->LoginTimeOut = *(( ULong* )pDataPtr ); break; case SQL_ATTR_METADATA_ID : ( ( pODBCConn ) pConn ) -> MetaDataID = ( ULong ) pDataPtr; break; case SQL_ATTR_ODBC_CURSORS : ( ( pODBCConn ) pConn ) -> ODBCCursors = ( ULong ) pDataPtr; break; case SQL_ATTR_PACKET_SIZE : // not a typical option return SQL_ERROR; case SQL_ATTR_QUIET_MODE : ( ( pODBCConn ) pConn ) -> Window = ( ULong ) pDataPtr; break; case SQL_ATTR_TRACE : // only for driver manager break; case SQL_ATTR_TRACEFILE : // only for driver manager break; case SQL_ATTR_TRANSLATE_LIB : // translation still not implemented break; case SQL_ATTR_TRANSLATE_OPTION : // translation still not implemented break; case SQL_ATTR_TXN_ISOLATION : ( ( pODBCConn ) pConn ) -> TxnIsolation = ( ULong ) pDataPtr; break; case SQL_ATTR_MAX_ROWS : ( ( pODBCConn ) pConn ) -> MaxRows = ( ULong ) pDataPtr; break; case SQL_ATTR_QUERY_TIMEOUT : ( ( pODBCConn ) pConn ) -> QueryTimeout = ( ULong ) pDataPtr; break; default : __ODBCPOPMSG ( _ODBCPopMsg ( "SQLSetConnectAttr is not recognized, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr, pDataSize ) ); return SQL_SUCCESS; } __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLSetConnectAttr, Attr: %d, DataPtr: %d, DataSize: %d is done!", pAttr, pDataPtr, pDataSize ) ); return SQL_SUCCESS; }