コード例 #1
0
ファイル: KO_ATTR.CPP プロジェクト: AdolphLua/kylin
RETCODE SQL_API SQLGetEnvAttr ( SQLHENV pEnv,
                                SQLINTEGER pAttr,
                                SQLPOINTER pDataPtr,
                                SQLINTEGER pDataSize,
                                SQLINTEGER* pDataSizePtr )
{
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetEnvAttr called" ) );
    __CHK_HANDLE ( pEnv, SQL_HANDLE_ENV, SQL_ERROR );
    _SQLFreeDiag ( _DIAGENV ( pEnv ) );

    switch ( pAttr )
    {
        case SQL_ATTR_ODBC_VERSION :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCEnv ) pEnv ) -> AttrODBCVersion;
            break;

        case SQL_ATTR_CONNECTION_POOLING :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCEnv ) pEnv ) -> AttrConnPooling;
            break;

        case SQL_ATTR_CP_MATCH :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCEnv ) pEnv ) -> AttrCPMatch;
            break;

        case SQL_ATTR_OUTPUT_NTS :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCEnv ) pEnv ) -> AttrOutputNTS;
            break;

        default :
            return SQL_ERROR; // unknown attribute
    }

    return SQL_SUCCESS;
}
コード例 #2
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE SQL_API SQLExtendedFetch ( SQLHSTMT        pStmt,
                                   SQLUSMALLINT    pFetchOrientation,
                                   SQLINTEGER      pFetchOffset,
                                   SQLUINTEGER*    pRowCountPtr,
                                   SQLUSMALLINT*   pRowStatusArray ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG,
                              "SQLExtendedFetch called, Stmt: %d, FO: %d, Offset: %d, Rcount: %d, RowStatus: %d", pStmt, pFetchOrientation,
                              pFetchOffset, pRowCountPtr, pRowStatusArray ) );
    __ODBCPOPMSG ( _ODBCPopMsg ( "SQLExtendedFetch is not implemented   " ) );
    return SQL_ERROR;
    Long n;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // only fetch next supported
    if ( pFetchOrientation != SQL_FETCH_NEXT ) {
        __ODBCPOPMSG ( _ODBCPopMsg ( "SQLExtendedFetch option not supported, FetchOrientation: %d", pFetchOrientation ) );
        return SQL_ERROR;
    }
    
    // check if number of rows explicitly specified
    if ( pFetchOffset <= 0 )
    { n = ( ( pODBCStmt ) pStmt )->ARD.RowArraySize; }
    
    // use default rowset size as a fallback
    if ( n <= 0 )
    { n = 1; }
    
    return _SQLFetch ( ( pODBCStmt ) pStmt, pFetchOrientation, n, pRowCountPtr, pRowStatusArray );
}
コード例 #3
0
ファイル: KO_EXEC.CPP プロジェクト: Arun-Ghosh/odbc-driver
/*
     Kylin uses rest request for query executing, SQLPrepare does not do anything meaningful
*/
RETCODE SQL_API SQLPrepareW ( SQLHSTMT    pStmt,
                              SQLWCHAR*    pStmtText,
                              SQLINTEGER  pTextLength ) {
    wchar_t*      s;
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLPrepareW called on: %d", pStmt ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // precaution
    if ( pStmtText == NULL || ( pTextLength <= 0 && pTextLength != SQL_NTS ) ) {
        __ODBCPOPMSG ( _ODBCPopMsg ( "SQLPrepare - bad params" ) );
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLPrepare", "01000", -1, "SQLPrepare - bad params" );
        return SQL_ERROR;
    }
    
    // MANAGE STMT CONTENT
    
    // convert to full request, with zero termination ( as well as params - later )
    if ( ProcessStmtForParams ( ( pODBCStmt ) pStmt, pStmtText, pTextLength, s ) == BAD )
    { return SQL_ERROR; }
    
    // release existing stmt contents
    SQLFreeStmt ( pStmt, SQL_CLOSE );
    // replace with new stmt string
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The query being prepared is :" ) );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, s ) );
    ( ( pODBCStmt ) pStmt )->Stmt = s;
    ( ( pODBCStmt ) pStmt )->StmtLen = pTextLength;
    // MARK as prepared
    // set the flag
    ( ( pODBCStmt ) pStmt )->Prepared = 1;
    return SQL_SUCCESS;
}
コード例 #4
0
ファイル: KO_EXEC.CPP プロジェクト: Arun-Ghosh/odbc-driver
RETCODE SQL_API SQLExecDirectW ( SQLHSTMT    pStmt,
                                 SQLWCHAR*    pStmtText,
                                 SQLINTEGER  pTextLength ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLExecDirectW called on: %d", pStmt ) );
    wchar_t*      s;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // precaution
    if ( pStmtText == NULL || ( pTextLength <= 0 && pTextLength != SQL_NTS ) ) {
        __ODBCPOPMSG ( _ODBCPopMsg ( "SQLExecDirect - bad params" ) );
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLExecDirectW", "01000", -1, "bad params" );
        return SQL_ERROR;
    }
    
    // convert to full request, with zero termination ( as well as params - later )
    if ( ProcessStmtForParams ( ( pODBCStmt ) pStmt, ( wchar_t* ) pStmtText, pTextLength, s ) == BAD )
    { return SQL_ERROR; }
    
    // release existing stmt contents
    SQLFreeStmt ( pStmt, SQL_CLOSE );
    // replace with new stmt string
    ( ( pODBCStmt ) pStmt )->Stmt = s;
    ( ( pODBCStmt ) pStmt )->StmtLen = pTextLength;
    // mark it as prepared
    ( ( pODBCStmt ) pStmt )->Prepared = 1;
    // execute
    RETCODE code = SQLExecute ( pStmt );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLExecDirectW exited on with %d", code ) );
    return code;
}
コード例 #5
0
ファイル: KO_ATTR.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE SQL_API SQLSetCursorName ( SQLHSTMT    pStmt,
                                   SQLCHAR*    pDataPtr,
                                   SQLSMALLINT pDataSize ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetCursorName called" ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    return SQL_SUCCESS;
}
コード例 #6
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE SQL_API SQLRowCount ( HSTMT pStmt, SQLLEN* pDataPtr ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLRowCount called" ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    *pDataPtr = ( ( pODBCStmt ) pStmt )->RowCount;
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLRowCount returned: %d", *pDataPtr ) );
    return SQL_SUCCESS;
}
コード例 #7
0
ファイル: KO_CONN.CPP プロジェクト: Arun-Ghosh/odbc-driver
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 );
}
コード例 #8
0
ファイル: KO_CONN.CPP プロジェクト: Arun-Ghosh/odbc-driver
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 );
}
コード例 #9
0
ファイル: KO_EXEC.CPP プロジェクト: Arun-Ghosh/odbc-driver
RETCODE SQL_API SQLExecute ( HSTMT pStmt ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLExecute called on: %d", pStmt ) );
    Word        x;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // check if prepared
    if ( ( ( pODBCStmt ) pStmt )->Prepared != 1 ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLExecute", "01000", -1, "No prepared stmt" );
        return SQL_ERROR;
    }
    
    // excute the request
    x  = _SQLExecStmtFromReq ( ( pODBCStmt ) pStmt, 1 );
    return x;
}
コード例 #10
0
ファイル: KO_EXEC.CPP プロジェクト: Arun-Ghosh/odbc-driver
RETCODE SQL_API SQLCloseCursor ( SQLHSTMT pStmt ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLCloseCursor called" ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // check if there is some result
    if (
        ( ( pODBCStmt ) pStmt )->IRD.RowDesc != NULL ) {
        // free the results
        return SQLFreeStmt ( pStmt, SQL_CLOSE );
    }
    
    else {
        // error condition
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLCloseCursor", "24000", -1, "Invalid cursor state" );
        return SQL_ERROR;
    }
}
コード例 #11
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE SQL_API SQLNumResultCols ( SQLHSTMT pStmt, SQLSMALLINT*  pColCountPtr ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLNumResultCols called" ) );
    SQLResponse* rowdesc;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    // caller safe
    * ( ( SQLSMALLINT* ) pColCountPtr ) = 0;
    // get the row desciptor
    rowdesc = ( ( pODBCStmt ) pStmt )->IRD.RowDesc.get();
    
    if ( rowdesc == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLNumResultCols", "01000", -1, "no resultset or IRD" );
        return SQL_ERROR;
    }
    
    // count the number of columns
    * ( ( SQLSMALLINT* ) pColCountPtr ) = ( SQLSMALLINT ) ( rowdesc->columnMetas.size() );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLNumResultCols called returned: %d",
                              * ( ( SQLSMALLINT* ) pColCountPtr ) ) );
    return SQL_SUCCESS;
}
コード例 #12
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE SQL_API SQLFetch ( HSTMT pStmt ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLFetch called" ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    // all fetch occur thru the local function _SQLFetch
    /*
        RETCODE SQL_API _SQLFetch ( pODBCStmt    pStmt,
        Word            pFetchOrientation,
        Long            pFetchOffset,
        ULong*          pRowCountPtr,
        UWord*          pRowStatusArray )
    */
    RETCODE ret =  _SQLFetch ( ( pODBCStmt ) pStmt, SQL_FETCH_NEXT,
                               ( ( pODBCStmt ) pStmt )->ARD.RowArraySize > 0 ? ( ( pODBCStmt ) pStmt )->ARD.RowArraySize : 1,
                               ( ( pODBCStmt ) pStmt )->IRD.RowsProcessedPtr, ( ( pODBCStmt ) pStmt )->IRD.ArrayStatusPtr );
                               
    if ( ret == SQL_NO_DATA ) {
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_INFO, "Last row of current query has been fetched" ) );
    }
    
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLFetch exiting" ) );
    return ret;
}
コード例 #13
0
ファイル: KO_ATTR.CPP プロジェクト: AdolphLua/kylin
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;
}
コード例 #14
0
ファイル: KO_CONN.CPP プロジェクト: Arun-Ghosh/odbc-driver
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;
}
コード例 #15
0
ファイル: KO_ATTR.CPP プロジェクト: AdolphLua/kylin
RETCODE SQL_API SQLSetStmtAttrW ( SQLHSTMT pStmt,
                                  SQLINTEGER pAttr,
                                  SQLPOINTER pDataPtr,
                                  SQLINTEGER pDataSize )

