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
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
));
36 template<class Class
, typename ParamType1
>
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
));
50 Database::AsyncPQuery(Class
*object
, void (Class::*method
)(QueryResult
*), const char *format
,...)
52 if(!format
) return false;
55 char szQuery
[MAX_QUERY_LEN
];
57 int res
= vsnprintf( szQuery
, MAX_QUERY_LEN
, format
, ap
);
62 sLog
.outError("SQL Query truncated (and not execute) for format: %s",format
);
66 return AsyncQuery(object
, method
, szQuery
);
69 template<class Class
, typename ParamType1
>
71 Database::AsyncPQuery(Class
*object
, void (Class::*method
)(QueryResult
*, ParamType1
), ParamType1 param1
, const char *format
,...)
73 if(!format
) return false;
76 char szQuery
[MAX_QUERY_LEN
];
78 int res
= vsnprintf( szQuery
, MAX_QUERY_LEN
, format
, ap
);
83 sLog
.outError("SQL Query truncated (and not execute) for format: %s",format
);
87 return AsyncQuery(object
, method
, param1
, szQuery
);
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
);
102 template<class Class
, typename ParamType1
>
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
);