1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-17 14:28:24 +01:00

Prefer QSQLITE3 over QSQLITE, but fallback.

This commit is contained in:
Christian Muehlhaeuser 2014-11-05 23:42:02 +01:00
parent 03106296d4
commit bb1e856955

View File

@ -733,15 +733,24 @@ Tomahawk::DatabaseImpl::openDatabase( const QString& dbname, bool checkSchema )
connName += "_" + uuid();
}
static QString sqlDriver;
bool schemaUpdated = false;
int version = -1;
{
QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE", connName );
if ( sqlDriver.isEmpty() )
{
sqlDriver = QString( "QSQLITE3" );
QSqlDatabase testdb = QSqlDatabase::addDatabase( sqlDriver, "testDriverConnection" );
if ( !testdb.isValid() )
sqlDriver = QString( "QSQLITE" );
}
QSqlDatabase db = QSqlDatabase::addDatabase( sqlDriver, connName );
db.setDatabaseName( dbname );
db.setConnectOptions( "QSQLITE_ENABLE_SHARED_CACHE=1" );
if ( !db.open() )
{
tLog() << "Failed to open database" << dbname;
tLog() << "Failed to open database" << dbname << "with driver" << sqlDriver;
throw "failed to open db"; // TODO
}
@ -752,7 +761,7 @@ Tomahawk::DatabaseImpl::openDatabase( const QString& dbname, bool checkSchema )
if ( qry.next() )
{
version = qry.value( 0 ).toInt();
tLog() << "Database schema of" << dbname << "is" << version;
tLog() << "Database schema of" << dbname << sqlDriver << "is" << version;
}
}
else
@ -775,7 +784,7 @@ Tomahawk::DatabaseImpl::openDatabase( const QString& dbname, bool checkSchema )
QFile::copy( dbname, newname );
{
m_db = QSqlDatabase::addDatabase( "QSQLITE", connName );
m_db = QSqlDatabase::addDatabase( sqlDriver, connName );
m_db.setDatabaseName( dbname );
if ( !m_db.open() )
throw "db moving failed";