[9122] Updated copyright notice for new year.
[getmangos.git] / src / shared / Database / QueryResult.h
blob7dd6e0673002ade59c058dc624f7b32f591defe1
1 /*
2 * Copyright (C) 2005-2010 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 #if !defined(QUERYRESULT_H)
20 #define QUERYRESULT_H
22 class MANGOS_DLL_SPEC QueryResult
24 public:
25 QueryResult(uint64 rowCount, uint32 fieldCount)
26 : mFieldCount(fieldCount), mRowCount(rowCount) {}
28 virtual ~QueryResult() {}
30 virtual bool NextRow() = 0;
32 Field *Fetch() const { return mCurrentRow; }
34 const Field & operator [] (int index) const { return mCurrentRow[index]; }
36 uint32 GetFieldCount() const { return mFieldCount; }
37 uint64 GetRowCount() const { return mRowCount; }
39 protected:
40 Field *mCurrentRow;
41 uint32 mFieldCount;
42 uint64 mRowCount;
45 typedef std::vector<std::string> QueryFieldNames;
47 class MANGOS_DLL_SPEC QueryNamedResult
49 public:
50 explicit QueryNamedResult(QueryResult* query, QueryFieldNames const& names) : mQuery(query), mFieldNames(names) {}
51 ~QueryNamedResult() { delete mQuery; }
53 // compatible interface with QueryResult
54 bool NextRow() { return mQuery->NextRow(); }
55 Field *Fetch() const { return mQuery->Fetch(); }
56 uint32 GetFieldCount() const { return mQuery->GetFieldCount(); }
57 uint64 GetRowCount() const { return mQuery->GetRowCount(); }
58 Field const& operator[] (int index) const { return (*mQuery)[index]; }
60 // named access
61 Field const& operator[] (const std::string &name) const { return mQuery->Fetch()[GetField_idx(name)]; }
62 QueryFieldNames const& GetFieldNames() const { return mFieldNames; }
64 uint32 GetField_idx(const std::string &name) const
66 for(size_t idx = 0; idx < mFieldNames.size(); ++idx)
68 if(mFieldNames[idx] == name)
69 return idx;
71 ASSERT(false && "unknown field name");
72 return uint32(-1);
75 protected:
76 QueryResult *mQuery;
77 QueryFieldNames mFieldNames;
80 #endif