Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv31063
Modified Files:
boats.cpp console.cpp console.h dbdriver.cpp log.h
persistentbroker.cpp persistentbroker.h
Log Message:
- some #include clean up.
- made INSERTs 25% faster, possibly updates as well ( didn't measure )
- cleanned some code.
Index: boats.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/boats.cpp,v
retrieving revision 1.115
retrieving revision 1.116
diff -C2 -d -r1.115 -r1.116
*** boats.cpp 23 Sep 2003 23:55:19 -0000 1.115
--- boats.cpp 24 Sep 2003 21:19:47 -0000 1.116
***************
*** 1290,1298 ****
INT32 i, j, k;
! for( i = 0; i < 4; ++i )
! addField( QString( "itemserial%1" ).arg( i ), itemserials[i] );
! for( i = 0; i < 4; ++i )
! addField( QString( "multi%1" ).arg( i ), multiids_[i] );
addCondition( "serial", serial() );
--- 1290,1302 ----
INT32 i, j, k;
! addField( "itemserial0", itemserials[0] );
! addField( "itemserial1", itemserials[1] );
! addField( "itemserial2", itemserials[2] );
! addField( "itemserial3", itemserials[3] );
! addField( "multi0", multiids_[0] );
! addField( "multi1", multiids_[1] );
! addField( "multi2", multiids_[2] );
! addField( "multi3", multiids_[3] );
addCondition( "serial", serial() );
Index: console.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/console.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** console.cpp 20 Sep 2003 01:05:10 -0000 1.6
--- console.cpp 24 Sep 2003 21:19:48 -0000 1.7
***************
*** 47,50 ****
--- 47,51 ----
#include <qglobal.h>
#include <qthread.h>
+ #include <qmutex.h>
#if defined(Q_OS_WIN32)
***************
*** 240,246 ****
void cConsole::queueCommand( const QString &command )
{
! commandMutex.lock();
commandQueue.push_back( command );
- commandMutex.unlock();
}
--- 241,246 ----
void cConsole::queueCommand( const QString &command )
{
! QMutexLocker lock(&commandMutex);
commandQueue.push_back( command );
}
Index: console.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/console.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** console.h 20 Sep 2003 01:26:54 -0000 1.7
--- console.h 24 Sep 2003 21:19:48 -0000 1.8
***************
*** 37,43 ****
// System Includes
- #include <iosfwd>
- #include <cstdarg>
- #include <cstdio>
#include <qstringlist.h>
#include <qstring.h>
--- 37,40 ----
***************
*** 45,51 ****
// Third Party includes
-
- // Forward class declaration
- class cPythonScript;
// Wolfpack Includes
--- 42,45 ----
Index: dbdriver.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/dbdriver.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** dbdriver.cpp 12 Sep 2003 20:02:44 -0000 1.23
--- dbdriver.cpp 24 Sep 2003 21:19:48 -0000 1.24
***************
*** 184,187 ****
--- 184,193 ----
}
+ exec( "PRAGMA synchronous = OFF;" );
+ exec( "PRAGMA default_synchronous = OFF;" );
+ exec( "PRAGMA full_column_names = OFF;" );
+ exec( "PRAGMA show_datatypes = OFF;" );
+ exec( "PRAGMA parser_trace = OFF;" );
+
return true;
}
Index: log.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/log.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** log.h 15 Sep 2003 02:00:41 -0000 1.3
--- log.h 24 Sep 2003 21:19:48 -0000 1.4
***************
*** 44,48 ****
class cLog
{
! protected:
eLogLevel loglevel;
QFile logfile;
--- 44,48 ----
class cLog
{
! private:
eLogLevel loglevel;
QFile logfile;
Index: persistentbroker.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** persistentbroker.cpp 13 Sep 2003 15:37:06 -0000 1.29
--- persistentbroker.cpp 24 Sep 2003 21:19:48 -0000 1.30
***************
*** 41,46 ****
#include <qstring.h>
! PersistentBroker::PersistentBroker() : connection(0)
{
}
--- 41,64 ----
#include <qstring.h>
+ #include <list>
! struct stDeleteItem
! {
! QString tables;
! QString conditions;
! };
!
! class PersistentBrokerPrivate
! {
! public:
! PersistentBrokerPrivate() : connection(0) {}
! ~PersistentBrokerPrivate() { delete connection; }
!
! cDBDriver* connection;
! bool sqlite;
! std::list< stDeleteItem > deleteQueue;
! };
!
! PersistentBroker::PersistentBroker() : d( new PersistentBrokerPrivate )
{
}
***************
*** 48,73 ****
PersistentBroker::~PersistentBroker()
{
! delete connection;
}
bool PersistentBroker::openDriver( const QString& driver )
{
! if( connection != 0 )
{
! connection->close();
! delete connection;
! connection = 0;
}
if( driver == "sqlite" )
{
! connection = new cSQLiteDriver();
! sqlite = true;
}
else if( driver == "mysql" )
{
#ifdef MYSQL_DRIVER
! connection = new cMySQLDriver;
! sqlite = false;
#else
throw QString( "Sorry, you have to define MYSQL_DRIVER to make wolfpack work with MySQL.\n" );
--- 66,91 ----
PersistentBroker::~PersistentBroker()
{
! delete d;
}
bool PersistentBroker::openDriver( const QString& driver )
{
! if( d->connection != 0 )
{
! d->connection->close();
! delete d->connection;
! d->connection = 0;
}
if( driver == "sqlite" )
{
! d->connection = new cSQLiteDriver();
! d->sqlite = true;
}
else if( driver == "mysql" )
{
#ifdef MYSQL_DRIVER
! d->connection = new cMySQLDriver;
! d->sqlite = false;
#else
throw QString( "Sorry, you have to define MYSQL_DRIVER to make wolfpack work with MySQL.\n" );
***************
*** 75,79 ****
}
! if ( !connection )
return false;
--- 93,97 ----
}
! if ( !d->connection )
return false;
***************
*** 83,108 ****
bool PersistentBroker::connect( const QString& host, const QString& db, const QString& username, const QString& password )
{
! if (!connection)
return false;
// This does nothing but a little test-connection
! connection->setDatabaseName( db );
! connection->setUserName( username );
! connection->setPassword( password );
! connection->setHostName( host );
! if( !connection->open() )
return false;
- // Disable fsynch for sqlite
- if( this->sqlite )
- {
- connection->exec( "PRAGMA synchronous = OFF;" );
- connection->exec( "PRAGMA default_synchronous = OFF;" );
- connection->exec( "PRAGMA full_column_names = OFF;" );
- connection->exec( "PRAGMA show_datatypes = OFF;" );
- connection->exec( "PRAGMA parser_trace = OFF;" );
- }
-
return true;
}
--- 101,116 ----
bool PersistentBroker::connect( const QString& host, const QString& db, const QString& username, const QString& password )
{
! if (!d->connection)
return false;
// This does nothing but a little test-connection
! d->connection->setDatabaseName( db );
! d->connection->setUserName( username );
! d->connection->setPassword( password );
! d->connection->setHostName( host );
! if( !d->connection->open() )
return false;
return true;
}
***************
*** 110,115 ****
void PersistentBroker::disconnect()
{
! if( connection )
! connection->close();
}
--- 118,123 ----
void PersistentBroker::disconnect()
{
! if( d->connection )
! d->connection->close();
}
***************
*** 144,155 ****
bool PersistentBroker::executeQuery( const QString& query )
{
! if( !connection )
throw QString( "PersistentBroker not connected to database." );
//qWarning( query );
! bool result = connection->exec(query);
if( !result )
{
! Console::instance()->log( LOG_ERROR, connection->error() );
}
return result;
--- 152,163 ----
bool PersistentBroker::executeQuery( const QString& query )
{
! if( !d->connection )
throw QString( "PersistentBroker not connected to database." );
//qWarning( query );
! bool result = d->connection->exec(query);
if( !result )
{
! Console::instance()->log( LOG_ERROR, d->connection->error() );
}
return result;
***************
*** 158,189 ****
cDBDriver* PersistentBroker::driver() const
{
! return connection;
}
cDBResult PersistentBroker::query( const QString& query )
{
! if( !connection )
throw QString( "PersistentBroker not connected to database." );
! return connection->query( query );
}
void PersistentBroker::clearDeleteQueue()
{
! deleteQueue.clear();
}
void PersistentBroker::flushDeleteQueue()
{
! std::vector< stDeleteItem >::iterator iter;
! for( iter = deleteQueue.begin(); iter != deleteQueue.end(); ++iter )
{
! QString tables = (*iter).tables;
! QString conditions = (*iter).conditions;
! QString sql = QString( "DELETE FROM %1 WHERE %2" ).arg( tables ).arg( conditions );
! executeQuery( sql );
}
! deleteQueue.clear();
}
--- 166,194 ----
cDBDriver* PersistentBroker::driver() const
{
! return d->connection;
}
cDBResult PersistentBroker::query( const QString& query )
{
! if( !d->connection )
throw QString( "PersistentBroker not connected to database." );
! return d->connection->query( query );
}
void PersistentBroker::clearDeleteQueue()
{
! d->deleteQueue.clear();
}
void PersistentBroker::flushDeleteQueue()
{
! std::list< stDeleteItem >::iterator iter;
! for( iter = d->deleteQueue.begin(); iter != d->deleteQueue.end(); ++iter )
{
! executeQuery( "DELETE FROM " + (*iter).tables + " WHERE " + (*iter).conditions );
}
! d->deleteQueue.clear();
}
***************
*** 193,234 ****
dItem.tables = tables;
dItem.conditions = conditions;
! deleteQueue.push_back( dItem );
}
QString PersistentBroker::lastError() const
{
! return connection->error();
}
void PersistentBroker::lockTable( const QString& table ) const
{
! connection->lockTable( table );
}
void PersistentBroker::unlockTable( const QString& table ) const
{
! connection->unlockTable( table );
}
void PersistentBroker::startTransaction()
{
! if( sqlite )
! executeQuery( "BEGIN;" );
}
void PersistentBroker::commitTransaction()
{
! if( sqlite )
! executeQuery( "END;" );
}
void PersistentBroker::rollbackTransaction()
{
! if( sqlite )
! executeQuery( "ROLLBACK;" );
}
bool PersistentBroker::tableExists( const QString &table )
{
! return connection->tableExists( table );
}
--- 198,244 ----
dItem.tables = tables;
dItem.conditions = conditions;
! d->deleteQueue.push_back( dItem );
}
QString PersistentBroker::lastError() const
{
! return d->connection->error();
}
void PersistentBroker::lockTable( const QString& table ) const
{
! d->connection->lockTable( table );
}
void PersistentBroker::unlockTable( const QString& table ) const
{
! d->connection->unlockTable( table );
}
void PersistentBroker::startTransaction()
{
! executeQuery( "BEGIN;" );
}
void PersistentBroker::commitTransaction()
{
! executeQuery( "COMMIT;" );
}
void PersistentBroker::rollbackTransaction()
{
! executeQuery( "ROLLBACK;" );
}
bool PersistentBroker::tableExists( const QString &table )
{
! return d->connection->tableExists( table );
! }
!
! QString PersistentBroker::quoteString( QString s )
! {
! if( d->sqlite )
! return s.replace( QRegExp("'"), "''" );
! else
! return s.replace( QRegExp("'"), "\\'" );
}
Index: persistentbroker.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** persistentbroker.h 13 Sep 2003 13:27:26 -0000 1.25
--- persistentbroker.h 24 Sep 2003 21:19:48 -0000 1.26
***************
*** 33,40 ****
#define __PERSISTENTBROKER_H__
- #include <qsqldatabase.h>
- #include <typeinfo>
#include <qregexp.h>
- #include <vector>
class PersistentObject;
--- 33,37 ----
***************
*** 42,57 ****
class cDBResult;
! struct stDeleteItem
! {
! QString tables;
! QString conditions;
! };
class PersistentBroker
{
! cDBDriver* connection;
! bool sqlite;
! std::vector< stDeleteItem > deleteQueue;
!
public:
PersistentBroker();
--- 39,47 ----
class cDBResult;
! class PersistentBrokerPrivate;
class PersistentBroker
{
! PersistentBrokerPrivate* d;
public:
PersistentBroker();
***************
*** 68,78 ****
void addToDeleteQueue( const QString &tables, const QString &conditions );
! QString quoteString( QString d )
! {
! if( sqlite )
! return d.replace( QRegExp("'"), "''" );
! else
! return d.replace( QRegExp("'"), "\\'" );
! }
void lockTable( const QString& table ) const;
--- 58,62 ----
void addToDeleteQueue( const QString &tables, const QString &conditions );
! QString quoteString( QString d );
void lockTable( const QString& table ) const;
***************
*** 99,103 ****
#define addField( name, value ) \
if( isPersistent ) \
! fields.push_back( QString( "%1='%2'" ).arg( name ).arg( QString::number( value ) ) ); \
else \
{ \
--- 83,87 ----
#define addField( name, value ) \
if( isPersistent ) \
! fields.push_back( name "='" + QString::number(value) + "'" ); \
else \
{ \
***************
*** 108,112 ****
#define addStrField( name, value ) \
if( isPersistent ) \
! fields.push_back( QString( "%1='%2'" ).arg( name ).arg( persistentBroker->quoteString( value ) ) ); \
else \
{ \
--- 92,96 ----
#define addStrField( name, value ) \
if( isPersistent ) \
! fields.push_back( name "='" + persistentBroker->quoteString( value ) + "'" ); \
else \
{ \
***************
*** 120,128 ****
if( isPersistent ) \
{ \
! persistentBroker->executeQuery( QString( "UPDATE %1 SET %2 WHERE %3" ).arg( table ).arg( fields.join( "," ) ).arg( conditions.join( " AND " ) ) ); \
} \
else \
{ \
! persistentBroker->executeQuery( QString( "REPLACE INTO %1 VALUES(%3)" ).arg( table )/*.arg( fields.join( "," ) )*/.arg( values.join( "," ) ) ); \
}
--- 104,112 ----
if( isPersistent ) \
{ \
! persistentBroker->executeQuery( "UPDATE " + table + " SET " + fields.join( "," ) + " WHERE " + conditions.join( " AND " ) ); \
} \
else \
{ \
! persistentBroker->executeQuery( "REPLACE INTO " + table + " VALUES(" + values.join( "," ) + ")" ); \
}
|