[7017] Updated copyright notice for new year
[getmangos.git] / src / shared / Database / QueryResultMysql.cpp
blob755a5532b50b89bd95209fd55af1df86e3fcb3f7
1 /*
2 * Copyright (C) 2005-2009 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 QueryResultMysql::QueryResultMysql(MYSQL_RES *result, uint64 rowCount, uint32 fieldCount) :
24 QueryResult(rowCount, fieldCount), mResult(result)
27 mCurrentRow = new Field[mFieldCount];
28 ASSERT(mCurrentRow);
30 MYSQL_FIELD *fields = mysql_fetch_fields(mResult);
32 for (uint32 i = 0; i < mFieldCount; i++)
34 mFieldNames[i] = fields[i].name;
35 mCurrentRow[i].SetType(ConvertNativeType(fields[i].type));
39 QueryResultMysql::~QueryResultMysql()
41 EndQuery();
44 bool QueryResultMysql::NextRow()
46 MYSQL_ROW row;
48 if (!mResult)
49 return false;
51 row = mysql_fetch_row(mResult);
52 if (!row)
54 EndQuery();
55 return false;
58 for (uint32 i = 0; i < mFieldCount; i++)
59 mCurrentRow[i].SetValue(row[i]);
61 return true;
64 void QueryResultMysql::EndQuery()
66 if (mCurrentRow)
68 delete [] mCurrentRow;
69 mCurrentRow = 0;
72 if (mResult)
74 mysql_free_result(mResult);
75 mResult = 0;
79 enum Field::DataTypes QueryResultMysql::ConvertNativeType(enum_field_types mysqlType) const
81 switch (mysqlType)
83 case FIELD_TYPE_TIMESTAMP:
84 case FIELD_TYPE_DATE:
85 case FIELD_TYPE_TIME:
86 case FIELD_TYPE_DATETIME:
87 case FIELD_TYPE_YEAR:
88 case FIELD_TYPE_STRING:
89 case FIELD_TYPE_VAR_STRING:
90 case FIELD_TYPE_BLOB:
91 case FIELD_TYPE_SET:
92 case FIELD_TYPE_NULL:
93 return Field::DB_TYPE_STRING;
94 case FIELD_TYPE_TINY:
96 case FIELD_TYPE_SHORT:
97 case FIELD_TYPE_LONG:
98 case FIELD_TYPE_INT24:
99 case FIELD_TYPE_LONGLONG:
100 case FIELD_TYPE_ENUM:
101 return Field::DB_TYPE_INTEGER;
102 case FIELD_TYPE_DECIMAL:
103 case FIELD_TYPE_FLOAT:
104 case FIELD_TYPE_DOUBLE:
105 return Field::DB_TYPE_FLOAT;
106 default:
107 return Field::DB_TYPE_UNKNOWN;
110 #endif