Exemple #1
0
CDB_Result *CMySQL_LangCmd::Result()
{
    m_HasMoreResults = false;
    _ASSERT(m_Connect);
    return Create_Result(*new CMySQL_RowResult(*m_Connect));
}
Exemple #2
0
CDB_Result* CODBC_RPCCmd::Result()
{
    enum {eNameStrLen = 64};

    if (m_Res) {
        delete m_Res;
        m_Res = 0;
        m_HasMoreResults = xCheck4MoreResults();
    }

    if ( !WasSent() ) {
        string err_message = "A command has to be sent first." + GetDbgInfo();
        DATABASE_DRIVER_ERROR( err_message, 420010 );
    }

    if(!m_HasMoreResults) {
        SetWasSent(false);
        return 0;
    }

    SQLSMALLINT nof_cols = 0;
    odbc::TChar buffer[eNameStrLen];

    while(m_HasMoreResults) {
        CheckSIE(SQLNumResultCols(GetHandle(), &nof_cols),
                 "SQLNumResultCols failed", 420011);

        if(nof_cols < 1) { // no data in this result set
            SQLLEN rc;

            CheckSIE(SQLRowCount(GetHandle(), &rc),
                     "SQLRowCount failed", 420013);

            m_RowCount = rc;
            m_HasMoreResults = xCheck4MoreResults();
            continue;
        }

        if(nof_cols == 1) { // it could be a status result
            SQLSMALLINT l;

            CheckSIE(SQLColAttribute(GetHandle(),
                                     1,
                                     SQL_DESC_LABEL,
                                     buffer,
                                     sizeof(buffer),
                                     &l,
                                     0),
                     "SQLColAttribute failed", 420015);

            if(util::strcmp(buffer, _T_NCBI_ODBC("STpROCrETURNsTATUS")) == 0) {
				//this is a status result
                m_HasStatus = true;
                m_Res = new CODBC_StatusResult(*this);
            }
        }
        if(!m_Res) {
            if(m_HasStatus) {
                m_HasStatus = false;
                m_Res = new CODBC_ParamResult(*this, nof_cols);
            }
            else {
                m_Res = new CODBC_RowResult(*this, nof_cols, &m_RowCount);
            }
        }
        return Create_Result(*m_Res);
    }

    SetWasSent(false);
    return 0;
}
Exemple #3
0
RETCODE CDBL_Connection::x_Results(DBPROCESS* pLink)
{
    unsigned int              x_Status = 0x1;
    unique_ptr<CDB_Result>    dbres;
    unique_ptr<impl::CResult> res;

    while ((x_Status & 0x1) != 0) {
        if ((x_Status & 0x20) != 0) { // check for return parameters from exec
            x_Status ^= 0x20;
            int n;
            if (GetResultProcessor() && (n = Check(dbnumrets(pLink))) > 0) {
                res.reset(new CDBL_ParamResult(*this, pLink, n));
                dbres.reset(Create_Result(*res));
                GetResultProcessor()->ProcessResult(*dbres);
                dbres.reset();
                res.reset();
            }
            continue;
        }

        if ((x_Status & 0x40) != 0) { // check for ret status
            x_Status ^= 0x40;
            if (GetResultProcessor() && Check(dbhasretstat(pLink))) {
                res.reset(new CDBL_StatusResult(*this, pLink));
                dbres.reset(Create_Result(*res));
                GetResultProcessor()->ProcessResult(*dbres);
                dbres.reset();
                res.reset();
            }
            continue;
        }
        if ((x_Status & 0x10) != 0) { // we do have a compute result
            res.reset(new CDBL_ComputeResult(*this, pLink, &x_Status));
            dbres.reset(Create_Result(*res));
            if(GetResultProcessor()) {
                GetResultProcessor()->ProcessResult(*dbres);
            }
            else {
                while(dbres->Fetch())
                    continue;
            }
            dbres.reset();
            res.reset();
        }

        RETCODE rc = Check(dbresults(pLink));

        switch (rc) {
        case SUCCEED:
            x_Status |= 0x60;
            if (DBCMDROW(pLink) == SUCCEED) { // we could get rows in result
                if(!GetResultProcessor()) {
                    while(1) {
                        switch(Check(dbnextrow(pLink))) {
                        case NO_MORE_ROWS:
                        case FAIL:
                        case BUF_FULL: break;
                        default: continue;
                        }
                        break;
                    }
                    continue;
                }

                if (Check(dbnumcols(pLink)) == 1) {
                    int ct = Check(dbcoltype(pLink, 1));
                    if ((ct == SYBTEXT) || (ct == SYBIMAGE)) {
                        res.reset(new CDBL_BlobResult(*this, pLink));
                    }
                }
                if ( !res.get() )
                    res.reset(new CDBL_RowResult(*this, pLink, &x_Status));
                dbres.reset(Create_Result(*res));
                GetResultProcessor()->ProcessResult(*dbres);
                dbres.reset();
                res.reset();
            } else {
                continue;
            }
        case NO_MORE_RESULTS:
            x_Status = 2;
            break;
        default:
            return FAIL;
        }
        break;
    }

    return SUCCEED;
}