1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "Database/Database.h" |
---|
22 | #include "Database/SqlOperations.h" |
---|
23 | |
---|
24 | /// Function body definitions for the template function members of the Database class |
---|
25 | |
---|
26 | template<class Class> |
---|
27 | bool |
---|
28 | Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql) |
---|
29 | { |
---|
30 | if (!sql) return false; |
---|
31 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
32 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
33 | if (itr == m_queryQueues.end()) return false; |
---|
34 | m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second)); |
---|
35 | return true; |
---|
36 | } |
---|
37 | |
---|
38 | template<class Class, typename ParamType1> |
---|
39 | bool |
---|
40 | Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) |
---|
41 | { |
---|
42 | if (!sql) return false; |
---|
43 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
44 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
45 | if (itr == m_queryQueues.end()) return false; |
---|
46 | m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second)); |
---|
47 | return true; |
---|
48 | } |
---|
49 | |
---|
50 | template<class Class, typename ParamType1, typename ParamType2> |
---|
51 | bool |
---|
52 | Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) |
---|
53 | { |
---|
54 | if (!sql) return false; |
---|
55 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
56 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
57 | if (itr == m_queryQueues.end()) return false; |
---|
58 | m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second)); |
---|
59 | return true; |
---|
60 | } |
---|
61 | |
---|
62 | template<typename ParamType1> |
---|
63 | bool |
---|
64 | Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) |
---|
65 | { |
---|
66 | if (!sql) return false; |
---|
67 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
68 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
69 | if (itr == m_queryQueues.end()) return false; |
---|
70 | m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second)); |
---|
71 | return true; |
---|
72 | } |
---|
73 | |
---|
74 | template<typename ParamType1, typename ParamType2> |
---|
75 | bool |
---|
76 | Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql) |
---|
77 | { |
---|
78 | if (!sql) return false; |
---|
79 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
80 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
81 | if (itr == m_queryQueues.end()) return false; |
---|
82 | m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second)); |
---|
83 | return true; |
---|
84 | } |
---|
85 | |
---|
86 | template<class Class> |
---|
87 | bool |
---|
88 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) |
---|
89 | { |
---|
90 | if(!format) return false; |
---|
91 | |
---|
92 | va_list ap; |
---|
93 | char szQuery [MAX_QUERY_LEN]; |
---|
94 | va_start(ap, format); |
---|
95 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
96 | va_end(ap); |
---|
97 | |
---|
98 | if(res==-1) |
---|
99 | { |
---|
100 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
101 | return false; |
---|
102 | } |
---|
103 | |
---|
104 | return AsyncQuery(object, method, szQuery); |
---|
105 | } |
---|
106 | |
---|
107 | template<class Class, typename ParamType1> |
---|
108 | bool |
---|
109 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
110 | { |
---|
111 | if(!format) return false; |
---|
112 | |
---|
113 | va_list ap; |
---|
114 | char szQuery [MAX_QUERY_LEN]; |
---|
115 | va_start(ap, format); |
---|
116 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
117 | va_end(ap); |
---|
118 | |
---|
119 | if(res==-1) |
---|
120 | { |
---|
121 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
122 | return false; |
---|
123 | } |
---|
124 | |
---|
125 | return AsyncQuery(object, method, param1, szQuery); |
---|
126 | } |
---|
127 | |
---|
128 | template<class Class, typename ParamType1, typename ParamType2> |
---|
129 | bool |
---|
130 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) |
---|
131 | { |
---|
132 | if(!format) return false; |
---|
133 | |
---|
134 | va_list ap; |
---|
135 | char szQuery [MAX_QUERY_LEN]; |
---|
136 | va_start(ap, format); |
---|
137 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
138 | va_end(ap); |
---|
139 | |
---|
140 | if(res==-1) |
---|
141 | { |
---|
142 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
143 | return false; |
---|
144 | } |
---|
145 | |
---|
146 | return AsyncQuery(object, method, param1, param2, szQuery); |
---|
147 | } |
---|
148 | |
---|
149 | template<typename ParamType1> |
---|
150 | bool |
---|
151 | Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
152 | { |
---|
153 | if(!format) return false; |
---|
154 | |
---|
155 | va_list ap; |
---|
156 | char szQuery [MAX_QUERY_LEN]; |
---|
157 | va_start(ap, format); |
---|
158 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
159 | va_end(ap); |
---|
160 | |
---|
161 | if(res==-1) |
---|
162 | { |
---|
163 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
164 | return false; |
---|
165 | } |
---|
166 | |
---|
167 | return AsyncQuery(method, param1, szQuery); |
---|
168 | } |
---|
169 | |
---|
170 | template<typename ParamType1, typename ParamType2> |
---|
171 | bool |
---|
172 | Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) |
---|
173 | { |
---|
174 | if(!format) return false; |
---|
175 | |
---|
176 | va_list ap; |
---|
177 | char szQuery [MAX_QUERY_LEN]; |
---|
178 | va_start(ap, format); |
---|
179 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
180 | va_end(ap); |
---|
181 | |
---|
182 | if(res==-1) |
---|
183 | { |
---|
184 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
185 | return false; |
---|
186 | } |
---|
187 | |
---|
188 | return AsyncQuery(method, param1, param2, szQuery); |
---|
189 | } |
---|
190 | |
---|
191 | template<class Class> |
---|
192 | bool |
---|
193 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder) |
---|
194 | { |
---|
195 | if (!holder) return false; |
---|
196 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
197 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
198 | if (itr == m_queryQueues.end()) return false; |
---|
199 | holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second); |
---|
200 | return true; |
---|
201 | } |
---|
202 | |
---|
203 | template<class Class, typename ParamType1> |
---|
204 | bool |
---|
205 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) |
---|
206 | { |
---|
207 | if (!holder) return false; |
---|
208 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
209 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
210 | if (itr == m_queryQueues.end()) return false; |
---|
211 | holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second); |
---|
212 | return true; |
---|
213 | } |
---|