/////////////////////////////////////////////////////////////// // // 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; }
/////////////////////////////////////////////////////////////// // // 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 ); }
/////////////////////////////////////////////////////////////// // // CDatabaseJobQueueManager::IgnoreConnectionResults // // Throw away results for all jobs using this connection // /////////////////////////////////////////////////////////////// void CDatabaseJobQueueManager::IgnoreConnectionResults(SConnectionHandle connectionHandle) { CDatabaseJobQueue* pJobQueue = FindQueueFromConnection(connectionHandle); if (!pJobQueue) return; pJobQueue->IgnoreConnectionResults(connectionHandle); }
/////////////////////////////////////////////////////////////// // // 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; }
/////////////////////////////////////////////////////////////// // // 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); }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::Exec // // Start a query and ignore the result // /////////////////////////////////////////////////////////////// CDbJobData* CDatabaseManagerImpl::Exec ( 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 CDbJobData* pJobData = m_JobQueue->AddCommand ( EJobCommand::QUERY, hConnection, strEscapedQuery ); // Ignore result m_JobQueue->FreeCommand ( pJobData ); return pJobData; }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::QueryPoll // // ulTimeout = 0 - No wait if not ready // ulTimeout > 0 - Wait(ms) if not ready // ulTimeout = -1 - Wait infinity+1 if not ready // /////////////////////////////////////////////////////////////// bool CDatabaseManagerImpl::QueryPoll ( CDbJobData* pJobData, uint ulTimeout ) { ClearLastErrorMessage (); if ( m_JobQueue->PollCommand ( pJobData, ulTimeout ) ) { if ( pJobData->result.status == EJobResult::FAIL ) SetLastErrorMessage ( pJobData->result.strReason ); return true; } return false; }
/////////////////////////////////////////////////////////////// // // 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; }
/////////////////////////////////////////////////////////////// // // 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 ); }
/////////////////////////////////////////////////////////////// // // 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; } }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::GetQueryFromId // // // /////////////////////////////////////////////////////////////// CDbJobData* CDatabaseManagerImpl::GetQueryFromId ( SDbJobId id ) { return m_JobQueue->FindCommandFromId ( id ); }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::QueryFree // // // /////////////////////////////////////////////////////////////// bool CDatabaseManagerImpl::QueryFree ( CDbJobData* pJobData ) { ClearLastErrorMessage (); return m_JobQueue->FreeCommand ( pJobData ); }
/////////////////////////////////////////////////////////////// // // CDatabaseManagerImpl::DoPulse // // Check if any callback functions are due // /////////////////////////////////////////////////////////////// void CDatabaseManagerImpl::DoPulse ( void ) { m_JobQueue->DoPulse (); }