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)
22 class MANGOS_DLL_SPEC QueryResult
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
; }
45 typedef std::vector
<std::string
> QueryFieldNames
;
47 class MANGOS_DLL_SPEC QueryNamedResult
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
]; }
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
)
71 ASSERT(false && "unknown field name");
77 QueryFieldNames mFieldNames
;