Revert revision: 053bfe8ad9, this cause some crash.

Use dynamic_cast more is safer.
I think no more crash on db code.

--HG--
branch : trunk
This commit is contained in:
n0n4m3
2010-02-10 16:04:48 +03:00
parent 1e4684826e
commit 293ea07a25
3 changed files with 14 additions and 9 deletions

View File

@@ -32,13 +32,14 @@ void SqlDelayThread::run()
mysql_thread_init();
#endif
SqlAsyncTask * s = NULL;
// Lets wait for next async task no more than 2 secs
ACE_Time_Value _time(2);
while (m_running)
{
// if the running state gets turned off while sleeping
// empty the queue before exiting
SqlAsyncTask * s = (SqlAsyncTask*)m_sqlQueue.dequeue(/*&_time*/);
s = dynamic_cast<SqlAsyncTask*> (m_sqlQueue.dequeue());
if(s)
{
s->call();

View File

@@ -33,17 +33,23 @@ void SqlStatement::Execute(Database *db)
void SqlTransaction::Execute(Database *db)
{
const char *sql;
if (m_queue.empty())
return;
db->DirectExecute("START TRANSACTION");
while(m_queue.next(sql))
while(!m_queue.empty())
{
char const *sql = m_queue.front();
m_queue.pop();
if(!db->DirectExecute(sql))
{
free((void*)const_cast<char*>(sql));
db->DirectExecute("ROLLBACK");
while(m_queue.next(sql))
while(!m_queue.empty())
{
free((void*)const_cast<char*>(sql));
free((void*)const_cast<char*>(m_queue.front()));
m_queue.pop();
}
return;
}

View File

@@ -57,13 +57,11 @@ class SqlStatement : public SqlOperation
class SqlTransaction : public SqlOperation
{
typedef ACE_Based::LockedQueue<const char *, ACE_Thread_Mutex> LockedQueue;
private:
LockedQueue m_queue;
std::queue<const char *> m_queue;
public:
SqlTransaction() {}
void DelayExecute(const char *sql) { m_queue.add(strdup(sql)); }
void DelayExecute(const char *sql) { m_queue.push(strdup(sql)); }
void Execute(Database *db);
};