extensions/sqlite/driver/SqQuery.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 29 14:56:24 2007 +0000 (2007-07-29)
changeset 1210 18e60c8737a2
parent 1203 633c25ce6405
child 1226 478550a4d5ec
permissions -rw-r--r--
fixed an sqlite bug where empty results would count as no result set
     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_QUERY_H_
    25 #define _INCLUDE_SQLITE_SOURCEMOD_QUERY_H_
    26 
    27 #include "SqDatabase.h"
    28 #include "SqResults.h"
    29 
    30 class SqQuery : 
    31 	public IPreparedQuery
    32 {
    33 public:
    34 	SqQuery(SqDatabase *parent, sqlite3_stmt *stmt);
    35 	~SqQuery();
    36 public: //IQuery
    37 	IResultSet *GetResultSet();
    38 	bool FetchMoreResults();
    39 	void Destroy();
    40 public: //IPreparedQuery
    41 	bool BindParamInt(unsigned int param, int num, bool signd=true);
    42 	bool BindParamFloat(unsigned int param, float f);
    43 	bool BindParamNull(unsigned int param);
    44 	bool BindParamString(unsigned int param, const char *text, bool copy);
    45 	bool BindParamBlob(unsigned int param, const void *data, size_t length, bool copy);
    46 	bool Execute();
    47 	const char *GetError(int *errCode=NULL);
    48 	unsigned int GetAffectedRows();
    49 	unsigned int GetInsertID();
    50 public: //IResultSet
    51 	unsigned int GetRowCount();
    52 	unsigned int GetFieldCount();
    53 	const char *FieldNumToName(unsigned int columnId);
    54 	bool FieldNameToNum(const char *name, unsigned int *columnId);
    55 	bool MoreRows();
    56 	IResultRow *FetchRow();
    57 	IResultRow *CurrentRow();
    58 	bool Rewind();
    59 	DBType GetFieldType(unsigned int field);
    60 	DBType GetFieldDataType(unsigned int field);
    61 public: //IResultRow
    62 	DBResult GetString(unsigned int columnId, const char **pString, size_t *length);
    63 	DBResult CopyString(unsigned int columnId, 
    64 		char *buffer, 
    65 		size_t maxlength, 
    66 		size_t *written);
    67 	DBResult GetFloat(unsigned int columnId, float *pFloat);
    68 	DBResult GetInt(unsigned int columnId, int *pInt);
    69 	bool IsNull(unsigned int columnId);
    70 	size_t GetDataSize(unsigned int columnId);
    71 	DBResult GetBlob(unsigned int columnId, const void **pData, size_t *length);
    72 	DBResult CopyBlob(unsigned int columnId, void *buffer, size_t maxlength, size_t *written);
    73 public:
    74 	sqlite3_stmt *GetStmt();
    75 private:
    76 	SqDatabase *m_pParent;
    77 	sqlite3_stmt *m_pStmt;
    78 	SqResults *m_pResults;
    79 	unsigned int m_ParamCount;
    80 	String m_LastError;
    81 	int m_LastErrorCode;
    82 	unsigned int m_AffectedRows;
    83 	unsigned int m_InsertID;
    84 	unsigned int m_ColCount;
    85 };
    86 
    87 #endif //_INCLUDE_SQLITE_SOURCEMOD_QUERY_H_