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

Revision 2, 2.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef DO_POSTGRESQL
20
21#include "DatabaseEnv.h"
22
23QueryResultSqlite::QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount) :
24QueryResult(rowCount, fieldCount), mTableData(tableData), mTableIndex(0)
25{
26    mCurrentRow = new Field[mFieldCount];
27
28    for (uint32 i = 0; i < mFieldCount; i++)
29    {
30        mFieldNames[i] = mTableData[i];
31        mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN);
32    }
33}
34
35QueryResultSqlite::~QueryResultSqlite()
36{
37    EndQuery();
38}
39
40bool QueryResultSqlite::NextRow()
41{
42    int startIndex;
43    uint32 i;
44
45    if (!mTableData)
46        return false;
47
48    if (mTableIndex >= mRowCount)
49    {
50        EndQuery();
51        return false;
52    }
53
54    startIndex = (mTableIndex + 1) * mFieldCount;
55    for (i = 0; i < mFieldCount; i++)
56    {
57        mCurrentRow[i].SetValue(mTableData[startIndex + i]);
58    }
59
60    ++mTableIndex;
61    return true;
62}
63
64void QueryResultSqlite::EndQuery()
65{
66    if (mCurrentRow)
67    {
68        delete [] mCurrentRow;
69        mCurrentRow = NULL;
70    }
71    if (mTableData)
72    {
73        sqlite_free_table(mTableData);
74        mTableData = NULL;
75    }
76}
77
78enum Field::DataTypes QueryResultSqlite::ConvertNativeType(const char* sqliteType) const
79{
80    if (sqliteType)
81    {
82        switch (*sqliteType)
83        {
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;
92        };
93    }
94    return Field::DB_TYPE_UNKNOWN;
95}
96#endif
Note: See TracBrowser for help on using the browser.