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 | #include "Database/Database.h" |
---|
20 | #include "Database/SqlOperations.h" |
---|
21 | |
---|
22 | /// Function body definitions for the template function members of the Database class |
---|
23 | |
---|
24 | template<class Class> |
---|
25 | bool |
---|
26 | Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql) |
---|
27 | { |
---|
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; |
---|
34 | } |
---|
35 | |
---|
36 | template<class Class, typename ParamType1> |
---|
37 | bool |
---|
38 | Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) |
---|
39 | { |
---|
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; |
---|
46 | } |
---|
47 | |
---|
48 | template<typename ParamType1> |
---|
49 | bool |
---|
50 | Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql) |
---|
51 | { |
---|
52 | if (!sql) return false; |
---|
53 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
54 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
55 | if (itr == m_queryQueues.end()) return false; |
---|
56 | m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second)); |
---|
57 | return true; |
---|
58 | } |
---|
59 | |
---|
60 | template<class Class> |
---|
61 | bool |
---|
62 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) |
---|
63 | { |
---|
64 | if(!format) return false; |
---|
65 | |
---|
66 | va_list ap; |
---|
67 | char szQuery [MAX_QUERY_LEN]; |
---|
68 | va_start(ap, format); |
---|
69 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
70 | va_end(ap); |
---|
71 | |
---|
72 | if(res==-1) |
---|
73 | { |
---|
74 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
75 | return false; |
---|
76 | } |
---|
77 | |
---|
78 | return AsyncQuery(object, method, szQuery); |
---|
79 | } |
---|
80 | |
---|
81 | template<class Class, typename ParamType1> |
---|
82 | bool |
---|
83 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
84 | { |
---|
85 | if(!format) return false; |
---|
86 | |
---|
87 | va_list ap; |
---|
88 | char szQuery [MAX_QUERY_LEN]; |
---|
89 | va_start(ap, format); |
---|
90 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
91 | va_end(ap); |
---|
92 | |
---|
93 | if(res==-1) |
---|
94 | { |
---|
95 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
96 | return false; |
---|
97 | } |
---|
98 | |
---|
99 | return AsyncQuery(object, method, param1, szQuery); |
---|
100 | } |
---|
101 | |
---|
102 | template<typename ParamType1> |
---|
103 | bool |
---|
104 | Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
105 | { |
---|
106 | if(!format) return false; |
---|
107 | |
---|
108 | va_list ap; |
---|
109 | char szQuery [MAX_QUERY_LEN]; |
---|
110 | va_start(ap, format); |
---|
111 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
112 | va_end(ap); |
---|
113 | |
---|
114 | if(res==-1) |
---|
115 | { |
---|
116 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
117 | return false; |
---|
118 | } |
---|
119 | |
---|
120 | return AsyncQuery(method, param1, szQuery); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | template<class Class> |
---|
125 | bool |
---|
126 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder) |
---|
127 | { |
---|
128 | if (!holder) return false; |
---|
129 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
130 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
131 | if (itr == m_queryQueues.end()) return false; |
---|
132 | holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second); |
---|
133 | return true; |
---|
134 | } |
---|
135 | |
---|
136 | template<class Class, typename ParamType1> |
---|
137 | bool |
---|
138 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) |
---|
139 | { |
---|
140 | if (!holder) return false; |
---|
141 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
142 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
143 | if (itr == m_queryQueues.end()) return false; |
---|
144 | holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second); |
---|
145 | return true; |
---|
146 | } |
---|