1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-19 12:21:52 +02:00

* Move database dumping into its own method.

This commit is contained in:
Christian Muehlhaeuser
2012-01-20 02:15:27 +01:00
parent 1f2cc33364
commit 60b746c430
2 changed files with 30 additions and 21 deletions

View File

@@ -83,27 +83,7 @@ DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )
if ( qApp->arguments().contains( "--dumpdb" ) ) if ( qApp->arguments().contains( "--dumpdb" ) )
{ {
QFile dump( "dbdump.txt" ); dumpDatabase();
if ( !dump.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
tDebug() << "Couldn't open dbdump.txt for writing!";
Q_ASSERT( false );
}
else
{
QTextStream dumpout( &dump );
query.exec( "SELECT * FROM oplog" );
while ( query.next() )
{
dumpout << "ID: " << query.value( 0 ).toInt() << endl
<< "GUID: " << query.value( 2 ).toString() << endl
<< "Command: " << query.value( 3 ).toString() << endl
<< "Singleton: " << query.value( 4 ).toBool() << endl
<< "JSON: " << ( query.value( 5 ).toBool() ? qUncompress( query.value( 6 ).toByteArray() ) : query.value( 6 ).toByteArray() )
<< endl << endl << endl;
}
}
::exit( 0 ); ::exit( 0 );
} }
} }
@@ -115,6 +95,34 @@ DatabaseImpl::~DatabaseImpl()
} }
void
DatabaseImpl::dumpDatabase()
{
QFile dump( "dbdump.txt" );
if ( !dump.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
tDebug() << "Couldn't open dbdump.txt for writing!";
Q_ASSERT( false );
}
else
{
QTextStream dumpout( &dump );
TomahawkSqlQuery query = newquery();
query.exec( "SELECT * FROM oplog" );
while ( query.next() )
{
dumpout << "ID: " << query.value( 0 ).toInt() << endl
<< "GUID: " << query.value( 2 ).toString() << endl
<< "Command: " << query.value( 3 ).toString() << endl
<< "Singleton: " << query.value( 4 ).toBool() << endl
<< "JSON: " << ( query.value( 5 ).toBool() ? qUncompress( query.value( 6 ).toByteArray() ) : query.value( 6 ).toByteArray() )
<< endl << endl << endl;
}
}
}
void void
DatabaseImpl::loadIndex() DatabaseImpl::loadIndex()
{ {

View File

@@ -84,6 +84,7 @@ public slots:
private: private:
QString cleanSql( const QString& sql ); QString cleanSql( const QString& sql );
bool updateSchema( int oldVersion ); bool updateSchema( int oldVersion );
void dumpDatabase();
bool m_ready; bool m_ready;
QSqlDatabase m_db; QSqlDatabase m_db;