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

Revision 102, 2.8 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
25QueryResultMysql::QueryResultMysql(MYSQL_RES *result, uint64 rowCount, uint32 fieldCount) :
26QueryResult(rowCount, fieldCount), mResult(result)
27{
28
29    mCurrentRow = new Field[mFieldCount];
30    ASSERT(mCurrentRow);
31
32    MYSQL_FIELD *fields = mysql_fetch_fields(mResult);
33
34    for (uint32 i = 0; i < mFieldCount; i++)
35    {
36        mFieldNames[i] = fields[i].name;
37        mCurrentRow[i].SetType(ConvertNativeType(fields[i].type));
38    }
39}
40
41QueryResultMysql::~QueryResultMysql()
42{
43    EndQuery();
44}
45
46bool QueryResultMysql::NextRow()
47{
48    MYSQL_ROW row;
49
50    if (!mResult)
51        return false;
52
53    row = mysql_fetch_row(mResult);
54    if (!row)
55    {
56        EndQuery();
57        return false;
58    }
59
60    for (uint32 i = 0; i < mFieldCount; i++)
61        mCurrentRow[i].SetValue(row[i]);
62
63    return true;
64}
65
66void QueryResultMysql::EndQuery()
67{
68    if (mCurrentRow)
69    {
70        delete [] mCurrentRow;
71        mCurrentRow = 0;
72    }
73
74    if (mResult)
75    {
76        mysql_free_result(mResult);
77        mResult = 0;
78    }
79}
80
81enum Field::DataTypes QueryResultMysql::ConvertNativeType(enum_field_types mysqlType) const
82{
83    switch (mysqlType)
84    {
85        case FIELD_TYPE_TIMESTAMP:
86        case FIELD_TYPE_DATE:
87        case FIELD_TYPE_TIME:
88        case FIELD_TYPE_DATETIME:
89        case FIELD_TYPE_YEAR:
90        case FIELD_TYPE_STRING:
91        case FIELD_TYPE_VAR_STRING:
92        case FIELD_TYPE_BLOB:
93        case FIELD_TYPE_SET:
94        case FIELD_TYPE_NULL:
95            return Field::DB_TYPE_STRING;
96        case FIELD_TYPE_TINY:
97
98        case FIELD_TYPE_SHORT:
99        case FIELD_TYPE_LONG:
100        case FIELD_TYPE_INT24:
101        case FIELD_TYPE_LONGLONG:
102        case FIELD_TYPE_ENUM:
103            return Field::DB_TYPE_INTEGER;
104        case FIELD_TYPE_DECIMAL:
105        case FIELD_TYPE_FLOAT:
106        case FIELD_TYPE_DOUBLE:
107            return Field::DB_TYPE_FLOAT;
108        default:
109            return Field::DB_TYPE_UNKNOWN;
110    }
111}
112#endif
Note: See TracBrowser for help on using the browser.