root/trunk/src/shared/Database/QueryResult.h @ 2

Revision 2, 2.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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