extensions/clientprefs/query.h
author David Anderson <dvander@alliedmods.net>
Wed Oct 15 01:01:36 2008 -0700 (2008-10-15)
changeset 2359 a51e376f3700
parent 2338 b9a152a270c9
child 2373 01dd8a057823
permissions -rw-r--r--
Various clientprefs logging to try and catch bug 2698 in the act.
pred@2009
     1
/**
pred@2009
     2
 * vim: set ts=4 :
pred@2009
     3
 * =============================================================================
pred@2009
     4
 * SourceMod Client Preferences Extension
pred@2009
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
pred@2009
     6
 * =============================================================================
pred@2009
     7
 *
pred@2009
     8
 * This program is free software; you can redistribute it and/or modify it under
pred@2009
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009
    10
 * Free Software Foundation.
pred@2009
    11
 * 
pred@2009
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2009
    15
 * details.
pred@2009
    16
 *
pred@2009
    17
 * You should have received a copy of the GNU General Public License along with
pred@2009
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2009
    19
 *
pred@2009
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2009
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2009
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2009
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009
    27
 * or <http://www.sourcemod.net/license.php>.
pred@2009
    28
 *
pred@2009
    29
 * Version: $Id$
pred@2009
    30
 */
pred@2009
    31
pred@2009
    32
#ifndef _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
pred@2009
    33
#define _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_
pred@2009
    34
pred@2009
    35
#include "extension.h"
pred@2009
    36
#include "cookie.h"
pred@2009
    37
#include "sh_string.h"
pred@2009
    38
pred@2009
    39
enum querytype
pred@2009
    40
{
pred@2009
    41
	Query_InsertCookie = 0,
pred@2009
    42
	Query_SelectData,
pred@2009
    43
	Query_InsertData,
pred@2048
    44
	Query_SelectId,
pred@2207
    45
	Query_Connect,
pred@2207
    46
};
pred@2207
    47
pred@2207
    48
struct PreparedQueryWrapper;
pred@2207
    49
struct Cookie;
pred@2207
    50
struct CookieData;
pred@2207
    51
#define MAX_NAME_LENGTH 30
pred@2207
    52
pred@2207
    53
/* This stores all the info required for our param binding until the thread is executed */
pred@2207
    54
struct ParamData
pred@2207
    55
{
pred@2207
    56
	ParamData();
pred@2207
    57
pred@2207
    58
	~ParamData();
pred@2207
    59
pred@2207
    60
	/* Contains a name, description and access for InsertCookie queries */
pred@2207
    61
	Cookie *cookie;
pred@2207
    62
	/* A clients steamid - Used for most queries - Doubles as storage for the cookie name*/
pred@2207
    63
	char steamId[MAX_NAME_LENGTH];
pred@2207
    64
pred@2207
    65
	int cookieId;
pred@2207
    66
	CookieData *data;
pred@2009
    67
};
pred@2009
    68
pred@2009
    69
class TQueryOp : public IDBThreadOperation
pred@2009
    70
{
pred@2009
    71
public:
pred@2207
    72
	TQueryOp(enum querytype type, int client);
pred@2207
    73
	TQueryOp(enum querytype type, Cookie *cookie);
pred@2009
    74
	~TQueryOp() {}
pred@2009
    75
pred@2009
    76
	IDBDriver *GetDriver();
pred@2009
    77
	IdentityToken_t *GetOwner();
pred@2009
    78
pred@2207
    79
	void SetDatabase(IDatabase *db);
pred@2207
    80
	void SetPreparedQuery();
pred@2207
    81
pred@2009
    82
	void Destroy();
pred@2009
    83
pred@2009
    84
	void RunThreadPart();
pred@2009
    85
	/* Thread has been cancelled due to driver unloading. Nothing else to do? */
pred@2207
    86
	void CancelThinkPart()	{}
pred@2009
    87
	void RunThinkPart();
pred@2009
    88
pred@2207
    89
	bool BindParamsAndRun();
pred@2207
    90
pred@2207
    91
	/* Params to be bound */
pred@2207
    92
	ParamData m_params;
pred@2207
    93
dvander@2359
    94
	inline IPreparedQuery *GetQuery()
dvander@2359
    95
	{
dvander@2359
    96
		return m_pQuery;
dvander@2359
    97
	}
dvander@2359
    98
dvander@2359
    99
	inline querytype GetType()
dvander@2359
   100
	{
dvander@2359
   101
		return m_type;
dvander@2359
   102
	}
dvander@2359
   103
dvander@2359
   104
	inline IDatabase *GetDB()
dvander@2359
   105
	{
dvander@2359
   106
		return m_database;
dvander@2359
   107
	}
dvander@2359
   108
pred@2009
   109
private:
pred@2207
   110
	IPreparedQuery *m_pQuery;
pred@2207
   111
	IDatabase *m_database;
pred@2207
   112
pred@2207
   113
	/* Query type */
pred@2009
   114
	enum querytype m_type;
pred@2207
   115
pred@2207
   116
	/* Data to be passed to the callback */
pred@2009
   117
	int m_client;
pred@2009
   118
	int m_insertId;
pred@2207
   119
	Cookie *m_pCookie;
pred@2009
   120
};
pred@2009
   121
pred@2009
   122
pred@2009
   123
#endif // _INCLUDE_SOURCEMOD_CLIENTPREFS_QUERY_H_