mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
* Use Db's impl() directly to always be in the right thread for sure.
This commit is contained in:
@@ -68,8 +68,7 @@ DatabaseWorker::~DatabaseWorker()
|
|||||||
void
|
void
|
||||||
DatabaseWorker::run()
|
DatabaseWorker::run()
|
||||||
{
|
{
|
||||||
m_dbimpl = Database::instance()->impl();
|
tDebug() << "New db connection with name:" << Database::instance()->impl()->database().connectionName();
|
||||||
tDebug() << "New db connection with name:" << m_dbimpl->database().connectionName();
|
|
||||||
exec();
|
exec();
|
||||||
qDebug() << Q_FUNC_INFO << "DatabaseWorker finishing...";
|
qDebug() << Q_FUNC_INFO << "DatabaseWorker finishing...";
|
||||||
}
|
}
|
||||||
@@ -122,9 +121,10 @@ DatabaseWorker::doWork()
|
|||||||
cmd = m_commands.takeFirst();
|
cmd = m_commands.takeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseImpl* impl = Database::instance()->impl();
|
||||||
if ( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
{
|
{
|
||||||
bool transok = m_dbimpl->database().transaction();
|
bool transok = impl->database().transaction();
|
||||||
Q_ASSERT( transok );
|
Q_ASSERT( transok );
|
||||||
Q_UNUSED( transok );
|
Q_UNUSED( transok );
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ DatabaseWorker::doWork()
|
|||||||
while ( !finished )
|
while ( !finished )
|
||||||
{
|
{
|
||||||
completed++;
|
completed++;
|
||||||
cmd->_exec( m_dbimpl ); // runs actual SQL stuff
|
cmd->_exec( impl ); // runs actual SQL stuff
|
||||||
|
|
||||||
if ( cmd->loggable() )
|
if ( cmd->loggable() )
|
||||||
{
|
{
|
||||||
@@ -160,7 +160,7 @@ DatabaseWorker::doWork()
|
|||||||
//
|
//
|
||||||
if ( !cmd->singletonCmd() )
|
if ( !cmd->singletonCmd() )
|
||||||
{
|
{
|
||||||
TomahawkSqlQuery query = m_dbimpl->newquery();
|
TomahawkSqlQuery query = impl->newquery();
|
||||||
query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" );
|
query.prepare( "UPDATE source SET lastop = ? WHERE id = ?" );
|
||||||
query.addBindValue( cmd->guid() );
|
query.addBindValue( cmd->guid() );
|
||||||
query.addBindValue( cmd->source()->id() );
|
query.addBindValue( cmd->source()->id() );
|
||||||
@@ -193,7 +193,7 @@ DatabaseWorker::doWork()
|
|||||||
if ( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
{
|
{
|
||||||
qDebug() << "Committing" << cmd->commandname() << cmd->guid();
|
qDebug() << "Committing" << cmd->commandname() << cmd->guid();
|
||||||
if ( !m_dbimpl->newquery().commitTransaction() )
|
if ( !impl->newquery().commitTransaction() )
|
||||||
{
|
{
|
||||||
tDebug() << "FAILED TO COMMIT TRANSACTION*";
|
tDebug() << "FAILED TO COMMIT TRANSACTION*";
|
||||||
throw "commit failed";
|
throw "commit failed";
|
||||||
@@ -219,12 +219,12 @@ DatabaseWorker::doWork()
|
|||||||
<< "*ERROR* processing databasecommand:"
|
<< "*ERROR* processing databasecommand:"
|
||||||
<< cmd->commandname()
|
<< cmd->commandname()
|
||||||
<< msg
|
<< msg
|
||||||
<< m_dbimpl->database().lastError().databaseText()
|
<< impl->database().lastError().databaseText()
|
||||||
<< m_dbimpl->database().lastError().driverText()
|
<< impl->database().lastError().driverText()
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
if ( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
m_dbimpl->database().rollback();
|
impl->database().rollback();
|
||||||
|
|
||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ DatabaseWorker::doWork()
|
|||||||
{
|
{
|
||||||
qDebug() << "Uncaught exception processing dbcmd";
|
qDebug() << "Uncaught exception processing dbcmd";
|
||||||
if ( cmd->doesMutates() )
|
if ( cmd->doesMutates() )
|
||||||
m_dbimpl->database().rollback();
|
impl->database().rollback();
|
||||||
|
|
||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
throw;
|
throw;
|
||||||
@@ -252,7 +252,7 @@ DatabaseWorker::doWork()
|
|||||||
void
|
void
|
||||||
DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
||||||
{
|
{
|
||||||
TomahawkSqlQuery oplogquery = m_dbimpl->newquery();
|
TomahawkSqlQuery oplogquery = Database::instance()->impl()->newquery();
|
||||||
qDebug() << "INSERTING INTO OPTLOG:" << command->source()->id() << command->guid() << command->commandname();
|
qDebug() << "INSERTING INTO OPTLOG:" << command->source()->id() << command->guid() << command->commandname();
|
||||||
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, singleton, compressed, json) "
|
oplogquery.prepare( "INSERT INTO oplog(source, guid, command, singleton, compressed, json) "
|
||||||
"VALUES(?, ?, ?, ?, ?, ?)" );
|
"VALUES(?, ?, ?, ?, ?, ?)" );
|
||||||
@@ -278,7 +278,7 @@ DatabaseWorker::logOp( DatabaseCommandLoggable* command )
|
|||||||
{
|
{
|
||||||
tDebug() << "Singleton command, deleting previous oplog commands";
|
tDebug() << "Singleton command, deleting previous oplog commands";
|
||||||
|
|
||||||
TomahawkSqlQuery oplogdelquery = m_dbimpl->newquery();
|
TomahawkSqlQuery oplogdelquery = Database::instance()->impl()->newquery();
|
||||||
oplogdelquery.prepare( QString( "DELETE FROM oplog WHERE source %1 AND singleton = 'true' AND command = ?" )
|
oplogdelquery.prepare( QString( "DELETE FROM oplog WHERE source %1 AND singleton = 'true' AND command = ?" )
|
||||||
.arg( command->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( command->source()->id() ) ) );
|
.arg( command->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( command->source()->id() ) ) );
|
||||||
|
|
||||||
|
@@ -60,7 +60,6 @@ private:
|
|||||||
|
|
||||||
QMutex m_mut;
|
QMutex m_mut;
|
||||||
Database* m_db;
|
Database* m_db;
|
||||||
DatabaseImpl* m_dbimpl;
|
|
||||||
QList< QSharedPointer<DatabaseCommand> > m_commands;
|
QList< QSharedPointer<DatabaseCommand> > m_commands;
|
||||||
int m_outstanding;
|
int m_outstanding;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user