extensions/clientprefs/query.cpp
author Matt Woodrow <pred@alliedmods.net>
Sun Jul 06 03:30:06 2008 +0000 (2008-07-06)
changeset 2165 ca3757e676f6
parent 2131 cbad21fc7626
child 2207 3a97a56ded62
permissions -rw-r--r--
Fixed requiring dependencies at the wrong time.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Client Preferences Extension
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include "query.h"
    33 
    34 
    35 void TQueryOp::RunThinkPart()
    36 {
    37 	//handler for threaded sql queries
    38 
    39 	if (m_pQuery)
    40 	{
    41 		switch (m_type)
    42 		{
    43 		case Query_InsertCookie:
    44 			g_CookieManager.InsertCookieCallback(pCookie, m_insertId);
    45 			break;
    46 		case Query_SelectData:
    47 			g_CookieManager.ClientConnectCallback(m_client, m_pQuery);
    48 			break;
    49 		case Query_InsertData:
    50 			//No specific handling
    51 			break;
    52 		case Query_SelectId:
    53 			g_CookieManager.SelectIdCallback(pCookie, m_pQuery);
    54 			break;
    55 		default:
    56 			break;
    57 		}
    58 
    59 		m_pQuery->Destroy();
    60 	}
    61 	else
    62 	{
    63 		g_pSM->LogError(myself,"Failed SQL Query, Error: \"%s\" (Query id %i - client %i)", error, m_type, m_client);
    64 	}
    65 }
    66 
    67 void TQueryOp::RunThreadPart()
    68 {
    69 	m_pDatabase->LockForFullAtomicOperation();
    70 	m_pQuery = m_pDatabase->DoQuery(m_Query.c_str());
    71 
    72 	if (!m_pQuery)
    73 	{
    74 		g_pSM->LogError(myself, "Failed SQL Query, Error: \"%s\" (Query id %i - client %i)", m_pDatabase->GetError(), m_type, m_client);
    75 	}
    76 
    77 	m_insertId = g_ClientPrefs.Database->GetInsertID();
    78 
    79 	m_pDatabase->UnlockFromFullAtomicOperation();
    80 }
    81 
    82 IDBDriver *TQueryOp::GetDriver()
    83 {
    84 	return m_pDatabase->GetDriver();
    85 }
    86 IdentityToken_t *TQueryOp::GetOwner()
    87 {
    88 	return myself->GetIdentity();
    89 }
    90 void TQueryOp::Destroy()
    91 {
    92 	delete this;
    93 }
    94 
    95 TQueryOp::TQueryOp(IDatabase *db, const char *query, enum querytype type, int client)
    96 {
    97 	m_pDatabase = db;
    98 	m_Query = query;
    99 	m_type = type;
   100 	m_client = client;
   101 	m_pQuery = NULL;
   102 
   103 	m_pDatabase->IncReferenceCount();
   104 }
   105 
   106 TQueryOp::TQueryOp(IDatabase *db, const char *query, enum querytype type, Cookie *cookie)
   107 {
   108 	m_pDatabase = db;
   109 	m_Query = query;
   110 	m_type = type;
   111 	pCookie = cookie;
   112 	m_pQuery = NULL;
   113 
   114 	m_pDatabase->IncReferenceCount();
   115 }