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 | |
---|
23 | QueryResultMysql::QueryResultMysql(MYSQL_RES *result, uint64 rowCount, uint32 fieldCount) : |
---|
24 | QueryResult(rowCount, fieldCount), mResult(result) |
---|
25 | { |
---|
26 | |
---|
27 | mCurrentRow = new Field[mFieldCount]; |
---|
28 | ASSERT(mCurrentRow); |
---|
29 | |
---|
30 | MYSQL_FIELD *fields = mysql_fetch_fields(mResult); |
---|
31 | |
---|
32 | for (uint32 i = 0; i < mFieldCount; i++) |
---|
33 | { |
---|
34 | mFieldNames[i] = fields[i].name; |
---|
35 | mCurrentRow[i].SetType(ConvertNativeType(fields[i].type)); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | QueryResultMysql::~QueryResultMysql() |
---|
40 | { |
---|
41 | EndQuery(); |
---|
42 | } |
---|
43 | |
---|
44 | bool QueryResultMysql::NextRow() |
---|
45 | { |
---|
46 | MYSQL_ROW row; |
---|
47 | |
---|
48 | if (!mResult) |
---|
49 | return false; |
---|
50 | |
---|
51 | row = mysql_fetch_row(mResult); |
---|
52 | if (!row) |
---|
53 | { |
---|
54 | EndQuery(); |
---|
55 | return false; |
---|
56 | } |
---|
57 | |
---|
58 | for (uint32 i = 0; i < mFieldCount; i++) |
---|
59 | mCurrentRow[i].SetValue(row[i]); |
---|
60 | |
---|
61 | return true; |
---|
62 | } |
---|
63 | |
---|
64 | void QueryResultMysql::EndQuery() |
---|
65 | { |
---|
66 | if (mCurrentRow) |
---|
67 | { |
---|
68 | delete [] mCurrentRow; |
---|
69 | mCurrentRow = 0; |
---|
70 | } |
---|
71 | |
---|
72 | if (mResult) |
---|
73 | { |
---|
74 | mysql_free_result(mResult); |
---|
75 | mResult = 0; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | enum Field::DataTypes QueryResultMysql::ConvertNativeType(enum_field_types mysqlType) const |
---|
80 | { |
---|
81 | switch (mysqlType) |
---|
82 | { |
---|
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: |
---|
95 | |
---|
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; |
---|
108 | } |
---|
109 | } |
---|
110 | #endif |
---|