extensions/sqlite/driver/SqDatabase.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 29 01:15:31 2007 +0000 (2007-07-29)
changeset 1203 633c25ce6405
child 1226 478550a4d5ec
permissions -rw-r--r--
initial import of sqlite extension
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod SQLite Driver Extension
     5  * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
     6  * ===============================================================
     7  *
     8  * This program is free software; you can redistribute it and/or
     9  * modify it under the terms of the GNU General Public License
    10  * as published by the Free Software Foundation; either version 2
    11  * of the License, or (at your option) any later version.
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  * 
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    20  *
    21  * Version: $Id$
    22  */
    23 
    24 #ifndef _INCLUDE_SQLITE_SOURCEMOD_DATABASE_H_
    25 #define _INCLUDE_SQLITE_SOURCEMOD_DATABASE_H_
    26 
    27 #include <IThreader.h>
    28 #include "SqDriver.h"
    29 
    30 class SqDatabase : public IDatabase
    31 {
    32 public:
    33 	SqDatabase(sqlite3 *sq3, bool persistent);
    34 	~SqDatabase();
    35 public:
    36 	bool Close();
    37 	const char *GetError(int *errorCode=NULL);
    38 	bool DoSimpleQuery(const char *query);
    39 	IQuery *DoQuery(const char *query);
    40 	IPreparedQuery *PrepareQuery(const char *query, char *error, size_t maxlength, int *errCode=NULL);
    41 	bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize);
    42 	unsigned int GetAffectedRows();
    43 	unsigned int GetInsertID();
    44 	bool LockForFullAtomicOperation();
    45 	void UnlockFromFullAtomicOperation();
    46 	void IncReferenceCount();
    47 	IDBDriver *GetDriver();
    48 public:
    49 	sqlite3 *GetDb();
    50 private:
    51 	sqlite3 *m_sq3;
    52 	unsigned int m_refcount;
    53 	IMutex *m_pFullLock;
    54 	IMutex *m_pRefLock;
    55 	bool m_Persistent;
    56 	String m_LastError;
    57 	int m_LastErrorCode;
    58 };
    59 
    60 #endif //_INCLUDE_SQLITE_SOURCEMOD_DATABASE_H_