2 * Copyright (C) 2005-2008 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
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
];
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()
44 bool QueryResultMysql::NextRow()
51 row
= mysql_fetch_row(mResult
);
58 for (uint32 i
= 0; i
< mFieldCount
; i
++)
59 mCurrentRow
[i
].SetValue(row
[i
]);
64 void QueryResultMysql::EndQuery()
68 delete [] mCurrentRow
;
74 mysql_free_result(mResult
);
79 enum Field::DataTypes
QueryResultMysql::ConvertNativeType(enum_field_types mysqlType
) const
83 case FIELD_TYPE_TIMESTAMP
:
86 case FIELD_TYPE_DATETIME
:
88 case FIELD_TYPE_STRING
:
89 case FIELD_TYPE_VAR_STRING
:
93 return Field::DB_TYPE_STRING
;
96 case FIELD_TYPE_SHORT
:
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
;
107 return Field::DB_TYPE_UNKNOWN
;