void CRUDupElimLogScanner::StartScan(Int32 phase)
{
	RUASSERT(NULL == pCurrentStmt_ && NULL == pResultSet_);

	if (0 == phase)
	{
		pCurrentStmt_ = GetPreparedStatement(CRUDupElimConst::PHASE_0_QUERY);
	}
	else
	{
		RUASSERT(phase > 0);

		// The same statement for each phase starting from 1
		pCurrentStmt_ = GetPreparedStatement(CRUDupElimConst::PHASE_1_QUERY);

		// Set the parameters for the lower bound ...
		CopyLowerBoundParams();
	}

	// Start the execution ...
	pCurrentStmt_->ExecuteQuery();
	pResultSet_ = pCurrentStmt_->GetResultSet();

	if (0 == phase)
	{
		// Allocate the buffer space and setup the output descriptors
		SetupScan();
	}
	else
	{
		// Nothing. Both queries have the same result set's structure.
		// Hence, we need not re-allocate the buffers.
	}
}
char const *
	CRUSQLDynamicStatementContainer::DynamicStmt::GetLastSQL()
{
	if (NULL != GetPreparedStatement() )
	{
		return  GetPreparedStatement()->GetSqlString();
	}
	else
	{
		return sql_;
	}
}
Beispiel #3
0
bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount)
{
    if (!m_Mysql)
        return false;

    uint32 index = stmt->m_index;
    {
        MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index);
        ASSERT(m_mStmt);            // Can only be null if preparation failed, server side error or bad query
        m_mStmt->m_stmt = stmt;     // Cross reference them for debug output
        stmt->m_stmt = m_mStmt;     // TODO: Cleaner way

        stmt->BindParameters();

        MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
        MYSQL_BIND* msql_BIND = m_mStmt->GetBind();

        uint32 _s = 0;
        if (sLog->GetSQLDriverQueryLogging())
            _s = getMSTime();

        if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return _Query(stmt, pResult, pRowCount, pFieldCount);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (mysql_stmt_execute(msql_STMT))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLog->outSQLDriver("SQL(p): %s\n [ERROR]: [%u] %s",
                m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return _Query(stmt, pResult, pRowCount, pFieldCount);      // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (sLog->GetSQLDriverQueryLogging())
            sLog->outSQLDriver("[%u ms] SQL(p): %s", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString(m_queries[index].first).c_str());

        m_mStmt->ClearParameters();

        *pResult = mysql_stmt_result_metadata(msql_STMT);
        *pRowCount = mysql_stmt_num_rows(msql_STMT);
        *pFieldCount = mysql_stmt_field_count(msql_STMT);

        return true;

    }
}
bool MySQLConnection::Execute(PreparedStatement* stmt)
{
    if (!m_Mysql)
        return false;

    uint32 index = stmt->m_index;
    {
        MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index);
        ASSERT(m_mStmt);            // Can only be null if preparation failed, server side error or bad query
        m_mStmt->m_stmt = stmt;     // Cross reference them for debug output
        stmt->m_stmt = m_mStmt;     // TODO: Cleaner way

        stmt->BindParameters();

        MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
        MYSQL_BIND* msql_BIND = m_mStmt->GetBind();

        uint32 _s = 0;
        if (sLog->GetSQLDriverQueryLogging())
            _s = getMSTime();

        if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error binding params:  [%u] %s",
                index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
            
            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled succesfuly (ie reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (mysql_stmt_execute(msql_STMT))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLog->outSQLDriver("[ERROR]: PreparedStatement (id: %u, database: `%s`) error executing:  [%u] %s",
                index, m_connectionInfo.database.c_str(), lErrno, mysql_stmt_error(msql_STMT));
            
            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled succesfuly (ie reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }
        
        if (sLog->GetSQLDriverQueryLogging())
            sLog->outSQLDriver("[%u ms] Prepared SQL: %u on database `%s`",
                getMSTimeDiff(_s, getMSTime()), index, m_connectionInfo.database.c_str());
 
        m_mStmt->ClearParameters();
        return true;
    }
}
bool MySQLConnection::Execute(PreparedStatement* stmt)
{
    if (!m_Mysql)
        return false;

    uint32 index = stmt->m_index;
    {
        MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index);
        ASSERT(m_mStmt);            // Can only be null if preparation failed, server side error or bad query
        m_mStmt->m_stmt = stmt;     // Cross reference them for debug output
        stmt->m_stmt = m_mStmt;     // TODO: Cleaner way

        stmt->BindParameters();

        MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
        MYSQL_BIND* msql_BIND = m_mStmt->GetBind();

        uint32 _s = 0;
        if (sLogMgr->IsLogEnabled(SQLDRIVER_LOG))
            _s = getMSTime();

        if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLogMgr->WriteLn(SQLDRIVER_LOG, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (mysql_stmt_execute(msql_STMT))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            sLogMgr->WriteLn(SQLDRIVER_LOG, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (sLogMgr->IsLogEnabled(SQLDRIVER_LOG))
            sLogMgr->WriteLn(SQLDRIVER_LOG, "[%u ms] SQL(p): %s", getMSTimeDiff(_s, getMSTime()), m_mStmt->getQueryString(m_queries[index].first).c_str());

        m_mStmt->ClearParameters();
        return true;
    }
}
bool MySqlConnection::_Query(PreparedStmt* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount)
{
	if (!m_Mysql)
		return false;

	uint32 index = stmt->m_stmtIndex;
	{
		MySqlPreparedStmt* pStmt = GetPreparedStatement(index);
		pStmt->m_pPrepareStmt = stmt;     // Cross reference them for debug output
		stmt->m_pStmt = pStmt;     /// @todo Cleaner way

		stmt->bindParameters();

		MYSQL_STMT* msql_STMT = pStmt->GetMySqlStmt();
		MYSQL_BIND* msql_BIND = pStmt->GetBind();

		if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
		{
			uint32 lErrno = mysql_errno(m_Mysql);
			ERROR_LOG("SQL(p): %s\n [ERROR]: [%u] %s\n", pStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

			if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
				return _Query(stmt, pResult, pRowCount, pFieldCount);       // Try again

			pStmt->clearParameters();
			return false;
		}

		TRACE_LOG("Exe SQL(p): %s\n\n", pStmt->getQueryString(m_queries[index].first).c_str());
		if (mysql_stmt_execute(msql_STMT))
		{
			uint32 lErrno = mysql_errno(m_Mysql);
			ERROR_LOG("SQL(p): %s\n [ERROR]: [%u] %s\n",
                      pStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

			if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
				return _Query(stmt, pResult, pRowCount, pFieldCount);      // Try again

			pStmt->clearParameters();
			return false;
		}
		
		pStmt->clearParameters();

		*pResult = mysql_stmt_result_metadata(msql_STMT);
		*pRowCount = mysql_stmt_num_rows(msql_STMT);
		*pFieldCount = mysql_stmt_field_count(msql_STMT);

		return true;
	}
}
bool MySQLConnection::Execute(PreparedStatement* stmt)
{
    if (!m_Mysql)
        return false;

    uint32 index = stmt->m_index;
    {
        MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index);
        ASSERT(m_mStmt);            // Can only be null if preparation failed, server side error or bad query
        m_mStmt->m_stmt = stmt;     // Cross reference them for debug output
        stmt->m_stmt = m_mStmt;     /// @todo Cleaner way

        stmt->BindParameters();

        MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
        MYSQL_BIND* msql_BIND = m_mStmt->GetBind();

       boost::timer _s;

        if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            _LOG_ERROR(LOG_FILTER_SQL, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        if (mysql_stmt_execute(msql_STMT))
        {
            uint32 lErrno = mysql_errno(m_Mysql);
            _LOG_ERROR(LOG_FILTER_SQL, "SQL(p): %s\n [ERROR]: [%u] %s", m_mStmt->getQueryString(m_queries[index].first).c_str(), lErrno, mysql_stmt_error(msql_STMT));

            if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
                return Execute(stmt);       // Try again

            m_mStmt->ClearParameters();
            return false;
        }

        _LOG_DEBUG(LOG_FILTER_SQL, "[%u ms] SQL(p): %s",(uint32)_s.elapsed(), m_mStmt->getQueryString(m_queries[index].first).c_str());

        m_mStmt->ClearParameters();
        return true;
    }
}
bool MySQLConnection::Execute(PreparedStatement* stmt)
{
    if (!m_Mysql)
        return false;

    uint32 index = stmt->m_index;
    {
        // guarded block for thread-safe mySQL request
        ACE_Guard<ACE_Thread_Mutex> query_connection_guard(m_Mutex);

        MySQLPreparedStatement* m_mStmt = GetPreparedStatement(index);
        ASSERT(m_mStmt);            // Can only be null if preparation failed, server side error or bad query
        m_mStmt->m_stmt = stmt;     // Cross reference them for debug output
        stmt->m_stmt = m_mStmt;     // TODO: Cleaner way

        stmt->BindParameters();

        MYSQL_STMT* msql_STMT = m_mStmt->GetSTMT();
        MYSQL_BIND* msql_BIND = m_mStmt->GetBind();

        #ifdef SQLQUERY_LOG
        uint32 _s = getMSTime();
        #endif
        if (mysql_stmt_bind_param(msql_STMT, msql_BIND))
        {
            sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u) error binding params:  %s", index, mysql_stmt_error(msql_STMT));
            m_mStmt->ClearParameters();
            return false;
        }

        if (mysql_stmt_execute(msql_STMT))
        {
            sLog.outSQLDriver("[ERROR]: PreparedStatement (id: %u) error executing:  %s", index, mysql_stmt_error(msql_STMT));
            m_mStmt->ClearParameters();
            return false;
        }
        else
        {
            #ifdef SQLQUERY_LOG
            sLog.outSQLDriver("[%u ms] Prepared SQL: %u", getMSTimeDiff(_s, getMSTime()), index);
            #endif
            m_mStmt->ClearParameters();
            return true;
        }
    }
}
bool MySqlConnection::Execute(PreparedStmt* stmt)
{
    if (!m_Mysql)
		return false;

	uint32 index = stmt->m_stmtIndex;
	MySqlPreparedStmt* pStmt = GetPreparedStatement(index);
	pStmt->m_pPrepareStmt = stmt;
	stmt->m_pStmt = pStmt;
	stmt->bindParameters();	
	MYSQL_STMT* pMySqlStmt = pStmt->GetMySqlStmt();
	MYSQL_BIND* pMySqlBind = pStmt->GetBind();
	if (mysql_stmt_bind_param(pMySqlStmt, pMySqlBind))
	{
		uint32 lErrno = mysql_errno(m_Mysql);	
		ERROR_LOG("MySqlConnection::execute mysql_stmt_bind_param failed %u\n", lErrno);
		if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
            return Execute(stmt);       // Try again
			
		pStmt->clearParameters();
		return false;
	}
	TRACE_LOG("Exe SQL(p): %s\n\n", pStmt->getQueryString(m_queries[index].first).c_str());
	if (mysql_stmt_execute(pMySqlStmt))
	{
		uint32 lErrno = mysql_errno(m_Mysql);
		ERROR_LOG("MySqlConnection::execute mysql_stmt_bind_param failed %u\n", lErrno);
		if (_HandleMySQLErrno(lErrno))  // If it returns true, an error was handled successfully (i.e. reconnection)
            return Execute(stmt);       // Try again
				
		pStmt->clearParameters();
		return false;
	}

	return true;
}