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 | #if !defined(QUERYRESULT_H) |
---|
22 | #define QUERYRESULT_H |
---|
23 | |
---|
24 | class TRINITY_DLL_SPEC QueryResult |
---|
25 | { |
---|
26 | public: |
---|
27 | QueryResult(uint64 rowCount, uint32 fieldCount) |
---|
28 | : mFieldCount(fieldCount), mRowCount(rowCount) {} |
---|
29 | |
---|
30 | virtual ~QueryResult() {} |
---|
31 | |
---|
32 | virtual bool NextRow() = 0; |
---|
33 | |
---|
34 | typedef std::map<uint32, std::string> FieldNames; |
---|
35 | |
---|
36 | uint32 GetField_idx(const std::string &name) const |
---|
37 | { |
---|
38 | for(FieldNames::const_iterator iter = GetFieldNames().begin(); iter != GetFieldNames().end(); ++iter) |
---|
39 | { |
---|
40 | if(iter->second == name) |
---|
41 | return iter->first; |
---|
42 | } |
---|
43 | assert(false && "unknown field name"); |
---|
44 | return uint32(-1); |
---|
45 | } |
---|
46 | |
---|
47 | Field *Fetch() const { return mCurrentRow; } |
---|
48 | |
---|
49 | const Field & operator [] (int index) const { return mCurrentRow[index]; } |
---|
50 | |
---|
51 | const Field & operator [] (const std::string &name) const |
---|
52 | { |
---|
53 | return mCurrentRow[GetField_idx(name)]; |
---|
54 | } |
---|
55 | |
---|
56 | uint32 GetFieldCount() const { return mFieldCount; } |
---|
57 | uint64 GetRowCount() const { return mRowCount; } |
---|
58 | FieldNames const& GetFieldNames() const {return mFieldNames; } |
---|
59 | |
---|
60 | protected: |
---|
61 | Field *mCurrentRow; |
---|
62 | uint32 mFieldCount; |
---|
63 | uint64 mRowCount; |
---|
64 | FieldNames mFieldNames; |
---|
65 | }; |
---|
66 | #endif |
---|