root/trunk/src/shared/Database/QueryResultSqlite.cpp @ 102

Revision 102, 2.4 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef DO_POSTGRESQL
22
23#include "DatabaseEnv.h"
24
25QueryResultSqlite::QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount) :
26QueryResult(rowCount, fieldCount), mTableData(tableData), mTableIndex(0)
27{
28    mCurrentRow = new Field[mFieldCount];
29
30    for (uint32 i = 0; i < mFieldCount; i++)
31    {
32        mFieldNames[i] = mTableData[i];
33        mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN);
34    }
35}
36
37QueryResultSqlite::~QueryResultSqlite()
38{
39    EndQuery();
40}
41
42bool QueryResultSqlite::NextRow()
43{
44    int startIndex;
45    uint32 i;
46
47    if (!mTableData)
48        return false;
49
50    if (mTableIndex >= mRowCount)
51    {
52        EndQuery();
53        return false;
54    }
55
56    startIndex = (mTableIndex + 1) * mFieldCount;
57    for (i = 0; i < mFieldCount; i++)
58    {
59        mCurrentRow[i].SetValue(mTableData[startIndex + i]);
60    }
61
62    ++mTableIndex;
63    return true;
64}
65
66void QueryResultSqlite::EndQuery()
67{
68    if (mCurrentRow)
69    {
70        delete [] mCurrentRow;
71        mCurrentRow = NULL;
72    }
73    if (mTableData)
74    {
75        sqlite_free_table(mTableData);
76        mTableData = NULL;
77    }
78}
79
80enum Field::DataTypes QueryResultSqlite::ConvertNativeType(const char* sqliteType) const
81{
82    if (sqliteType)
83    {
84        switch (*sqliteType)
85        {
86            case 'S':
87                return Field::DB_TYPE_STRING;
88            case 'I':
89                return Field::DB_TYPE_INTEGER;
90            case 'F':
91                return Field::DB_TYPE_FLOAT;
92            default:
93                return Field::DB_TYPE_UNKNOWN;
94        };
95    }
96    return Field::DB_TYPE_UNKNOWN;
97}
98#endif
Note: See TracBrowser for help on using the browser.