aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Database/QueryResult.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/Database/QueryResult.h')
-rw-r--r--src/shared/Database/QueryResult.h56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h
index 39228dd4ba9..f9f1a009833 100644
--- a/src/shared/Database/QueryResult.h
+++ b/src/shared/Database/QueryResult.h
@@ -31,37 +31,53 @@ class TRINITY_DLL_SPEC QueryResult
virtual bool NextRow() = 0;
- typedef std::map<uint32, std::string> FieldNames;
-
- uint32 GetField_idx(const std::string &name) const
- {
- for(FieldNames::const_iterator iter = GetFieldNames().begin(); iter != GetFieldNames().end(); ++iter)
- {
- if(iter->second == name)
- return iter->first;
- }
- ASSERT(false && "unknown field name");
- return uint32(-1);
- }
-
Field *Fetch() const { return mCurrentRow; }
const Field & operator [] (int index) const { return mCurrentRow[index]; }
- const Field & operator [] (const std::string &name) const
- {
- return mCurrentRow[GetField_idx(name)];
- }
-
uint32 GetFieldCount() const { return mFieldCount; }
uint64 GetRowCount() const { return mRowCount; }
- FieldNames const& GetFieldNames() const {return mFieldNames; }
protected:
Field *mCurrentRow;
uint32 mFieldCount;
uint64 mRowCount;
- FieldNames mFieldNames;
};
+
+typedef std::vector<std::string> QueryFieldNames;
+
+class MANGOS_DLL_SPEC QueryNamedResult
+{
+ public:
+ explicit QueryNamedResult(QueryResult* query, QueryFieldNames const& names) : mQuery(query), mFieldNames(names) {}
+ ~QueryNamedResult() { delete mQuery; }
+
+ // compatible interface with QueryResult
+ bool NextRow() { return mQuery->NextRow(); }
+ Field *Fetch() const { return mQuery->Fetch(); }
+ uint32 GetFieldCount() const { return mQuery->GetFieldCount(); }
+ uint64 GetRowCount() const { return mQuery->GetRowCount(); }
+ Field const& operator[] (int index) const { return (*mQuery)[index]; }
+
+ // named access
+ Field const& operator[] (const std::string &name) const { return mQuery->Fetch()[GetField_idx(name)]; }
+ QueryFieldNames const& GetFieldNames() const { return mFieldNames; }
+
+ uint32 GetField_idx(const std::string &name) const
+ {
+ for(size_t idx = 0; idx < mFieldNames.size(); ++idx)
+ {
+ if(mFieldNames[idx] == name)
+ return idx;
+ }
+ ASSERT(false && "unknown field name");
+ return uint32(-1);
+ }
+
+ protected:
+ QueryResult *mQuery;
+ QueryFieldNames mFieldNames;
+};
+
#endif