[6844] Daily quest fixes.
[getmangos.git] / src / shared / Database / QueryResultSqlite.cpp
blob53adb72ccb7c80f82f8206122eecb70bacaa23e4
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef DO_POSTGRESQL
21 #include "DatabaseEnv.h"
23 QueryResultSqlite::QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount) :
24 QueryResult(rowCount, fieldCount), mTableData(tableData), mTableIndex(0)
26 mCurrentRow = new Field[mFieldCount];
28 for (uint32 i = 0; i < mFieldCount; i++)
30 mFieldNames[i] = mTableData[i];
31 mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN);
35 QueryResultSqlite::~QueryResultSqlite()
37 EndQuery();
40 bool QueryResultSqlite::NextRow()
42 int startIndex;
43 uint32 i;
45 if (!mTableData)
46 return false;
48 if (mTableIndex >= mRowCount)
50 EndQuery();
51 return false;
54 startIndex = (mTableIndex + 1) * mFieldCount;
55 for (i = 0; i < mFieldCount; i++)
57 mCurrentRow[i].SetValue(mTableData[startIndex + i]);
60 ++mTableIndex;
61 return true;
64 void QueryResultSqlite::EndQuery()
66 if (mCurrentRow)
68 delete [] mCurrentRow;
69 mCurrentRow = NULL;
71 if (mTableData)
73 sqlite_free_table(mTableData);
74 mTableData = NULL;
78 enum Field::DataTypes QueryResultSqlite::ConvertNativeType(const char* sqliteType) const
80 if (sqliteType)
82 switch (*sqliteType)
84 case 'S':
85 return Field::DB_TYPE_STRING;
86 case 'I':
87 return Field::DB_TYPE_INTEGER;
88 case 'F':
89 return Field::DB_TYPE_FLOAT;
90 default:
91 return Field::DB_TYPE_UNKNOWN;
94 return Field::DB_TYPE_UNKNOWN;
96 #endif