|
|
|
@ -6062,11 +6062,11 @@ SqliteConnection::SqliteConnection( const SqliteConfig* config )
|
|
|
|
|
{
|
|
|
|
|
TQString format;
|
|
|
|
|
file.readLine( format, 50 );
|
|
|
|
|
if ( !format.startsWith( "STQLite format 3" ) )
|
|
|
|
|
if ( !format.startsWith( "SQLite format 3" ) )
|
|
|
|
|
{
|
|
|
|
|
warning() << "Database versions incompatible. Removing and rebuilding database.\n";
|
|
|
|
|
}
|
|
|
|
|
else if ( sqlite3_open( path, &m_db ) != STQLITE_OK )
|
|
|
|
|
else if ( sqlite3_open( path, &m_db ) != SQLITE_OK )
|
|
|
|
|
{
|
|
|
|
|
warning() << "Database file corrupt. Removing and rebuilding database.\n";
|
|
|
|
|
sqlite3_close( m_db );
|
|
|
|
@ -6079,24 +6079,24 @@ SqliteConnection::SqliteConnection( const SqliteConfig* config )
|
|
|
|
|
{
|
|
|
|
|
// Remove old db file; create new
|
|
|
|
|
TQFile::remove( path );
|
|
|
|
|
if ( sqlite3_open( path, &m_db ) == STQLITE_OK )
|
|
|
|
|
if ( sqlite3_open( path, &m_db ) == SQLITE_OK )
|
|
|
|
|
{
|
|
|
|
|
m_initialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( m_initialized )
|
|
|
|
|
{
|
|
|
|
|
if( sqlite3_create_function(m_db, "rand", 0, STQLITE_UTF8, NULL, sqlite_rand, NULL, NULL) != STQLITE_OK )
|
|
|
|
|
if( sqlite3_create_function(m_db, "rand", 0, SQLITE_UTF8, NULL, sqlite_rand, NULL, NULL) != SQLITE_OK )
|
|
|
|
|
m_initialized = false;
|
|
|
|
|
if( sqlite3_create_function(m_db, "power", 2, STQLITE_UTF8, NULL, sqlite_power, NULL, NULL) != STQLITE_OK )
|
|
|
|
|
if( sqlite3_create_function(m_db, "power", 2, SQLITE_UTF8, NULL, sqlite_power, NULL, NULL) != SQLITE_OK )
|
|
|
|
|
m_initialized = false;
|
|
|
|
|
if ( sqlite3_create_function(m_db, "like", 2, STQLITE_UTF8, NULL, sqlite_like_new, NULL, NULL) != STQLITE_OK )
|
|
|
|
|
if ( sqlite3_create_function(m_db, "like", 2, SQLITE_UTF8, NULL, sqlite_like_new, NULL, NULL) != SQLITE_OK )
|
|
|
|
|
m_initialized = false;
|
|
|
|
|
if ( sqlite3_create_function(m_db, "like", 3, STQLITE_UTF8, NULL, sqlite_like_new, NULL, NULL) != STQLITE_OK )
|
|
|
|
|
if ( sqlite3_create_function(m_db, "like", 3, SQLITE_UTF8, NULL, sqlite_like_new, NULL, NULL) != SQLITE_OK )
|
|
|
|
|
m_initialized = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//optimization for speeding up STQLite
|
|
|
|
|
//optimization for speeding up SQLite
|
|
|
|
|
query( "PRAGMA default_synchronous = OFF;" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -6128,11 +6128,11 @@ TQStringList SqliteConnection::query( const TQString& statement, bool /*suppress
|
|
|
|
|
}
|
|
|
|
|
error = sqlite3_prepare( m_db, statement.utf8(), -1, &stmt, &tail );
|
|
|
|
|
}
|
|
|
|
|
while ( STQLITE_BUSY==error && busyCnt++ < 120 );
|
|
|
|
|
while ( SQLITE_BUSY==error && busyCnt++ < 120 );
|
|
|
|
|
|
|
|
|
|
if ( error != STQLITE_OK )
|
|
|
|
|
if ( error != SQLITE_OK )
|
|
|
|
|
{
|
|
|
|
|
if ( STQLITE_BUSY==error )
|
|
|
|
|
if ( SQLITE_BUSY==error )
|
|
|
|
|
Debug::error() << "Gave up waiting for lock to clear" << endl;
|
|
|
|
|
Debug::error() << k_funcinfo << " sqlite3_compile error:" << endl;
|
|
|
|
|
Debug::error() << sqlite3_errmsg( m_db ) << endl;
|
|
|
|
@ -6149,7 +6149,7 @@ TQStringList SqliteConnection::query( const TQString& statement, bool /*suppress
|
|
|
|
|
{
|
|
|
|
|
error = sqlite3_step( stmt );
|
|
|
|
|
|
|
|
|
|
if ( error == STQLITE_BUSY )
|
|
|
|
|
if ( error == SQLITE_BUSY )
|
|
|
|
|
{
|
|
|
|
|
if ( busyCnt++ > 120 ) {
|
|
|
|
|
Debug::error() << "Busy-counter has reached maximum. Aborting this sql statement!\n";
|
|
|
|
@ -6159,9 +6159,9 @@ TQStringList SqliteConnection::query( const TQString& statement, bool /*suppress
|
|
|
|
|
debug() << "sqlite3_step: BUSY counter: " << busyCnt << endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( error == STQLITE_MISUSE )
|
|
|
|
|
if ( error == SQLITE_MISUSE )
|
|
|
|
|
debug() << "sqlite3_step: MISUSE" << endl;
|
|
|
|
|
if ( error == STQLITE_DONE || error == STQLITE_ERROR )
|
|
|
|
|
if ( error == SQLITE_DONE || error == SQLITE_ERROR )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//iterate over columns
|
|
|
|
@ -6173,17 +6173,17 @@ TQStringList SqliteConnection::query( const TQString& statement, bool /*suppress
|
|
|
|
|
//deallocate vm resources
|
|
|
|
|
rc = sqlite3_finalize( stmt );
|
|
|
|
|
|
|
|
|
|
if ( error != STQLITE_DONE && rc != STQLITE_SCHEMA )
|
|
|
|
|
if ( error != SQLITE_DONE && rc != SQLITE_SCHEMA )
|
|
|
|
|
{
|
|
|
|
|
Debug::error() << k_funcinfo << "sqlite_step error.\n";
|
|
|
|
|
Debug::error() << sqlite3_errmsg( m_db ) << endl;
|
|
|
|
|
Debug::error() << "on query: " << statement << endl;
|
|
|
|
|
values = TQStringList();
|
|
|
|
|
}
|
|
|
|
|
if ( rc == STQLITE_SCHEMA )
|
|
|
|
|
if ( rc == SQLITE_SCHEMA )
|
|
|
|
|
{
|
|
|
|
|
retryCnt++;
|
|
|
|
|
debug() << "STQLITE_SCHEMA error occurred on query: " << statement << endl;
|
|
|
|
|
debug() << "SQLITE_SCHEMA error occurred on query: " << statement << endl;
|
|
|
|
|
if ( retryCnt < 10 )
|
|
|
|
|
debug() << "Retrying now." << endl;
|
|
|
|
|
else
|
|
|
|
@ -6195,7 +6195,7 @@ TQStringList SqliteConnection::query( const TQString& statement, bool /*suppress
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while ( rc == STQLITE_SCHEMA && retryCnt < 10 );
|
|
|
|
|
while ( rc == SQLITE_SCHEMA && retryCnt < 10 );
|
|
|
|
|
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
@ -6220,11 +6220,11 @@ int SqliteConnection::insert( const TQString& statement, const TQString& /* tabl
|
|
|
|
|
}
|
|
|
|
|
error = sqlite3_prepare( m_db, statement.utf8(), -1, &stmt, &tail );
|
|
|
|
|
}
|
|
|
|
|
while ( STQLITE_BUSY==error && busyCnt++ < 120 );
|
|
|
|
|
while ( SQLITE_BUSY==error && busyCnt++ < 120 );
|
|
|
|
|
|
|
|
|
|
if ( error != STQLITE_OK )
|
|
|
|
|
if ( error != SQLITE_OK )
|
|
|
|
|
{
|
|
|
|
|
if ( STQLITE_BUSY==error )
|
|
|
|
|
if ( SQLITE_BUSY==error )
|
|
|
|
|
Debug::error() << "Gave up waiting for lock to clear" << endl;
|
|
|
|
|
Debug::error() << k_funcinfo << " sqlite3_compile error:" << endl;
|
|
|
|
|
Debug::error() << sqlite3_errmsg( m_db ) << endl;
|
|
|
|
@ -6239,7 +6239,7 @@ int SqliteConnection::insert( const TQString& statement, const TQString& /* tabl
|
|
|
|
|
{
|
|
|
|
|
error = sqlite3_step( stmt );
|
|
|
|
|
|
|
|
|
|
if ( error == STQLITE_BUSY )
|
|
|
|
|
if ( error == SQLITE_BUSY )
|
|
|
|
|
{
|
|
|
|
|
if ( busyCnt++ > 120 ) {
|
|
|
|
|
Debug::error() << "Busy-counter has reached maximum. Aborting this sql statement!\n";
|
|
|
|
@ -6248,24 +6248,24 @@ int SqliteConnection::insert( const TQString& statement, const TQString& /* tabl
|
|
|
|
|
::usleep( 100000 ); // Sleep 100 msec
|
|
|
|
|
debug() << "sqlite3_step: BUSY counter: " << busyCnt << endl;
|
|
|
|
|
}
|
|
|
|
|
if ( error == STQLITE_MISUSE )
|
|
|
|
|
if ( error == SQLITE_MISUSE )
|
|
|
|
|
debug() << "sqlite3_step: MISUSE" << endl;
|
|
|
|
|
if ( error == STQLITE_DONE || error == STQLITE_ERROR )
|
|
|
|
|
if ( error == SQLITE_DONE || error == SQLITE_ERROR )
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//deallocate vm resources
|
|
|
|
|
rc = sqlite3_finalize( stmt );
|
|
|
|
|
|
|
|
|
|
if ( error != STQLITE_DONE && rc != STQLITE_SCHEMA)
|
|
|
|
|
if ( error != SQLITE_DONE && rc != SQLITE_SCHEMA)
|
|
|
|
|
{
|
|
|
|
|
Debug::error() << k_funcinfo << "sqlite_step error.\n";
|
|
|
|
|
Debug::error() << sqlite3_errmsg( m_db ) << endl;
|
|
|
|
|
Debug::error() << "on insert: " << statement << endl;
|
|
|
|
|
}
|
|
|
|
|
if ( rc == STQLITE_SCHEMA )
|
|
|
|
|
if ( rc == SQLITE_SCHEMA )
|
|
|
|
|
{
|
|
|
|
|
retryCnt++;
|
|
|
|
|
debug() << "STQLITE_SCHEMA error occurred on insert: " << statement << endl;
|
|
|
|
|
debug() << "SQLITE_SCHEMA error occurred on insert: " << statement << endl;
|
|
|
|
|
if ( retryCnt < 10 )
|
|
|
|
|
debug() << "Retrying now." << endl;
|
|
|
|
|
else
|
|
|
|
@ -6276,7 +6276,7 @@ int SqliteConnection::insert( const TQString& statement, const TQString& /* tabl
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while ( STQLITE_SCHEMA == rc && retryCnt < 10 );
|
|
|
|
|
while ( SQLITE_SCHEMA == rc && retryCnt < 10 );
|
|
|
|
|
return sqlite3_last_insert_rowid( m_db );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -6291,7 +6291,7 @@ void SqliteConnection::sqlite_rand(sqlite3_context *context, int /*argc*/, sqlit
|
|
|
|
|
void SqliteConnection::sqlite_power(sqlite3_context *context, int argc, sqlite3_value **argv)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT( argc==2 );
|
|
|
|
|
if( sqlite3_value_type(argv[0])==STQLITE_NULL || sqlite3_value_type(argv[1])==STQLITE_NULL ) {
|
|
|
|
|
if( sqlite3_value_type(argv[0])==SQLITE_NULL || sqlite3_value_type(argv[1])==SQLITE_NULL ) {
|
|
|
|
|
sqlite3_result_null(context);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -6356,7 +6356,7 @@ MySqlConnection::MySqlConnection( const MySqlConfig* config )
|
|
|
|
|
{
|
|
|
|
|
m_initialized = true;
|
|
|
|
|
|
|
|
|
|
#if MYSTQL_VERSION_ID >= 40113
|
|
|
|
|
#if MYSQL_VERSION_ID >= 40113
|
|
|
|
|
// now set the right charset for the connection
|
|
|
|
|
TQStringList my_qslist = query( "SHOW VARIABLES LIKE 'character_set_database'" );
|
|
|
|
|
if( !my_qslist.isEmpty() && !mysql_set_character_set( m_db, const_cast<char *>( my_qslist[1].latin1() ) ) )
|
|
|
|
@ -6409,11 +6409,11 @@ TQStringList MySqlConnection::query( const TQString& statement, bool suppressDeb
|
|
|
|
|
|
|
|
|
|
if ( !mysql_query( m_db, statement.utf8() ) )
|
|
|
|
|
{
|
|
|
|
|
MYSTQL_RES* result;
|
|
|
|
|
MYSQL_RES* result;
|
|
|
|
|
if ( ( result = mysql_use_result( m_db ) ) )
|
|
|
|
|
{
|
|
|
|
|
int number = mysql_field_count( m_db );
|
|
|
|
|
MYSTQL_ROW row;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
while ( ( row = mysql_fetch_row( result ) ) )
|
|
|
|
|
{
|
|
|
|
|
for ( int i = 0; i < number; i++ )
|
|
|
|
@ -6530,7 +6530,7 @@ TQStringList PostgresqlConnection::query( const TQString& statement, bool suppre
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = PQresulttqStatus(result);
|
|
|
|
|
status = PQresultStatus(result);
|
|
|
|
|
if ((status != PGRES_COMMAND_OK) && (status != PGRES_TUPLES_OK))
|
|
|
|
|
{
|
|
|
|
|
if ( !suppressDebug )
|
|
|
|
@ -6579,7 +6579,7 @@ int PostgresqlConnection::insert( const TQString& statement, const TQString& tab
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = PQresulttqStatus(result);
|
|
|
|
|
status = PQresultStatus(result);
|
|
|
|
|
if (status != PGRES_COMMAND_OK)
|
|
|
|
|
{
|
|
|
|
|
debug() << "POSTGRESQL INSERT FAILED: " << PQerrorMessage( m_db ) << "\n" << "FAILED SQL: " << statement << "\n";
|
|
|
|
@ -6601,7 +6601,7 @@ int PostgresqlConnection::insert( const TQString& statement, const TQString& tab
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = PQresulttqStatus(result);
|
|
|
|
|
status = PQresultStatus(result);
|
|
|
|
|
if (status != PGRES_TUPLES_OK)
|
|
|
|
|
{
|
|
|
|
|
debug() << "POSTGRESQL INSERT FAILED: " << PQerrorMessage( m_db ) << "\n" << "FAILED SQL: " << curvalSql << "\n";
|
|
|
|
@ -7660,7 +7660,7 @@ const int
|
|
|
|
|
QueryBuilder::dragFieldCount = 21;
|
|
|
|
|
|
|
|
|
|
TQString
|
|
|
|
|
QueryBuilder::dragSTQLFields()
|
|
|
|
|
QueryBuilder::dragSQLFields()
|
|
|
|
|
{
|
|
|
|
|
return "tags.url, tags.deviceid, album.name, artist.name, composer.name, "
|
|
|
|
|
"genre.name, tags.title, year.name, "
|
|
|
|
@ -7672,7 +7672,7 @@ QueryBuilder::dragSTQLFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
QueryBuilder::initSTQLDrag()
|
|
|
|
|
QueryBuilder::initSQLDrag()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
addReturnValue( QueryBuilder::tabSong, QueryBuilder::valURL );
|
|
|
|
|