{
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLSetStmtAttrW, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr,
        pDataSize ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );

    switch ( pAttr )
    {
        case 1226 : /* MS SQL Server Extension */
        case 1227 :
        case 1228 :
            break;

        case SQL_ATTR_APP_PARAM_DESC :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_APP_PARAM_DESC - Cannot set descriptor" ) );
            return SQL_ERROR;

        case SQL_ATTR_APP_ROW_DESC :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_APP_ROW_DESC - Cannot set descriptor" ) );
            return SQL_ERROR;

        case SQL_ATTR_ASYNC_ENABLE :
            ( ( pODBCStmt ) pStmt ) -> AsyncEnable = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_CONCURRENCY :
            ( ( pODBCStmt ) pStmt ) -> Concurrency = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_CURSOR_SCROLLABLE :
            ( ( pODBCStmt ) pStmt ) -> CursorScroll = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_CURSOR_SENSITIVITY :
            ( ( pODBCStmt ) pStmt ) -> CursorSensitivity = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_CURSOR_TYPE :
            ( ( pODBCStmt ) pStmt ) -> CursorType = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_ENABLE_AUTO_IPD :
            ( ( pODBCStmt ) pStmt ) -> AutoIPD = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_FETCH_BOOKMARK_PTR :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_FETCH_BOOKMARK_PTR - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_IMP_PARAM_DESC :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_IMP_PARAM_DESC - Cannot set descriptor" ) );
            return SQL_ERROR;

        case SQL_ATTR_IMP_ROW_DESC :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_IMP_ROW_DESC - Cannot set descriptor" ) );
            return SQL_ERROR;

        case SQL_ATTR_KEYSET_SIZE :
            ( ( pODBCStmt ) pStmt ) -> KeysetSize = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_MAX_LENGTH :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_MAX_LENGTH - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_MAX_ROWS :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_MAX_ROWS - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_METADATA_ID :
            ( ( pODBCStmt ) pStmt ) -> MetaDataID = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_NOSCAN :
            ( ( pODBCStmt ) pStmt ) -> NoScan = ( ULong ) pDataPtr;
            break;

        case SQL_ATTR_PARAM_BIND_TYPE :
            _SQLSetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_BIND_TYPE, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_PARAM_BIND_OFFSET_PTR :
            _SQLSetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_BIND_OFFSET_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_PARAM_OPERATION_PTR :
            _SQLSetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_PARAM_STATUS_PTR :
            _SQLSetIPDField ( & ( ( ( pODBCStmt ) pStmt ) -> IPD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_PARAMS_PROCESSED_PTR :
            // ???? note there is an error in MSDN on SQLSetDescField which says ARD/APD instead of IRD/IPD for this option
            _SQLSetIPDField ( & ( ( ( pODBCStmt ) pStmt ) -> IPD ), SQL_DESC_ROWS_PROCESSED_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_PARAMSET_SIZE :
            _SQLSetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_ARRAY_SIZE, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_QUERY_TIMEOUT :
            if ( pDataPtr != NULL )
            {
                ( ( pODBCStmt ) pStmt ) -> QryTimeout = ( ( ULong ) pDataPtr );
            }

            break;

        case SQL_ATTR_RETRIEVE_DATA :
            ( ( pODBCStmt ) pStmt ) -> RetrieveData = ( ULong ) pDataPtr;
            break;

        case SQL_ROWSET_SIZE :
        case SQL_ATTR_ROW_ARRAY_SIZE :
            _SQLSetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_ARRAY_SIZE, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_ROW_BIND_OFFSET_PTR :
            _SQLSetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_BIND_OFFSET_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_ROW_BIND_TYPE :
            _SQLSetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_BIND_TYPE, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_ROW_OPERATION_PTR :
            _SQLSetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_ROW_STATUS_PTR :
            _SQLSetIRDField ( & ( ( ( pODBCStmt ) pStmt ) -> IRD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_ROWS_FETCHED_PTR :
            _SQLSetIRDField ( & ( ( ( pODBCStmt ) pStmt ) -> IRD ), SQL_DESC_ROWS_PROCESSED_PTR, pDataPtr, pDataSize );
            break;

        case SQL_ATTR_SIMULATE_CURSOR :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_SIMULATE_CURSOR - option not implemented" ) );
            return SQL_ERROR;

        default :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQLSetStmtAttrW : Stmt attr - unknown %d", pAttr ) );
            return SQL_ERROR;
    }

    return SQL_SUCCESS;
}
コード例 #16
0
ファイル: KO_ATTR.CPP プロジェクト: AdolphLua/kylin
RETCODE SQL_API SQLGetStmtAttr ( SQLHSTMT pStmt,
                                 SQLINTEGER pAttr,
                                 SQLPOINTER pDataPtr,
                                 SQLINTEGER pDataSize,
                                 SQLINTEGER* pDataSizePtr )
{
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetStmtAttr, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr,
        pDataSize ) );
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );

    switch ( pAttr )
    {
        case SQL_ATTR_APP_PARAM_DESC :
            * ( ( Long* ) pDataPtr ) = ( Long ) & ( ( ( pODBCStmt ) pStmt ) -> APD );
            break;

        case SQL_ATTR_APP_ROW_DESC :
            * ( ( Long* ) pDataPtr ) = ( Long ) & ( ( ( pODBCStmt ) pStmt ) -> ARD );
            break;

        case SQL_ATTR_ASYNC_ENABLE :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> AsyncEnable;
            break;

        case SQL_ATTR_CONCURRENCY :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> Concurrency;
            break;

        case SQL_ATTR_CURSOR_SCROLLABLE :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> CursorScroll;
            break;

        case SQL_ATTR_CURSOR_SENSITIVITY :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> CursorSensitivity;
            break;

        case SQL_ATTR_CURSOR_TYPE :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> CursorType;
            break;

        case SQL_ATTR_ENABLE_AUTO_IPD :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> AutoIPD;
            break;

        case SQL_ATTR_FETCH_BOOKMARK_PTR :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_FETCH_BOOKMARK_PTR - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_IMP_PARAM_DESC :
            * ( ( Long* ) pDataPtr ) = ( Long ) & ( ( ( pODBCStmt ) pStmt ) -> IPD );
            break;

        case SQL_ATTR_IMP_ROW_DESC :
            * ( ( Long* ) pDataPtr ) = ( Long ) & ( ( ( pODBCStmt ) pStmt ) -> IRD );
            break;

        case SQL_ATTR_KEYSET_SIZE :
            * ( ( Long* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> KeysetSize;
            break;

        case SQL_ATTR_MAX_LENGTH :
            * ( ( ULong* ) pDataPtr ) = 0;
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_MAX_LENGTH - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_MAX_ROWS :
            * ( ( ULong* ) pDataPtr ) = 0;
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_MAX_ROWS - option not implemented" ) );
            return SQL_ERROR;

        case SQL_ATTR_METADATA_ID :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> MetaDataID;
            break;

        case SQL_ATTR_NOSCAN :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> NoScan;
            break;

        case SQL_ATTR_PARAM_BIND_TYPE :
            _SQLGetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_BIND_TYPE, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_PARAM_BIND_OFFSET_PTR :
            _SQLGetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_BIND_OFFSET_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_PARAM_OPERATION_PTR :
            _SQLGetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_PARAM_STATUS_PTR :
            _SQLGetIPDField ( & ( ( ( pODBCStmt ) pStmt ) -> IPD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_PARAMS_PROCESSED_PTR :
            // ???? note there is an error in MSDN on SQLSetDescField which says ARD/APD instead of IRD/IPD for this option
            _SQLGetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_ROWS_PROCESSED_PTR, pDataPtr, pDataSize,
                              pDataSizePtr );
            break;

        case SQL_ATTR_PARAMSET_SIZE :
            _SQLGetAPDField ( & ( ( ( pODBCStmt ) pStmt ) -> APD ), SQL_DESC_ARRAY_SIZE, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_QUERY_TIMEOUT :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> QryTimeout;
            break;

        case SQL_ATTR_RETRIEVE_DATA :
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> RetrieveData;
            break;

        case SQL_ROWSET_SIZE :
        case SQL_ATTR_ROW_ARRAY_SIZE :
            _SQLGetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_ARRAY_SIZE, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_ROW_BIND_OFFSET_PTR :
            _SQLGetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_BIND_OFFSET_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_ROW_BIND_TYPE :
            _SQLGetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_BIND_TYPE, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_ROW_NUMBER :
            // ??? in case of rowset being > 1, start row is being returned
            * ( ( ULong* ) pDataPtr ) = ( ( pODBCStmt ) pStmt ) -> CurRowsetStartRowPos;
            break;

        case SQL_ATTR_ROW_OPERATION_PTR :
            _SQLGetARDField ( & ( ( ( pODBCStmt ) pStmt ) -> ARD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_ROW_STATUS_PTR :
            _SQLGetIRDField ( & ( ( ( pODBCStmt ) pStmt ) -> IRD ), SQL_DESC_ARRAY_STATUS_PTR, pDataPtr, pDataSize, pDataSizePtr );
            break;

        case SQL_ATTR_ROWS_FETCHED_PTR :
            _SQLGetIRDField ( & ( ( ( pODBCStmt ) pStmt ) -> IRD ), SQL_DESC_ROWS_PROCESSED_PTR, pDataPtr, pDataSize,
                              pDataSizePtr );
            break;

        case SQL_ATTR_SIMULATE_CURSOR :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQL_ATTR_SIMULATE_CURSOR - option not implemented" ) );
            return SQL_ERROR;

        default :
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQLGetStmtAttr: Stmt attr - unknown %d", pAttr ) );
            return SQL_ERROR;
    }

    return SQL_SUCCESS;
}
コード例 #17
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
RETCODE  _SQLColAttribute_basic ( SQLHSTMT        pStmt,
                                  SQLUSMALLINT    pColNum,
                                  SQLUSMALLINT    pFldID,
                                  SQLPOINTER      pDataPtr,
                                  SQLSMALLINT     pDataSize,
                                  SQLSMALLINT*    pDataSizePtr, // in bytes
                                  SQLPOINTER      pNumValuePtr ,// integer
                                  bool isANSI
                                ) { //if returned data is numeric, feed this
    Long            n;
    SQLResponse*    ird;
    pIRDItem        col;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // precaution
    if ( pColNum == 0 ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLColAttribute", "01000", -1, "bad params" );
        return SQL_ERROR;
    }
    
    // get the row descriptor obtained with response
    ird = ( ( ( pODBCStmt ) pStmt )->IRD ).RowDesc.get();
    
    // check
    if ( ird == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLColAttribute", "01000", -1, "No resultset or no col descriptors" );
        return SQL_ERROR;
    }
    
    // find the xth element/col
    col = _SQLGetIRDItem ( & ( ( ( pODBCStmt ) pStmt )->IRD ), pColNum );
    
    // check
    if ( col == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLColAttribute", "01000", -1, "Invalid col num" );
        return SQL_ERROR;
    }
    
    // get value from descriptor as per field type
    switch ( pFldID ) {
        // numeric types clubbed together
        case SQL_DESC_AUTO_UNIQUE_VALUE:                // is col auto-incrementing
        case SQL_DESC_CASE_SENSITIVE:                   // is col case-insensitive
        case SQL_DESC_TYPE:                             // verbose type
        case SQL_DESC_CONCISE_TYPE:                     // concise type
        case SQL_DESC_COUNT:                            // no.of highest bound column
        case SQL_DESC_LENGTH:
        case SQL_DESC_DISPLAY_SIZE:
        case SQL_DESC_OCTET_LENGTH:
        case SQL_DESC_FIXED_PREC_SCALE:
        case SQL_DESC_NULLABLE:
        case SQL_DESC_NUM_PREC_RADIX:
        case SQL_DESC_PRECISION:
        case SQL_DESC_SCALE:
        case SQL_DESC_SEARCHABLE:
        case SQL_DESC_UNNAMED:
        case SQL_DESC_UNSIGNED:
        case SQL_DESC_UPDATABLE:
            _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, pFldID, pNumValuePtr, -1, NULL , isANSI );
            break;
            
        // char types clubbed together
        
        case SQL_DESC_BASE_TABLE_NAME:                  // table name for column
        case SQL_DESC_CATALOG_NAME:                     // database name
        case SQL_DESC_LITERAL_PREFIX:
        case SQL_DESC_LITERAL_SUFFIX:
        case SQL_DESC_LOCAL_TYPE_NAME:
        case SQL_DESC_TYPE_NAME:
        case SQL_DESC_SCHEMA_NAME:
        case SQL_DESC_TABLE_NAME:
            _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, pFldID, pDataPtr, pDataSize,
                                  pDataSizePtr ? &n : NULL, isANSI );
                                  
            if ( pDataSizePtr )
            { *pDataSizePtr = ( Word ) n; }
            
            break;
            
        case SQL_DESC_BASE_COLUMN_NAME:
        case SQL_DESC_LABEL:
        case SQL_DESC_NAME:
            // ////
            // as a special case the name length may be required without the actual name
            //////
            StrPtr cname;
            Word   cnamesize;
            
            if ( pDataPtr ) {
                cname       = ( StrPtr ) pDataPtr;
                cnamesize   = pDataSize;
            }
            
            else {
                cname       = new Char[256];             // arbitary
                cnamesize   = 255;
            }
            
            _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, pFldID, cname, cnamesize,
                                  pDataSizePtr ? &n : NULL, isANSI );
                                  
            if ( pDataPtr == NULL )
            { delete[] cname; }
            
            if ( pDataSizePtr )
            { *pDataSizePtr = ( Word ) n; }
            
            break;
            
        default:
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQLColAttribute unknown attr, ColNum: %d, FldID: %d\n", pColNum, pFldID ) );
            return SQL_ERROR;
    }
    
    return SQL_SUCCESS;
}
コード例 #18
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
SQLRETURN SQL_API _SQLDescribeCol_basic ( SQLHSTMT        pStmt,
                                          SQLUSMALLINT    pColNum,
                                          void*        pColNamePtr,
                                          SQLSMALLINT     pColNameSize,
                                          SQLSMALLINT*    pColNameSizePtr,
                                          SQLSMALLINT*    pDataTypePtr,
                                          SQLULEN*        pColSizePtr,
                                          SQLSMALLINT*    pDecimalDigitsPtr,
                                          SQLSMALLINT*    pNullablePtr ,
                                          bool isANSI
                                        ) {
    Long            n;
    SQLResponse*        ird;
    pIRDItem        col;
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    
    // precaution
    if ( pColNum == 0 ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLDescribeCol", "01000", -1, "bad params" );
        return SQL_ERROR;
    }
    
    // get the row descriptor obtained with response
    ird = ( ( ( pODBCStmt ) pStmt )->IRD ).RowDesc.get();
    
    // check
    if ( ird == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLDescribeCol", "01000", -1, "No resultset or no col descriptors" );
        return SQL_ERROR;
    }
    
    // find the xth element/col
    col = _SQLGetIRDItem ( & ( ( ( pODBCStmt ) pStmt )->IRD ), pColNum );
    
    // check
    if ( col == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLDescribeCol", "01000", -1, "Invalid col num" );
        return SQL_ERROR;
    }
    
    // COL-NAME ie title
    
    if ( pColNamePtr ) {
        _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, SQL_DESC_BASE_COLUMN_NAME, pColNamePtr,
                              pColNameSize, pColNameSizePtr ? &n : NULL, isANSI );
                              
        if ( pColNameSizePtr )
        { *pColNameSizePtr = ( Word ) n; }
        
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "name: %s", pColNamePtr ) );
    }
    
    // COL-DATA TYPE
    
    if ( pDataTypePtr ) {
        _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, SQL_DESC_CONCISE_TYPE, pDataTypePtr, -1,
                              NULL, isANSI );
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "data type: %d", *pDataTypePtr ) );
    }
    
    // COL-SIZE
    
    if ( pColSizePtr ) {
        _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, SQL_DESC_LENGTH, pColSizePtr, -1, NULL,
                              isANSI );
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "column size: %d", *pColSizePtr ) );
    }
    
    // COL-DECIMAL
    
    if ( pDecimalDigitsPtr ) {
        _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, SQL_DESC_SCALE, pDecimalDigitsPtr, -1, NULL,
                              isANSI );
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "decimal scale: %d", *pDecimalDigitsPtr ) );
    }
    
    // COL-NULLABLE
    
    if ( pNullablePtr ) {
        _SQLGetIRDItemField ( & ( ( ( pODBCStmt ) pStmt )->IRD ), col, pColNum, SQL_DESC_NULLABLE, pNullablePtr, -1, NULL,
                              isANSI );
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "nullable: %d", *pNullablePtr ) );
    }
    
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLDescribeCol returned" ) );
    return SQL_SUCCESS;
}
コード例 #19
0
ファイル: KO_ATTR.CPP プロジェクト: AdolphLua/kylin
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;
}
コード例 #20
0
ファイル: KO_FETCH.CPP プロジェクト: KylinOLAP/odbc-driver
/*

    From msdn:

    SQLRETURN SQLBindCol(
    SQLHSTMT       StatementHandle,
    SQLUSMALLINT   ColumnNumber,
    SQLSMALLINT    TargetType,
    SQLPOINTER     TargetValuePtr,
    SQLLEN         BufferLength,
    SQLLEN *       StrLen_or_Ind);

*/
RETCODE SQL_API SQLBindCol ( SQLHSTMT        pStmt,
                             SQLUSMALLINT    pColNum,
                             SQLSMALLINT     pDataType,
                             SQLPOINTER      pDataPtr,
                             SQLLEN      pDataSize,
                             SQLLEN*         pDataSizePtr ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLBindCol called, ColNum: %d, TgtType: %d, ValuePtr: %d, Capacity: %d",
                              pColNum, pDataType, pDataPtr, pDataSize ) );
    pODBCARD         ard;                            // application row descriptor
    pARDItem     ardcol;                         // application row descriptor item
    __CHK_HANDLE ( pStmt, SQL_HANDLE_STMT, SQL_ERROR );
    // free diags
    _SQLFreeDiag ( _DIAGSTMT ( pStmt ) );
    // extract the appl. row descriptor from stmt
    ard = & ( ( ( pODBCStmt ) pStmt )->ARD );
    // get the specified column if already bound
    ardcol = _SQLGetARDItem ( ard, pColNum );
    
    // EXISTS
    
    if ( ardcol != NULL ) {
        // check if total unbind is required
        if ( pDataPtr == NULL && pDataSizePtr == NULL ) {
            // detach it from ARD link list
            _SQLDetachARDItem ( ard, ardcol );
            // free
            delete ardcol;
        }
        
        else  {
            // unbind/rebind col details
            _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_DATA_PTR, pDataPtr, -1 );
            _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_CONCISE_TYPE, ( void* ) pDataType, -1 );
            _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_LENGTH, ( void* ) pDataSize, -1 );
            _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_OCTET_LENGTH_PTR, pDataSizePtr, -1 );
            // reset the source data type
            ardcol->SrcDataType     = 0;
        }
        
        return SQL_SUCCESS;
    }
    
    // DOES NOT EXIST
    
    // check for bad params
    if ( pDataPtr == NULL && pDataSizePtr == NULL ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLBindCol", "01000", -1, "Bad params" );
        return SQL_ERROR;
    }
    
    // check for bad params
    else if ( pDataSize < 0 ) {
        _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "SQLBindCol", "01000", -1, "Invalid buffer length" );
        return SQL_ERROR;
    }
    
    // CREATE
    // allocate a new col-item
    ardcol = new ARDItem;
    // reset
    _SQLSetARDItemFieldsDefault ( ardcol, pColNum );
    // set all values - bind
    _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_DATA_PTR, pDataPtr, -1 );
    _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_CONCISE_TYPE, ( void* ) pDataType, -1 );
    _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_LENGTH, ( void* ) pDataSize, -1 );
    _SQLSetARDItemField ( ard, ardcol, pColNum, SQL_DESC_OCTET_LENGTH_PTR, pDataSizePtr, -1 );
    // attach it to link list
    _SQLAttachARDItem ( ard, ardcol );
    return SQL_SUCCESS;
}