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<typename ParamType1> |
---|
51 | bool |
---|
52 | Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, 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::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second)); |
---|
59 | return true; |
---|
60 | } |
---|
61 | |
---|
62 | template<class Class> |
---|
63 | bool |
---|
64 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) |
---|
65 | { |
---|
66 | if(!format) return false; |
---|
67 | |
---|
68 | va_list ap; |
---|
69 | char szQuery [MAX_QUERY_LEN]; |
---|
70 | va_start(ap, format); |
---|
71 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
72 | va_end(ap); |
---|
73 | |
---|
74 | if(res==-1) |
---|
75 | { |
---|
76 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
77 | return false; |
---|
78 | } |
---|
79 | |
---|
80 | return AsyncQuery(object, method, szQuery); |
---|
81 | } |
---|
82 | |
---|
83 | template<class Class, typename ParamType1> |
---|
84 | bool |
---|
85 | Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
86 | { |
---|
87 | if(!format) return false; |
---|
88 | |
---|
89 | va_list ap; |
---|
90 | char szQuery [MAX_QUERY_LEN]; |
---|
91 | va_start(ap, format); |
---|
92 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
93 | va_end(ap); |
---|
94 | |
---|
95 | if(res==-1) |
---|
96 | { |
---|
97 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
98 | return false; |
---|
99 | } |
---|
100 | |
---|
101 | return AsyncQuery(object, method, param1, szQuery); |
---|
102 | } |
---|
103 | |
---|
104 | template<typename ParamType1> |
---|
105 | bool |
---|
106 | Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) |
---|
107 | { |
---|
108 | if(!format) return false; |
---|
109 | |
---|
110 | va_list ap; |
---|
111 | char szQuery [MAX_QUERY_LEN]; |
---|
112 | va_start(ap, format); |
---|
113 | int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); |
---|
114 | va_end(ap); |
---|
115 | |
---|
116 | if(res==-1) |
---|
117 | { |
---|
118 | sLog.outError("SQL Query truncated (and not execute) for format: %s",format); |
---|
119 | return false; |
---|
120 | } |
---|
121 | |
---|
122 | return AsyncQuery(method, param1, szQuery); |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | template<class Class> |
---|
127 | bool |
---|
128 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder) |
---|
129 | { |
---|
130 | if (!holder) return false; |
---|
131 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
132 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
133 | if (itr == m_queryQueues.end()) return false; |
---|
134 | holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, itr->second); |
---|
135 | return true; |
---|
136 | } |
---|
137 | |
---|
138 | template<class Class, typename ParamType1> |
---|
139 | bool |
---|
140 | Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1) |
---|
141 | { |
---|
142 | if (!holder) return false; |
---|
143 | ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); |
---|
144 | QueryQueues::iterator itr = m_queryQueues.find(queryThread); |
---|
145 | if (itr == m_queryQueues.end()) return false; |
---|
146 | holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, itr->second); |
---|
147 | return true; |
---|
148 | } |
---|