예제 #1
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::Disconnect
//
//
//
///////////////////////////////////////////////////////////////
bool CDatabaseManagerImpl::Disconnect ( uint hConnection )
{
    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return false;
    }

    // Start disconnect
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::DISCONNECT, hConnection, "" );

    // Complete disconnect
    m_JobQueue->PollCommand ( pJobData, -1 );

    // Check for problems
    if ( pJobData->result.status == EJobResult::FAIL )
    {
        SetLastErrorMessage ( pJobData->result.strReason );
        return false;
    }

    // Remove connection refs
    MapRemove ( m_ConnectionTypeMap, hConnection );
    m_JobQueue->IgnoreConnectionResults ( hConnection );
    return true;
}
예제 #2
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::QueryWithCallbackf
//
// Start a query and direct the result through a callback
//
///////////////////////////////////////////////////////////////
bool CDatabaseManagerImpl::QueryWithCallbackf ( SConnectionHandle hConnection, PFN_DBRESULT pfnDbResult, void* pCallbackContext, const char* szQuery, ... )
{
    va_list vl;
    va_start ( vl, szQuery );

    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return NULL;
    }

    // Insert arguments with correct escapement
    SString strEscapedQuery = InsertQueryArguments ( hConnection, szQuery, vl );

    // Start query
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery );

    // Set callback vars
    pJobData->SetCallback ( pfnDbResult, pCallbackContext );

    return true;
}
예제 #3
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::SetLogLevel
//
//
//
///////////////////////////////////////////////////////////////
void CDatabaseManagerImpl::SetLogLevel ( EJobLogLevelType logLevel, const SString& strLogFilename )
{
    CDbOptionsMap argMap;
    argMap.Set ( "name", strLogFilename );
    argMap.Set ( "level", logLevel );
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::SETLOGLEVEL, NULL, argMap.ToString () );
    m_JobQueue->FreeCommand ( pJobData );
}
예제 #4
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::QueryStart
//
// Start a query
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseManagerImpl::QueryStart ( SConnectionHandle hConnection, const SString& strQuery, CLuaArguments* pArgs )
{
    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return NULL;
    }

    // Insert arguments with correct escapement
    SString strEscapedQuery = InsertQueryArguments ( hConnection, strQuery, pArgs );

    // Start query
    return m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery );
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueManager::AddCommand
//
// AddCommand to correct queue
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseJobQueueManager::AddCommand(EJobCommandType jobType, SConnectionHandle connectionHandle, const SString& strData)
{
    CDatabaseJobQueue* pJobQueue;
    if (jobType == EJobCommand::CONNECT)
    {
        connectionHandle = GetNextConnectionHandle();
        pJobQueue = GetQueueFromConnectCommand(strData);
    }
    else
    {
        pJobQueue = FindQueueFromConnection(connectionHandle);
        if (!pJobQueue)
        {
            return nullptr;
        }
    }
    return pJobQueue->AddCommand(jobType, connectionHandle, strData);
}
예제 #6
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::QueryStartf
//
//
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseManagerImpl::QueryStartf ( SConnectionHandle hConnection, const char* szQuery, ... )
{
    va_list vl;
    va_start ( vl, szQuery );

    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return NULL;
    }

    // Insert arguments with correct escapement
    SString strEscapedQuery = InsertQueryArguments ( hConnection, szQuery, vl );

    // Start query
    return m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery );
}
예제 #7
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::DatabaseConnect
//
// strType is one of the supported database types i.e. "sqlite"
//
///////////////////////////////////////////////////////////////
uint CDatabaseManagerImpl::Connect ( const SString& strType, const SString& strHost, const SString& strUsername, const SString& strPassword, const SString& strOptions )
{
    ClearLastErrorMessage ();

    SString strCombo = strType + "\1" + strHost + "\1" + strUsername + "\1" + strPassword + "\1" + strOptions;

    // Start connect
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::CONNECT, 0, strCombo );

    // Complete connect
    m_JobQueue->PollCommand ( pJobData, -1 );

    // Check for problems
    if ( pJobData->result.status == EJobResult::FAIL )
    {
        SetLastErrorMessage ( pJobData->result.strReason );
        return INVALID_DB_HANDLE;
    }

    // Process result
    MapSet ( m_ConnectionTypeMap, pJobData->result.connectionHandle, strType );
    return pJobData->result.connectionHandle;
}
예제 #8
0
///////////////////////////////////////////////////////////////
//
// CDatabaseManagerImpl::QueryWithResultf
//
// Start a query and wait for the result
//
///////////////////////////////////////////////////////////////
bool CDatabaseManagerImpl::QueryWithResultf ( SConnectionHandle hConnection, CRegistryResult* pResult, const char* szQuery, ... )
{
    va_list vl;
    va_start ( vl, szQuery );

    ClearLastErrorMessage ();

    // Check connection
    if ( !MapContains ( m_ConnectionTypeMap, hConnection ) )
    {
        SetLastErrorMessage ( "Invalid connection" );
        return false;
    }

    // Insert arguments with correct escapement
    SString strEscapedQuery = InsertQueryArguments ( hConnection, szQuery, vl );

    // Start query
    CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery );

    // Wait for result
    QueryPoll ( pJobData, -1 );

    // Process result
    if ( pJobData->result.status == EJobResult::FAIL )
    {
        if ( pResult )
            *pResult = CRegistryResult ();
        return false;
    }
    else
    {
        if ( pResult )
            *pResult = pJobData->result.registryResult;
        return true;
    }
}