[4362] Applied MaNGOS coding style to src/shared/Database.
[mangos-git.git] / src / shared / Database / DatabaseImpl.h
blob8fb9f15dc95abb93efbcba4f8ce2415eda58b0a6
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
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 #include "Database/Database.h"
20 #include "Database/SqlOperations.h"
22 /// Function body definitions for the template function members of the Database class
24 template<class Class>
25 bool
26 Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
28 if (!sql) return false;
29 ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
30 QueryQueues::iterator itr = m_queryQueues.find(queryThread);
31 if (itr == m_queryQueues.end()) return false;
32 m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), itr->second));
33 return true;
36 template<class Class, typename ParamType1>
37 bool
38 Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
40 if (!sql) return false;
41 ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
42 QueryQueues::iterator itr = m_queryQueues.find(queryThread);
43 if (itr == m_queryQueues.end()) return false;
44 m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
45 return true;
48 template<class Class>
49 bool
50 Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
52 if(!format) return false;
54 va_list ap;
55 char szQuery [MAX_QUERY_LEN];
56 va_start(ap, format);
57 int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
58 va_end(ap);
60 if(res==-1)
62 sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
63 return false;
66 return AsyncQuery(object, method, szQuery);
69 template<class Class, typename ParamType1>
70 bool
71 Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
73 if(!format) return false;
75 va_list ap;
76 char szQuery [MAX_QUERY_LEN];
77 va_start(ap, format);
78 int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
79 va_end(ap);
81 if(res==-1)
83 sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
84 return false;
87 return AsyncQuery(object, method, param1, szQuery);
90 template<class Class>
91 bool
92 Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder)
94 if (!holder) return false;
95 ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
96 QueryQueues::iterator itr = m_queryQueues.find(queryThread);
97 if (itr == m_queryQueues.end()) return false;
98 holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second);
99 return true;
102 template<class Class, typename ParamType1>
103 bool
104 Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
106 if (!holder) return false;
107 ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current();
108 QueryQueues::iterator itr = m_queryQueues.find(queryThread);
109 if (itr == m_queryQueues.end()) return false;
110 holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second);
111 return true;