Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv13226/src
Modified Files:
books.cpp corpse.cpp customtags.cpp multis.cpp
persistentbroker.h
Log Message:
Improved SQL Loading and Saving speed.
Index: books.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/books.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** books.cpp 26 Aug 2003 15:36:44 -0000 1.43
--- books.cpp 27 Aug 2003 16:06:12 -0000 1.44
***************
*** 142,146 ****
for ( QStringList::iterator it = content_.begin(); it != content_.end(); ++it )
{
! persistentBroker->executeQuery( QString( "INSERT INTO bookpages SET serial = '%1', page = '%2', text = '%3'" ).arg( serial() ).arg( i ).arg( persistentBroker->quoteString( *it ) ) );
++i;
}
--- 142,146 ----
for ( QStringList::iterator it = content_.begin(); it != content_.end(); ++it )
{
! persistentBroker->executeQuery( QString( "INSERT INTO bookpages VALUES (%1,%2,'%3')" ).arg( serial() ).arg( i ).arg( persistentBroker->quoteString( *it ) ) );
++i;
}
***************
*** 160,253 ****
return cItem::del();
}
-
- /*void cBook::Serialize( ISerialization &archive )
- {
- if( archive.isReading() )
- {
- }
- else
- {
- archive.write( "book.title", title_ );
- archive.write( "book.author", author_ );
- UINT32 contsize = content_.size();
- archive.write( "book.contsize", contsize );
- UI32 i;
- for( i = 0; i < content_.size(); i++ )
- {
- archive.write( (char*)QString("book.content.page%1").arg(i).latin1(), content_[i] );
- }
- archive.write( "book.readonly", readonly_ );
- archive.write( "book.predefined", predefined_ );
- archive.write( "book.section", section_ );
- archive.write( "book.pages", pages_ );
- }
- cItem::Serialize( archive );
- }*/
-
- /*void cBook::save( const QString& s )
- {
- startSaveSqlStatement("Books");
- savePersistentIntValue("serial", serial); // never forget we have serials on each table
- savePersistentStrValue("title", title_ );
- savePersistentStrValue("author", author_ );
- for ( QMap<int, QString>::iterator it = content_.begin(); it != content_.end(); ++it )
- {
- startSaveSqlStatement("BookPages");
- savePersistentIntValue("serial", serial );
- savePersistentIntValue("page", it.key() );
- savePersistentStrValue("text", it.data() );
- endSaveSqlStatement(QString("serial='%1' AND page='%2'").arg(serial).arg(it.key()));
- }
- savePersistentIntValue("readonly", readonly_ );
- savePersistentIntValue("predefined", predefined_ );
- savePersistentStrValue("section", section_ );
- savePersistentIntValue("pages", pages_ );
- endSaveSqlStatement(QString("serial='%1'").arg(serial));
- cItem::save(s);
- }*/
-
- /*void cBook::load( const QString& s )
- {
- startLoadSqlStatement("Books", "serial", s)
- {
- loadPersistentStrValue("title", title_ );
- loadPersistentStrValue("author", author_ );
- QSqlCursor bookPages("BookPages");
- bookPages.select(QString("serial='%1'").arg(serial));
- while( bookPages.next() )
- {
- content_[bookPages.value("page").toInt()] = bookPages.value("text").toString();
- }
- loadPersistentIntValue( "readonly", readonly_ );
- loadPersistentIntValue( "predefined", predefined_ );
- loadPersistentStrValue( "section", section_ );
- loadPersistentIntValue( "pages", pages_ );
- }
- endLoadSqlStatement(s);
- cItem::load(s);
- }*/
-
- /*bool cBook::del( const QString& s )
- {
- QSqlCursor cursor("Books");
- cursor.select(QString("serial='%1'").arg(serial));
- while ( cursor.next() )
- {
- cursor.primeDelete();
- if ( cursor.del() > 1 )
- {
- qWarning("More than one record was deleted in table Books when only 1 was expected, delete criteria was:");
- qWarning(cursor.filter());
- }
- }
- cursor.setName("BookPages");
- cursor.select(QString("serial='%1'").arg(serial));
- while ( cursor.next() )
- {
- cursor.primeDelete();
- cursor.del();
- }
- return cItem::del( s );
- }*/
void cBook::processNode( const cElement *Tag )
--- 160,163 ----
Index: corpse.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/corpse.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** corpse.cpp 14 Jul 2003 16:58:49 -0000 1.32
--- corpse.cpp 27 Aug 2003 16:06:12 -0000 1.33
***************
*** 111,118 ****
// Equipment can change as well
if( isPersistent )
persistentBroker->executeQuery( QString( "DELETE FROM corpses_equipment WHERE serial = '%1'" ).arg( serial() ) );
for( map< UINT8, SERIAL >::iterator it = equipment_.begin(); it != equipment_.end(); ++it )
! persistentBroker->executeQuery( QString( "INSERT INTO corpses_equipment SET serial = '%1', layer = '%2', item = '%3'" ).arg( serial() ).arg( it->first ).arg( it->second ) );
cItem::save();
--- 111,120 ----
// Equipment can change as well
if( isPersistent )
+ {
persistentBroker->executeQuery( QString( "DELETE FROM corpses_equipment WHERE serial = '%1'" ).arg( serial() ) );
+ }
for( map< UINT8, SERIAL >::iterator it = equipment_.begin(); it != equipment_.end(); ++it )
! persistentBroker->executeQuery( QString( "INSERT INTO corpses_equipment VALUES(%1,%2,%3)" ).arg( serial() ).arg( it->first ).arg( it->second ) );
cItem::save();
Index: customtags.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/customtags.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** customtags.cpp 27 Aug 2003 13:33:17 -0000 1.25
--- customtags.cpp 27 Aug 2003 16:06:12 -0000 1.26
***************
*** 705,713 ****
// Save the Variant type and value
- QString type = it.data().typeName();
- QString value = it.data().toString();
QString name = it.key();
! persistentBroker->executeQuery( QString( "INSERT INTO tags SET serial = '%1', type = '%2', value = '%3', name = '%4'" ).arg( key ).arg( type ).arg( persistentBroker->quoteString( value ) ).arg( persistentBroker->quoteString( name ) ) );
}
--- 705,713 ----
// Save the Variant type and value
QString name = it.key();
+ QString type = it.data().typeName();
+ QString value = it.data().toString();
! persistentBroker->executeQuery( QString( "INSERT INTO tags VALUES(%1,'%2','%3','%4')" ).arg( key ).arg( persistentBroker->quoteString( name ) ).arg( type ).arg( persistentBroker->quoteString( value ) ) );
}
Index: multis.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/multis.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** multis.cpp 20 Aug 2003 17:10:48 -0000 1.32
--- multis.cpp 27 Aug 2003 16:06:12 -0000 1.33
***************
*** 132,139 ****
INT32 i;
for ( i = 0; i < bans_.size(); ++i )
! persistentBroker->executeQuery( QString( "INSERT INTO multis_bans SET serial = '%1', ban = '%2'" ).arg( serial() ).arg( bans_[i] ) );
for ( i = 0; i < friends_.size(); ++i )
! persistentBroker->executeQuery( QString( "INSERT INTO multis_friends SET serial = '%1', friend = '%2'" ).arg( serial() ).arg( friends_[i] ) );
cItem::save();
--- 132,139 ----
INT32 i;
for ( i = 0; i < bans_.size(); ++i )
! persistentBroker->executeQuery( QString( "INSERT INTO multis_bans VALUES(%1,%2)" ).arg( serial() ).arg( bans_[i] ) );
for ( i = 0; i < friends_.size(); ++i )
! persistentBroker->executeQuery( QString( "INSERT INTO multis_friends VALUES(%1,%2)" ).arg( serial() ).arg( friends_[i] ) );
cItem::save();
Index: persistentbroker.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** persistentbroker.h 27 Aug 2003 15:29:18 -0000 1.19
--- persistentbroker.h 27 Aug 2003 16:06:12 -0000 1.20
***************
*** 84,147 ****
};
- #define savePersistentIntValue(field, value) \
- SqlStatement += QString("%1='%2',").arg(field).arg(value)
-
- #define savePersistentStrValue(field, value) \
- if ( !value.isNull() ) \
- SqlStatement += QString("%1='%2',").arg(field).arg(persistentBroker->quoteString(value))
-
- #define startSaveSqlStatement(table) \
- QString SqlStatement; \
- if ( this->isPersistent ) \
- SqlStatement = QString("UPDATE %1 SET ").arg(table); \
- else \
- SqlStatement = QString("INSERT INTO %1 SET ").arg(table);
-
- #define endSaveSqlStatement(condition) \
- SqlStatement = SqlStatement.left( SqlStatement.length() - 1 ); \
- if ( this->isPersistent ) \
- persistentBroker->executeQuery( SqlStatement + QString("WHERE %1;").arg(condition)); \
- else \
- persistentBroker->executeQuery( SqlStatement + ";" );
-
- #define startLoadSqlStatement(table, keyfield, keyvalue) \
- static QSqlCursor cursor(table); \
- cursor.setMode( QSqlCursor::ReadOnly ); \
- cursor.select( QString("%1='%2'").arg(keyfield).arg(keyvalue) ); \
- if ( cursor.first() )
-
- #define endLoadSqlStatement(keyvalue) \
- else \
- qWarning(QString("Error trying to load persistent object %1, key %2").arg(typeid(this).name()).arg(keyvalue));
-
- #define loadPersistentStrValue(fieldName, property) \
- property = cursor.field(fieldName)->value().toString();
-
- #if defined(_DEBUG)
- #define loadPersistentIntValue(fieldName, property) \
- {\
- bool ok = false; \
- property = cursor.field(fieldName)->value().toInt(&ok); \
- if ( !ok ) \
- qWarning(QString("Error trying to read Integer value from field %1").arg(fieldName));\
- }
- #else
- #define loadPersistentIntValue(fieldName, property) \
- property = cursor.field(fieldName)->value().toInt()
- #endif
-
- #if defined(_DEBUG)
- #define loadPersistentUIntValue(fieldName, property) \
- { \
- bool ok = false; \
- property = cursor.field(fieldName)->value().toUInt(&ok); \
- if ( !ok ) \
- qWarning(QString("Error trying to read UInt value from field %1").arg(fieldName));\
- }
- #else
- #define loadPersistentUIntValue(fieldName, property) \
- property = cursor.field(fieldName)->value().toUInt()
- #endif
-
#define initSave QStringList conditions, fields, values; QString table;
#define clearFields conditions.clear(); fields.clear(); values.clear();
--- 84,87 ----
|