Fixed extension version reporting.
3 * =============================================================================
4 * SourceMod SQLite Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
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.
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
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/>.
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>.
34 SqQuery::SqQuery(SqDatabase *parent, sqlite3_stmt *stmt) :
35 m_pParent(parent), m_pStmt(stmt), m_pResults(NULL), m_AffectedRows(0), m_InsertID(0)
37 m_ParamCount = sqlite3_bind_parameter_count(m_pStmt);
38 m_ColCount = sqlite3_column_count(m_pStmt);
39 m_pParent->IncReferenceCount();
45 sqlite3_finalize(m_pStmt);
49 IResultSet *SqQuery::GetResultSet()
54 bool SqQuery::FetchMoreResults()
56 /* We never have multiple result sets */
60 void SqQuery::Destroy()
65 bool SqQuery::BindParamFloat(unsigned int param, float f)
67 /* SQLite is 1 indexed */
70 if (param > m_ParamCount)
75 return (sqlite3_bind_double(m_pStmt, param, (double)f) == SQLITE_OK);
78 bool SqQuery::BindParamNull(unsigned int param)
80 /* SQLite is 1 indexed */
83 if (param > m_ParamCount)
88 return (sqlite3_bind_null(m_pStmt, param) == SQLITE_OK);
91 bool SqQuery::BindParamString(unsigned int param, const char *text, bool copy)
93 /* SQLite is 1 indexed */
96 if (param > m_ParamCount)
101 return (sqlite3_bind_text(m_pStmt, param, text, -1, copy ? SQLITE_TRANSIENT : SQLITE_STATIC) == SQLITE_OK);
104 bool SqQuery::BindParamInt(unsigned int param, int num, bool signd/* =true */)
106 /* SQLite is 1 indexed */
109 if (param > m_ParamCount)
114 return (sqlite3_bind_int(m_pStmt, param, num) == SQLITE_OK);
117 bool SqQuery::BindParamBlob(unsigned int param, const void *data, size_t length, bool copy)
119 /* SQLite is 1 indexed */
122 if (param > m_ParamCount)
127 return (sqlite3_bind_blob(m_pStmt, param, data, length, copy ? SQLITE_TRANSIENT : SQLITE_STATIC) == SQLITE_OK);
130 sqlite3_stmt *SqQuery::GetStmt()
135 bool SqQuery::Execute()
139 /* If we don't have a result set and we have a column count,
140 * create a result set pre-emptively. This is in case there
141 * are no rows in the upcoming result set.
143 if (!m_pResults && m_ColCount)
145 m_pResults = new SqResults(this);
148 /* If we've got results, throw them away */
151 m_pResults->ResetResultCount();
154 /* Fetch each row, if any */
155 while ((rc = sqlite3_step(m_pStmt)) == SQLITE_ROW)
157 /* This should NEVER happen but we're being safe. */
160 m_pResults = new SqResults(this);
162 m_pResults->PushResult();
165 sqlite3 *db = m_pParent->GetDb();
166 if (rc != SQLITE_OK && rc != SQLITE_DONE && rc == sqlite3_errcode(db))
168 /* Something happened... */
169 m_LastErrorCode = rc;
170 m_LastError.assign(sqlite3_errmsg(db));
174 m_LastErrorCode = SQLITE_OK;
175 m_AffectedRows = (unsigned int)sqlite3_changes(db);
176 m_InsertID = (unsigned int)sqlite3_last_insert_rowid(db);
179 /* Reset everything for the next execute */
180 sqlite3_reset(m_pStmt);
181 sqlite3_clear_bindings(m_pStmt);
183 return (m_LastErrorCode == SQLITE_OK);
186 const char *SqQuery::GetError(int *errCode/* =NULL */)
190 *errCode = m_LastErrorCode;
192 return m_LastError.c_str();
195 unsigned int SqQuery::GetAffectedRows()
197 return m_AffectedRows;
200 unsigned int SqQuery::GetInsertID()