Initial TQt conversion

pull/1/head
Slávek Banko 11 years ago
parent 40d6261f7d
commit 5f9410ae91

@ -1060,7 +1060,7 @@ elif test "$kde_use_qt_emb" = "yes"; then
x_includes=""
x_libraries=""
elif test "$kde_use_qt_mac" = "yes"; then
dnl We're using QT/Mac (I use QT_MAC so that qglobal.h doesn't *have* to
dnl We're using QT/Mac (I use QT_MAC so that ntqglobal.h doesn't *have* to
dnl be included to get the information) --Sam
CXXFLAGS="$CXXFLAGS -DQT_MAC -no-cpp-precomp"
CFLAGS="$CFLAGS -DQT_MAC -no-cpp-precomp"
@ -1092,19 +1092,19 @@ AC_DEFUN([KDE_PRINT_QT_PROGRAM],
AC_REQUIRE([KDE_USE_QT])
cat > conftest.$ac_ext <<EOF
#include "confdefs.h"
#include <qglobal.h>
#include <qapplication.h>
#include <ntqglobal.h>
#include <ntqapplication.h>
EOF
if test "$kde_qtver" = "2"; then
cat >> conftest.$ac_ext <<EOF
#include <qevent.h>
#include <qstring.h>
#include <qstyle.h>
#include <ntqevent.h>
#include <ntqstring.h>
#include <ntqstyle.h>
EOF
if test $kde_qtsubver -gt 0; then
cat >> conftest.$ac_ext <<EOF
#if QT_VERSION < 210
#if TQT_VERSION < 210
#error 1
#endif
EOF
@ -1113,8 +1113,8 @@ fi
if test "$kde_qtver" = "3"; then
cat >> conftest.$ac_ext <<EOF
#include <qcursor.h>
#include <qstylefactory.h>
#include <ntqcursor.h>
#include <ntqstylefactory.h>
#include <private/qucomextra_p.h>
EOF
fi
@ -1201,22 +1201,22 @@ fi
if test -z "$3"; then
if test $kde_qtver = 3; then
if test $kde_qtsubver -gt 0; then
kde_qt_verstring="QT_VERSION >= 0x03@VER@00 && QT_VERSION < 0x040000"
kde_qt_verstring="TQT_VERSION >= 0x03@VER@00 && TQT_VERSION < 0x040000"
qtsubver=`echo "00$kde_qtsubver" | sed -e 's,.*\(..\)$,\1,'`
kde_qt_verstring=`echo $kde_qt_verstring | sed -e "s,@VER@,$qtsubver,"`
else
kde_qt_verstring="QT_VERSION >= 300 && QT_VERSION < 0x040000"
kde_qt_verstring="TQT_VERSION >= 300 && TQT_VERSION < 0x040000"
fi
fi
if test $kde_qtver = 2; then
if test $kde_qtsubver -gt 0; then
kde_qt_verstring="QT_VERSION >= 222"
kde_qt_verstring="TQT_VERSION >= 222"
else
kde_qt_verstring="QT_VERSION >= 200"
kde_qt_verstring="TQT_VERSION >= 200"
fi
fi
if test $kde_qtver = 1; then
kde_qt_verstring="QT_VERSION >= 142 && QT_VERSION < 200"
kde_qt_verstring="TQT_VERSION >= 142 && TQT_VERSION < 200"
fi
else
kde_qt_verstring="$3"
@ -1325,7 +1325,7 @@ AC_ARG_ENABLE(
USING_QT_MT=""
dnl ------------------------------------------------------------------------
dnl If we not get --disable-qt-mt then adjust some vars for the host.
dnl If we not get --disable-tqt-mt then adjust some vars for the host.
dnl ------------------------------------------------------------------------
KDE_MT_LDFLAGS=
@ -1383,7 +1383,7 @@ dnl ------------------------------------------------------------
fi
dnl ------------------------------------------------------------------------
dnl If we got --enable-qt-mt then adjust the Qt library name for the host.
dnl If we got --enable-tqt-mt then adjust the Qt library name for the host.
dnl ------------------------------------------------------------------------
if test "x$kde_use_qt_mt" = "xyes"; then
@ -1449,9 +1449,9 @@ if test ! "$ac_qt_includes" = "NO"; then
fi
if test "$kde_qtver" != "1"; then
kde_qt_header=qstyle.h
kde_qt_header=ntqstyle.h
else
kde_qt_header=qglobal.h
kde_qt_header=ntqglobal.h
fi
AC_FIND_FILE($kde_qt_header, $qt_incdirs, qt_incdir)
@ -2034,7 +2034,7 @@ AC_CACHE_VAL(kde_cv_have_kdeqtaddon,
LDFLAGS="$LDFLAGS $all_libraries $USER_LDFLAGS"
AC_TRY_LINK([
#include <qdom.h>
#include <ntqdom.h>
],
[
QDomDocument doc;
@ -2595,7 +2595,7 @@ LIBS=`echo $LIBS | sed "s/$LIBJPEG//"`
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $all_includes $USER_INCLUDES"
AC_TRY_LINK(
[#include <qapplication.h>],
[#include <ntqapplication.h>],
[
int argc;
char** argv;
@ -3439,7 +3439,7 @@ AC_DEFUN([KDE_ENABLE_HIDDEN_VISIBILITY],
AC_TRY_COMPILE(
[
#include <qglobal.h>
#include <ntqglobal.h>
#if Q_EXPORT - 0 != 0
/* if this compiles, then Q_EXPORT is undefined */
/* if Q_EXPORT is nonempty, this will break compilation */
@ -4687,7 +4687,7 @@ CXXFLAGS="$CXXFLAGS -I$qt_incdir $all_includes"
AC_TRY_RUN(dnl
[
#include <qimageio.h>
#include <qstring.h>
#include <ntqstring.h>
int main() {
QString t = "hallo";
t.fill('t');
@ -5531,7 +5531,7 @@ if test "${with_qt_dir+set}" = set; then
kde_qtdir="$with_qt_dir"
fi
AC_FIND_FILE(qsql.html, [ $kde_qtdir/doc/html $QTDIR/doc/html /usr/share/doc/packages/qt3/html /usr/lib/qt/doc /usr/lib/qt3/doc /usr/lib/qt3/doc/html /usr/doc/qt3/html /usr/doc/qt3 /usr/share/doc/qt3-doc /usr/share/qt3/doc/html /usr/X11R6/share/doc/qt/html ], QTDOCDIR)
AC_FIND_FILE(ntqsql.html, [ $kde_qtdir/doc/html $QTDIR/doc/html /usr/share/doc/packages/qt3/html /usr/lib/qt/doc /usr/lib/qt3/doc /usr/lib/qt3/doc/html /usr/doc/qt3/html /usr/doc/qt3 /usr/share/doc/qt3-doc /usr/share/qt3/doc/html /usr/X11R6/share/doc/qt/html ], QTDOCDIR)
AC_MSG_RESULT($QTDOCDIR)
AC_SUBST(QTDOCDIR)
@ -5552,7 +5552,7 @@ AC_SUBST(DOXYGEN_PROJECT_NAME)
AC_SUBST(DOXYGEN_PROJECT_NUMBER)
KDE_HAS_DOXYGEN=no
if test -n "$DOXYGEN" && test -x "$DOXYGEN" && test -f $QTDOCDIR/qsql.html; then
if test -n "$DOXYGEN" && test -x "$DOXYGEN" && test -f $QTDOCDIR/ntqsql.html; then
KDE_HAS_DOXYGEN=yes
fi
AC_SUBST(KDE_HAS_DOXYGEN)

@ -21,7 +21,7 @@
#include <kconfig.h>
#include <kglobal.h>
MySQLRecipeDB::MySQLRecipeDB( const QString &host, const QString &user, const QString &pass, const QString &DBname, int port ) : QSqlRecipeDB( host, user, pass, DBname, port )
MySQLRecipeDB::MySQLRecipeDB( const TQString &host, const TQString &user, const TQString &pass, const TQString &DBname, int port ) : TQSqlRecipeDB( host, user, pass, DBname, port )
{}
MySQLRecipeDB::~MySQLRecipeDB()
@ -29,7 +29,7 @@ MySQLRecipeDB::~MySQLRecipeDB()
void MySQLRecipeDB::createDB()
{
QString real_db_name = database->databaseName();
TQString real_db_name = database->databaseName();
//we have to be connected to some database in order to create the Krecipes database
//so long as the permissions given are allowed access to "mysql', this works
@ -37,7 +37,7 @@ void MySQLRecipeDB::createDB()
if ( database->open() ) {
// Create the Database (Note: needs permissions)
//FIXME: I've noticed certain characters cause this to fail (such as '-'). Somehow let the user know.
QSqlQuery query( QString( "CREATE DATABASE %1" ).arg( real_db_name ), database );
TQSqlQuery query( TQString( "CREATE DATABASE %1" ).arg( real_db_name ), database );
if ( !query.isActive() )
kdDebug() << "create query failed: " << database->lastError().databaseText() << endl;
@ -49,49 +49,49 @@ void MySQLRecipeDB::createDB()
database->setDatabaseName( real_db_name );
}
QStringList MySQLRecipeDB::backupCommand() const
TQStringList MySQLRecipeDB::backupCommand() const
{
KConfig *config = KGlobal::config();
config->setGroup("Server");
QStringList command;
TQStringList command;
command<<config->readEntry( "MySQLDumpPath", "mysqldump" )<<"-q";
QString pass = config->readEntry("Password", QString::null);
TQString pass = config->readEntry("Password", TQString::null);
if ( !pass.isEmpty() )
command<<"-p"+pass;
QString user = config->readEntry("Username", QString::null);
TQString user = config->readEntry("Username", TQString::null);
command<<"-u"+user;
command<<"-h"+config->readEntry("Host", "localhost");
int port = config->readNumEntry("Port", 0);
if ( port > 0 )
command<<"-P"+QString::number(port);
command<<"-P"+TQString::number(port);
command<<database->databaseName();
return command;
}
QStringList MySQLRecipeDB::restoreCommand() const
TQStringList MySQLRecipeDB::restoreCommand() const
{
KConfig *config = KGlobal::config();
config->setGroup("Server");
QStringList command;
TQStringList command;
command<<config->readEntry( "MySQLPath", "mysql" );
QString pass = config->readEntry("Password", QString::null);
TQString pass = config->readEntry("Password", TQString::null);
if ( !pass.isEmpty() )
command<<"-p"+pass;
QString user = config->readEntry("Username", QString::null);
TQString user = config->readEntry("Username", TQString::null);
command<<"-u"+user;
int port = config->readNumEntry("Port", 0);
if ( port > 0 )
command<<"-P"+QString::number(port);
command<<"-P"+TQString::number(port);
command<<"-h"+config->readEntry("Host", "localhost");
@ -99,16 +99,16 @@ QStringList MySQLRecipeDB::restoreCommand() const
return command;
}
void MySQLRecipeDB::createTable( const QString &tableName )
void MySQLRecipeDB::createTable( const TQString &tableName )
{
QStringList commands;
TQStringList commands;
if ( tableName == "recipes" )
commands << QString( "CREATE TABLE recipes (id INTEGER NOT NULL AUTO_INCREMENT,title VARCHAR(%1), yield_amount FLOAT, yield_amount_offset FLOAT, yield_type_id int(11) DEFAULT '-1', instructions TEXT, photo BLOB, prep_time TIME, ctime TIMESTAMP, mtime TIMESTAMP, atime TIMESTAMP, PRIMARY KEY (id));" ).arg( maxRecipeTitleLength() );
commands << TQString( "CREATE TABLE recipes (id INTEGER NOT NULL AUTO_INCREMENT,title VARCHAR(%1), yield_amount FLOAT, yield_amount_offset FLOAT, yield_type_id int(11) DEFAULT '-1', instructions TEXT, photo BLOB, prep_time TIME, ctime TIMESTAMP, mtime TIMESTAMP, atime TIMESTAMP, PRIMARY KEY (id));" ).arg( maxRecipeTitleLength() );
else if ( tableName == "ingredients" )
commands << QString( "CREATE TABLE ingredients (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxIngredientNameLength() );
commands << TQString( "CREATE TABLE ingredients (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxIngredientNameLength() );
else if ( tableName == "ingredient_list" )
commands << "CREATE TABLE ingredient_list (id INTEGER NOT NULL AUTO_INCREMENT, recipe_id INTEGER, ingredient_id INTEGER, amount FLOAT, amount_offset FLOAT, unit_id INTEGER, order_index INTEGER, group_id INTEGER, substitute_for INTEGER, PRIMARY KEY(id), INDEX ridil_index(recipe_id), INDEX iidil_index(ingredient_id), INDEX gidil_index(group_id))";
@ -117,11 +117,11 @@ void MySQLRecipeDB::createTable( const QString &tableName )
commands << "CREATE TABLE unit_list (ingredient_id INTEGER, unit_id INTEGER);";
else if ( tableName == "units" )
commands << QString( "CREATE TABLE units (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), name_abbrev VARCHAR(%2), plural VARCHAR(%3), plural_abbrev VARCHAR(%4), type INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (id));" )
commands << TQString( "CREATE TABLE units (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), name_abbrev VARCHAR(%2), plural VARCHAR(%3), plural_abbrev VARCHAR(%4), type INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (id));" )
.arg( maxUnitNameLength() ).arg( maxUnitNameLength() ).arg( maxUnitNameLength() ).arg( maxUnitNameLength() );
else if ( tableName == "prep_methods" )
commands << QString( "CREATE TABLE prep_methods (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxPrepMethodNameLength() );
commands << TQString( "CREATE TABLE prep_methods (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxPrepMethodNameLength() );
else if ( tableName == "prep_method_list" )
commands << "CREATE TABLE prep_method_list (ingredient_list_id int(11) NOT NULL,prep_method_id int(11) NOT NULL, order_index int(11), INDEX iid_index (ingredient_list_id), INDEX pid_index (prep_method_id));";
@ -139,26 +139,26 @@ void MySQLRecipeDB::createTable( const QString &tableName )
commands << "CREATE TABLE units_conversion (unit1_id INTEGER, unit2_id INTEGER, ratio FLOAT);";
else if ( tableName == "categories" )
commands << QString( "CREATE TABLE categories (id int(11) NOT NULL auto_increment, name varchar(%1) default NULL, parent_id int(11) NOT NULL default -1, PRIMARY KEY (id), INDEX parent_id_index(parent_id));" ).arg( maxCategoryNameLength() );
commands << TQString( "CREATE TABLE categories (id int(11) NOT NULL auto_increment, name varchar(%1) default NULL, parent_id int(11) NOT NULL default -1, PRIMARY KEY (id), INDEX parent_id_index(parent_id));" ).arg( maxCategoryNameLength() );
else if ( tableName == "category_list" )
commands << "CREATE TABLE category_list (recipe_id int(11) NOT NULL,category_id int(11) NOT NULL, INDEX rid_index (recipe_id), INDEX cid_index (category_id));";
else if ( tableName == "authors" )
commands << QString( "CREATE TABLE authors (id int(11) NOT NULL auto_increment, name varchar(%1) default NULL,PRIMARY KEY (id));" ).arg( maxAuthorNameLength() );
commands << TQString( "CREATE TABLE authors (id int(11) NOT NULL auto_increment, name varchar(%1) default NULL,PRIMARY KEY (id));" ).arg( maxAuthorNameLength() );
else if ( tableName == "author_list" )
commands << "CREATE TABLE author_list (recipe_id int(11) NOT NULL,author_id int(11) NOT NULL);";
else if ( tableName == "db_info" ) {
commands << "CREATE TABLE db_info (ver FLOAT NOT NULL,generated_by varchar(200) default NULL);";
commands << QString( "INSERT INTO db_info VALUES(%1,'Krecipes %2');" ).arg( latestDBVersion() ).arg( krecipes_version() );
commands << TQString( "INSERT INTO db_info VALUES(%1,'Krecipes %2');" ).arg( latestDBVersion() ).arg( krecipes_version() );
}
else if ( tableName == "ingredient_groups" ) {
commands << QString( "CREATE TABLE `ingredient_groups` (`id` int(11) NOT NULL auto_increment, `name` varchar(%1), PRIMARY KEY (`id`));" ).arg( maxIngGroupNameLength() );
commands << TQString( "CREATE TABLE `ingredient_groups` (`id` int(11) NOT NULL auto_increment, `name` varchar(%1), PRIMARY KEY (`id`));" ).arg( maxIngGroupNameLength() );
}
else if ( tableName == "yield_types" ) {
commands << QString( "CREATE TABLE `yield_types` (`id` int(11) NOT NULL auto_increment, `name` varchar(%1), PRIMARY KEY (`id`));" ).arg( 20 );
commands << TQString( "CREATE TABLE `yield_types` (`id` int(11) NOT NULL auto_increment, `name` varchar(%1), PRIMARY KEY (`id`));" ).arg( 20 );
}
else if ( tableName == "ratings" )
@ -173,29 +173,29 @@ void MySQLRecipeDB::createTable( const QString &tableName )
else
return ;
QSqlQuery databaseToCreate( QString::null, database );
TQSqlQuery databaseToCreate( TQString::null, database );
// execute the queries
for ( QStringList::const_iterator it = commands.begin(); it != commands.end(); ++it )
for ( TQStringList::const_iterator it = commands.begin(); it != commands.end(); ++it )
databaseToCreate.exec( ( *it ) );
}
void MySQLRecipeDB::portOldDatabases( float version )
{
kdDebug() << "Current database version is..." << version << "\n";
QString command;
TQString command;
// Note that version no. means the version in which this DB structure
// was introduced. To work with SVN users, the database will be incrementally
// upgraded for each change made between releases (e.g. 0.81, 0.82,... are
// what will become 0.9)
if ( qRound(version*10) < 3 ) // The database was generated with a version older than v 0.3. First update to 0.3 version
if ( tqRound(version*10) < 3 ) // The database was generated with a version older than v 0.3. First update to 0.3 version
{
// Add new columns to existing tables (creating new tables is not necessary. Integrity check does that before)
command = "ALTER TABLE recipes ADD COLUMN persons int(11) AFTER title;";
QSqlQuery tableToAlter( command, database );
TQSqlQuery tableToAlter( command, database );
// Set the version to the new one (0.3)
@ -205,12 +205,12 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*10) < 4 ) // Upgrade to the current DB version 0.4
if ( tqRound(version*10) < 4 ) // Upgrade to the current DB version 0.4
{
// Add new columns to existing tables (creating any new tables is not necessary. Integrity check does that before)
command = "ALTER TABLE ingredient_list ADD COLUMN order_index int(11) AFTER unit_id;";
QSqlQuery tableToAlter( command, database );
TQSqlQuery tableToAlter( command, database );
// Missing indexes in the previous versions
command = "CREATE index rid_index ON category_list(recipe_id)";
@ -229,13 +229,13 @@ void MySQLRecipeDB::portOldDatabases( float version )
//*1:: Recipes have always category -1 to speed up searches (no JOINs needed)
command = "SELECT r.id FROM recipes r;"; // Find all recipes
QSqlQuery categoryToAdd( QString::null, database );
TQSqlQuery categoryToAdd( TQString::null, database );
tableToAlter.exec( command );
if ( tableToAlter.isActive() )
{
while ( tableToAlter.next() ) {
int recipeId = tableToAlter.value( 0 ).toInt();
QString cCommand = QString( "INSERT INTO category_list VALUES (%1,-1);" ).arg( recipeId );
TQString cCommand = TQString( "INSERT INTO category_list VALUES (%1,-1);" ).arg( recipeId );
categoryToAdd.exec( cCommand );
emit progress();
@ -250,9 +250,9 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*10) < 5 ) {
command = QString( "CREATE TABLE prep_methods (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxPrepMethodNameLength() );
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*10) < 5 ) {
command = TQString( "CREATE TABLE prep_methods (id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(%1), PRIMARY KEY (id));" ).arg( maxPrepMethodNameLength() );
TQSqlQuery tableToAlter( command, database );
command = "ALTER TABLE ingredient_list ADD COLUMN prep_method_id int(11) AFTER unit_id;";
tableToAlter.exec( command );
@ -271,9 +271,9 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*10) < 6 ) {
if ( tqRound(version*10) < 6 ) {
command = "ALTER TABLE categories ADD COLUMN parent_id int(11) NOT NULL default '-1' AFTER name;";
QSqlQuery tableToAlter( command, database );
TQSqlQuery tableToAlter( command, database );
command = "DELETE FROM db_info;"; // Remove previous version records if they exist
tableToAlter.exec( command );
@ -281,9 +281,9 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*100) < 61 ) {
QString command = "ALTER TABLE `recipes` ADD COLUMN `prep_time` TIME DEFAULT NULL";
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*100) < 61 ) {
TQString command = "ALTER TABLE `recipes` ADD COLUMN `prep_time` TIME DEFAULT NULL";
TQSqlQuery tableToAlter( command, database );
command = "DELETE FROM db_info;"; // Remove previous version records if they exist
tableToAlter.exec( command );
@ -291,9 +291,9 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*100) < 62 ) {
QString command = "ALTER TABLE `ingredient_list` ADD COLUMN `group_id` int(11) default '-1' AFTER order_index;";
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*100) < 62 ) {
TQString command = "ALTER TABLE `ingredient_list` ADD COLUMN `group_id` int(11) default '-1' AFTER order_index;";
TQSqlQuery tableToAlter( command, database );
command = "DELETE FROM db_info;"; // Remove previous version records if they exist
tableToAlter.exec( command );
@ -301,15 +301,15 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*100) < 63 ) {
QString command = "ALTER TABLE `units` ADD COLUMN `plural` varchar(20) DEFAULT NULL AFTER name;";
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*100) < 63 ) {
TQString command = "ALTER TABLE `units` ADD COLUMN `plural` varchar(20) DEFAULT NULL AFTER name;";
TQSqlQuery tableToAlter( command, database );
QSqlQuery result( "SELECT id,name FROM units WHERE plural IS NULL", database );
TQSqlQuery result( "SELECT id,name FROM units WHERE plural IS NULL", database );
if ( result.isActive() ) {
while ( result.next() ) {
command = "UPDATE units SET plural='" + result.value( 1 ).toString() + "' WHERE id=" + QString::number( result.value( 0 ).toInt() );
QSqlQuery query( command, database );
command = "UPDATE units SET plural='" + result.value( 1 ).toString() + "' WHERE id=" + TQString::number( result.value( 0 ).toInt() );
TQSqlQuery query( command, database );
emit progress();
}
@ -321,22 +321,22 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*10) < 7 ) { //simply call 0.63 -> 0.7
QString command = "UPDATE db_info SET ver='0.7';";
QSqlQuery query( command, database );
if ( tqRound(version*10) < 7 ) { //simply call 0.63 -> 0.7
TQString command = "UPDATE db_info SET ver='0.7';";
TQSqlQuery query( command, database );
}
if ( qRound(version*100) < 81 ) {
QString command = "ALTER TABLE `ingredient_list` ADD COLUMN `amount_offset` FLOAT DEFAULT '0' AFTER amount;";
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*100) < 81 ) {
TQString command = "ALTER TABLE `ingredient_list` ADD COLUMN `amount_offset` FLOAT DEFAULT '0' AFTER amount;";
TQSqlQuery tableToAlter( command, database );
command = "UPDATE db_info SET ver='0.81',generated_by='Krecipes SVN (20050816)';";
tableToAlter.exec( command );
}
if ( qRound(version*100) < 82 ) {
QString command = "ALTER TABLE `recipes` ADD COLUMN `yield_amount` FLOAT DEFAULT '0' AFTER persons;";
QSqlQuery tableToAlter( command, database );
if ( tqRound(version*100) < 82 ) {
TQString command = "ALTER TABLE `recipes` ADD COLUMN `yield_amount` FLOAT DEFAULT '0' AFTER persons;";
TQSqlQuery tableToAlter( command, database );
command = "ALTER TABLE `recipes` ADD COLUMN `yield_amount_offset` FLOAT DEFAULT '0' AFTER yield_amount;";
tableToAlter.exec(command);
@ -344,11 +344,11 @@ void MySQLRecipeDB::portOldDatabases( float version )
command = "ALTER TABLE `recipes` ADD COLUMN `yield_type_id` INTEGER DEFAULT '-1' AFTER yield_amount_offset;";
tableToAlter.exec(command);
QSqlQuery result( "SELECT id,persons FROM recipes", database );
TQSqlQuery result( "SELECT id,persons FROM recipes", database );
if ( result.isActive() ) {
while ( result.next() ) {
command = "UPDATE recipes SET yield_amount='" + QString::number( result.value( 1 ).toInt() ) + "' WHERE id=" + QString::number( result.value( 0 ).toInt() );
QSqlQuery query( command, database );
command = "UPDATE recipes SET yield_amount='" + TQString::number( result.value( 1 ).toInt() ) + "' WHERE id=" + TQString::number( result.value( 0 ).toInt() );
TQSqlQuery query( command, database );
emit progress();
}
@ -361,17 +361,17 @@ void MySQLRecipeDB::portOldDatabases( float version )
tableToAlter.exec( command );
}
if ( qRound(version*100) < 83 ) {
if ( tqRound(version*100) < 83 ) {
database->transaction();
//====add a id columns to 'ingredient_list' to identify it for the prep method list
database->exec( "RENAME TABLE ingredient_list TO ingredient_list_copy;" );
database->exec( "CREATE TABLE ingredient_list (id INTEGER NOT NULL AUTO_INCREMENT, recipe_id INTEGER, ingredient_id INTEGER, amount FLOAT, amount_offset FLOAT, unit_id INTEGER, order_index INTEGER, group_id INTEGER, PRIMARY KEY(id), INDEX ridil_index(recipe_id), INDEX iidil_index(ingredient_id));" );
QSqlQuery copyQuery = database->exec( "SELECT recipe_id,ingredient_id,amount,amount_offset,unit_id,prep_method_id,order_index,group_id FROM ingredient_list_copy" );
TQSqlQuery copyQuery = database->exec( "SELECT recipe_id,ingredient_id,amount,amount_offset,unit_id,prep_method_id,order_index,group_id FROM ingredient_list_copy" );
if ( copyQuery.isActive() ) {
while ( copyQuery.next() ) {
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.prepare( "INSERT INTO ingredient_list VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)" );
query.addBindValue( copyQuery.value( 0 ) );
query.addBindValue( copyQuery.value( 1 ) );
@ -402,7 +402,7 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.83 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 84 ) {
if ( tqRound(version*100) < 84 ) {
database->transaction();
database->exec( "ALTER TABLE recipes ADD COLUMN ctime TIMESTAMP;" );
@ -417,10 +417,10 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.84 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 85 ) {
if ( tqRound(version*100) < 85 ) {
database->transaction();
QSqlQuery query( "SELECT id,photo FROM recipes", database );
TQSqlQuery query( "SELECT id,photo FROM recipes", database );
if ( query.isActive() ) {
while ( query.next() ) {
@ -436,24 +436,24 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.85 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 86 ) {
if ( tqRound(version*100) < 86 ) {
database->transaction();
database->exec( "ALTER TABLE ingredient_list ADD INDEX (group_id)" );
QSqlQuery query( "SELECT id,name FROM ingredient_groups ORDER BY name", database );
TQSqlQuery query( "SELECT id,name FROM ingredient_groups ORDER BY name", database );
QString last;
TQString last;
int lastID;
if ( query.isActive() ) {
while ( query.next() ) {
QString name = query.value(1).toString();
TQString name = query.value(1).toString();
int id = query.value(0).toInt();
if ( last == name ) {
QString command = QString("UPDATE ingredient_list SET group_id=%1 WHERE group_id=%2").arg(lastID).arg(id);
TQString command = TQString("UPDATE ingredient_list SET group_id=%1 WHERE group_id=%2").arg(lastID).arg(id);
database->exec(command);
command = QString("DELETE FROM ingredient_groups WHERE id=%1").arg(id);
command = TQString("DELETE FROM ingredient_groups WHERE id=%1").arg(id);
database->exec(command);
}
last = name;
@ -468,27 +468,27 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.86 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 87 ) {
if ( tqRound(version*100) < 87 ) {
//Load this default data so the user knows what rating criteria is
database->exec( QString("INSERT INTO rating_criteria VALUES (1,'%1')").arg(i18n("Overall")) );
database->exec( QString("INSERT INTO rating_criteria VALUES (2,'%1')").arg(i18n("Taste") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (3,'%1')").arg(i18n("Appearance") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (4,'%1')").arg(i18n("Originality") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (5,'%1')").arg(i18n("Ease of Preparation") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (1,'%1')").arg(i18n("Overall")) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (2,'%1')").arg(i18n("Taste") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (3,'%1')").arg(i18n("Appearance") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (4,'%1')").arg(i18n("Originality") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (5,'%1')").arg(i18n("Ease of Preparation") ) );
database->exec( "UPDATE db_info SET ver='0.87',generated_by='Krecipes SVN (20051014)'" );
}
if ( qRound(version*100) < 90 ) {
if ( tqRound(version*100) < 90 ) {
database->exec("UPDATE db_info SET ver='0.9',generated_by='Krecipes 0.9'");
}
if ( qRound(version*100) < 91 ) {
if ( tqRound(version*100) < 91 ) {
database->exec("CREATE index parent_id_index ON categories(parent_id)");
database->exec("UPDATE db_info SET ver='0.91',generated_by='Krecipes SVN (20060526)'");
}
if ( qRound(version*100) < 92 ) {
if ( tqRound(version*100) < 92 ) {
database->transaction();
database->exec( "ALTER TABLE units ADD COLUMN name_abbrev VARCHAR(20) AFTER name");
@ -499,7 +499,7 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.92 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 93 ) {
if ( tqRound(version*100) < 93 ) {
database->transaction();
database->exec( "ALTER TABLE ingredient_list ADD COLUMN substitute_for INTEGER AFTER group_id");
@ -509,7 +509,7 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.93 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 94 ) {
if ( tqRound(version*100) < 94 ) {
database->transaction();
database->exec( "ALTER TABLE units ADD COLUMN type INTEGER NOT NULL DEFAULT 0 AFTER plural_abbrev");
@ -519,7 +519,7 @@ void MySQLRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.94 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 95 ) {
if ( tqRound(version*100) < 95 ) {
database->exec( "DROP TABLE ingredient_weights" );
createTable( "ingredient_weights" );
database->exec( "UPDATE db_info SET ver='0.95',generated_by='Krecipes SVN (20060726)'" );
@ -528,7 +528,7 @@ void MySQLRecipeDB::portOldDatabases( float version )
int MySQLRecipeDB::lastInsertID()
{
QSqlQuery lastInsertID( "SELECT LAST_INSERT_ID();", database );
TQSqlQuery lastInsertID( "SELECT LAST_INSERT_ID();", database );
int id = -1;
if ( lastInsertID.isActive() && lastInsertID.next() )
@ -537,18 +537,18 @@ int MySQLRecipeDB::lastInsertID()
return id;
}
void MySQLRecipeDB::givePermissions( const QString &dbName, const QString &username, const QString &password, const QString &clientHost )
void MySQLRecipeDB::givePermissions( const TQString &dbName, const TQString &username, const TQString &password, const TQString &clientHost )
{
QString command;
TQString command;
if ( !password.isEmpty() )
command = QString( "GRANT ALL ON %1.* TO '%2'@'%3' IDENTIFIED BY '%4';" ).arg( dbName ).arg( username ).arg( clientHost ).arg( password );
command = TQString( "GRANT ALL ON %1.* TO '%2'@'%3' IDENTIFIED BY '%4';" ).arg( dbName ).arg( username ).arg( clientHost ).arg( password );
else
command = QString( "GRANT ALL ON %1.* TO '%2'@'%3';" ).arg( dbName ).arg( username ).arg( clientHost );
command = TQString( "GRANT ALL ON %1.* TO '%2'@'%3';" ).arg( dbName ).arg( username ).arg( clientHost );
kdDebug() << "I'm doing the query to setup permissions\n";
QSqlQuery permissionsToSet( command, database );
TQSqlQuery permissionsToSet( command, database );
}
#include "mysqlrecipedb.moc"

@ -14,14 +14,14 @@
#ifndef MYSQLRECIPEDB_H
#define MYSQLRECIPEDB_H
#define MYSQL_DRIVER "QMYSQL3"
#define MYSQL_DRIVER "TQMYSQL3"
#include "qsqlrecipedb.h"
/**
@author Unai Garro
*/
class MySQLRecipeDB : public QSqlRecipeDB
class MySQLRecipeDB : public TQSqlRecipeDB
{
Q_OBJECT
@ -30,24 +30,24 @@ private:
void createDB( void );
public:
MySQLRecipeDB( const QString &host, const QString &user = QString::null, const QString &pass = QString::null, const QString &DBName = DEFAULT_DB_NAME, int port = 0 );
MySQLRecipeDB( const TQString &host, const TQString &user = TQString::null, const TQString &pass = TQString::null, const TQString &DBName = DEFAULT_DB_NAME, int port = 0 );
~MySQLRecipeDB( void );
int lastInsertID();
void createTable( const QString &tableName );
void givePermissions( const QString &dbName, const QString &username, const QString &password = QString::null, const QString &clientHost = "localhost" );
void createTable( const TQString &tableName );
void givePermissions( const TQString &dbName, const TQString &username, const TQString &password = TQString::null, const TQString &clientHost = "localhost" );
protected:
QString qsqlDriverPlugin() const
TQString qsqlDriverPlugin() const
{
return MYSQL_DRIVER;
}
private:
void portOldDatabases( float version );
QStringList backupCommand() const;
QStringList restoreCommand() const;
TQStringList backupCommand() const;
TQStringList restoreCommand() const;
};

@ -20,10 +20,10 @@
#include <klocale.h>
#include <kconfig.h>
#include <qvariant.h>
#include <ntqvariant.h>
//Note: PostgreSQL's database names are always lowercase
PSqlRecipeDB::PSqlRecipeDB( const QString& host, const QString& user, const QString& pass, const QString& DBname, int port ) : QSqlRecipeDB( host, user, pass, DBname.lower(), port )
PSqlRecipeDB::PSqlRecipeDB( const TQString& host, const TQString& user, const TQString& pass, const TQString& DBname, int port ) : TQSqlRecipeDB( host, user, pass, DBname.lower(), port )
{}
PSqlRecipeDB::~PSqlRecipeDB()
@ -31,13 +31,13 @@ PSqlRecipeDB::~PSqlRecipeDB()
void PSqlRecipeDB::createDB()
{
QString real_db_name = database->databaseName();
TQString real_db_name = database->databaseName();
//we have to be connected to some database in order to create the Krecipes database
//so long as the permissions given are allowed access to "template1', this works
database->setDatabaseName( "template1" );
if ( database->open() ) {
QSqlQuery query( QString( "CREATE DATABASE %1" ).arg( real_db_name ), database );
TQSqlQuery query( TQString( "CREATE DATABASE %1" ).arg( real_db_name ), database );
if ( !query.isActive() )
kdDebug() << "create query failed: " << database->lastError().databaseText() << endl;
@ -49,42 +49,42 @@ void PSqlRecipeDB::createDB()
database->setDatabaseName( real_db_name );
}
QStringList PSqlRecipeDB::backupCommand() const
TQStringList PSqlRecipeDB::backupCommand() const
{
KConfig *config = KGlobal::config();
config->setGroup("Server");
QStringList command;
TQStringList command;
command<<config->readEntry( "PgDumpPath", "pg_dump" )<<"-d"<<database->databaseName()
<<"-U"<<config->readEntry( "Username" );
int port = config->readNumEntry( "Port", 0 );
if ( port > 0 )
command<<"-p"<<QString::number(port);
command<<"-p"<<TQString::number(port);
return command;
}
QStringList PSqlRecipeDB::restoreCommand() const
TQStringList PSqlRecipeDB::restoreCommand() const
{
KConfig *config = KGlobal::config();
config->setGroup("Server");
QStringList command;
TQStringList command;
command<<config->readEntry( "PsqlPath", "psql" )<<database->databaseName()
<<"-U"<<config->readEntry( "Username" );
int port = config->readNumEntry( "Port", 0 );
if ( port > 0 )
command<<"-p"<<QString::number(port);
command<<"-p"<<TQString::number(port);
return command;
}
void PSqlRecipeDB::createTable( const QString &tableName )
void PSqlRecipeDB::createTable( const TQString &tableName )
{
QStringList commands;
TQStringList commands;
if ( tableName == "recipes" )
commands << "CREATE TABLE recipes (id SERIAL NOT NULL PRIMARY KEY,title CHARACTER VARYING, yield_amount FLOAT, yield_amount_offset FLOAT, yield_type_id INTEGER DEFAULT '-1', instructions TEXT, photo TEXT, prep_time TIME, ctime TIMESTAMP, mtime TIMESTAMP, atime TIMESTAMP );";
@ -147,7 +147,7 @@ void PSqlRecipeDB::createTable( const QString &tableName )
else if ( tableName == "db_info" ) {
commands << "CREATE TABLE db_info (ver FLOAT NOT NULL,generated_by CHARACTER VARYING default NULL);";
commands << QString( "INSERT INTO db_info VALUES(%1,'Krecipes %2');" ).arg( latestDBVersion() ).arg( krecipes_version() );
commands << TQString( "INSERT INTO db_info VALUES(%1,'Krecipes %2');" ).arg( latestDBVersion() ).arg( krecipes_version() );
}
else if ( tableName == "ingredient_groups" ) {
commands << "CREATE TABLE ingredient_groups (id SERIAL NOT NULL PRIMARY KEY, name CHARACTER VARYING);";
@ -167,36 +167,36 @@ void PSqlRecipeDB::createTable( const QString &tableName )
else
return ;
QSqlQuery databaseToCreate( QString::null, database );
TQSqlQuery databaseToCreate( TQString::null, database );
// execute the queries
for ( QStringList::const_iterator it = commands.begin(); it != commands.end(); ++it )
for ( TQStringList::const_iterator it = commands.begin(); it != commands.end(); ++it )
databaseToCreate.exec( *it );
}
void PSqlRecipeDB::initializeData()
{
QSqlRecipeDB::initializeData();
TQSqlRecipeDB::initializeData();
QSqlQuery updateSeq( "SELECT setval('units_id_seq',(SELECT COUNT(1) FROM units))", database );
TQSqlQuery updateSeq( "SELECT setval('units_id_seq',(SELECT COUNT(1) FROM units))", database );
updateSeq.exec( "SELECT setval('categories_id_seq',(SELECT COUNT(1) FROM categories))" );
}
void PSqlRecipeDB::portOldDatabases( float version )
{
kdDebug() << "Current database version is..." << version << "\n";
QString command;
TQString command;
if ( qRound(version*10) < 7 ) {
if ( tqRound(version*10) < 7 ) {
//version added
}
if ( qRound(version*100) < 81 ) {
if ( tqRound(version*100) < 81 ) {
database->transaction();
addColumn("CREATE TABLE %1 (recipe_id INTEGER, ingredient_id INTEGER, amount FLOAT, %2 unit_id INTEGER, prep_method_id INTEGER, order_index INTEGER, group_id INTEGER);","amount_offset FLOAT","'0'","ingredient_list",3);
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.exec( "CREATE INDEX ridil_index ON ingredient_list USING BTREE (recipe_id);" );
query.exec( "CREATE INDEX iidil_index ON ingredient_list USING BTREE (ingredient_id);");
@ -206,15 +206,15 @@ void PSqlRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.81 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 82 ) {
if ( tqRound(version*100) < 82 ) {
database->transaction();
//==================add a columns to 'recipes' to allow yield range + yield type
database->exec( "CREATE TABLE recipes_copy (id SERIAL NOT NULL PRIMARY KEY,title CHARACTER VARYING, persons INTEGER, instructions TEXT, photo TEXT, prep_time TIME);" );
QSqlQuery copyQuery = database->exec( "SELECT id,title,persons,instructions,photo,prep_time FROM recipes;" );
TQSqlQuery copyQuery = database->exec( "SELECT id,title,persons,instructions,photo,prep_time FROM recipes;" );
if ( copyQuery.isActive() ) {
while ( copyQuery.next() ) {
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.prepare( "INSERT INTO recipes_copy VALUES (?, ?, ?, ?, ?, ?)" );
query.addBindValue( copyQuery.value( 0 ) );
query.addBindValue( copyQuery.value( 1 ) );
@ -232,7 +232,7 @@ void PSqlRecipeDB::portOldDatabases( float version )
copyQuery = database->exec( "SELECT id,title,persons,instructions,photo,prep_time FROM recipes_copy" );
if ( copyQuery.isActive() ) {
while ( copyQuery.next() ) {
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.prepare( "INSERT INTO recipes VALUES (?, ?, ?, ?, ?, ?, ?, ?)" );
query.addBindValue( copyQuery.value( 0 ) ); //id
query.addBindValue( copyQuery.value( 1 ) ); //title
@ -255,7 +255,7 @@ void PSqlRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.82 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 83 ) {
if ( tqRound(version*100) < 83 ) {
database->transaction();
//====add a id columns to 'ingredient_list' to identify it for the prep method list
@ -263,12 +263,12 @@ void PSqlRecipeDB::portOldDatabases( float version )
database->exec( "CREATE TABLE ingredient_list (id SERIAL NOT NULL PRIMARY KEY, recipe_id INTEGER, ingredient_id INTEGER, amount FLOAT, amount_offset FLOAT, unit_id INTEGER, order_index INTEGER, group_id INTEGER);" );
QSqlQuery copyQuery = database->exec( "SELECT recipe_id,ingredient_id,amount,amount_offset,unit_id,prep_method_id,order_index,group_id FROM ingredient_list_copy" );
TQSqlQuery copyQuery = database->exec( "SELECT recipe_id,ingredient_id,amount,amount_offset,unit_id,prep_method_id,order_index,group_id FROM ingredient_list_copy" );
if ( copyQuery.isActive() ) {
while ( copyQuery.next() ) {
int ing_list_id = getNextInsertID("ingredient_list","id");
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.prepare( "INSERT INTO ingredient_list VALUES (?, ?, ?, ?, ?, ?, ?, ?)" );
query.addBindValue( ing_list_id );
query.addBindValue( copyQuery.value( 0 ) );
@ -305,7 +305,7 @@ void PSqlRecipeDB::portOldDatabases( float version )
}
}
if ( qRound(version*100) < 84 ) {
if ( tqRound(version*100) < 84 ) {
database->transaction();
database->exec( "ALTER TABLE recipes ADD COLUMN ctime TIMESTAMP" );
@ -322,7 +322,7 @@ void PSqlRecipeDB::portOldDatabases( float version )
}
}
if ( qRound(version*100) < 85 ) { //this change altered the photo format, but this backend already used the newer format
if ( tqRound(version*100) < 85 ) { //this change altered the photo format, but this backend already used the newer format
database->transaction();
database->exec( "UPDATE db_info SET ver='0.85',generated_by='Krecipes SVN (20050926)';" );
@ -333,24 +333,24 @@ void PSqlRecipeDB::portOldDatabases( float version )
}
}
if ( qRound(version*100) < 86 ) {
if ( tqRound(version*100) < 86 ) {
database->transaction();
database->exec( "CREATE INDEX gidil_index ON ingredient_list USING BTREE (group_id);" );
QSqlQuery query( "SELECT id,name FROM ingredient_groups ORDER BY name", database );
TQSqlQuery query( "SELECT id,name FROM ingredient_groups ORDER BY name", database );
QString last;
TQString last;
int lastID;
if ( query.isActive() ) {
while ( query.next() ) {
QString name = query.value(1).toString();
TQString name = query.value(1).toString();
int id = query.value(0).toInt();
if ( last == name ) {
QString command = QString("UPDATE ingredient_list SET group_id=%1 WHERE group_id=%2").arg(lastID).arg(id);
TQString command = TQString("UPDATE ingredient_list SET group_id=%1 WHERE group_id=%2").arg(lastID).arg(id);
database->exec(command);
command = QString("DELETE FROM ingredient_groups WHERE id=%1").arg(id);
command = TQString("DELETE FROM ingredient_groups WHERE id=%1").arg(id);
database->exec(command);
}
last = name;
@ -365,50 +365,50 @@ void PSqlRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.86 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 87 ) {
if ( tqRound(version*100) < 87 ) {
//Load this default data so the user knows what rating criteria is
database->exec( QString("INSERT INTO rating_criteria VALUES (1,'%1')").arg(i18n("Overall")) );
database->exec( QString("INSERT INTO rating_criteria VALUES (2,'%1')").arg(i18n("Taste") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (3,'%1')").arg(i18n("Appearance") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (4,'%1')").arg(i18n("Originality") ) );
database->exec( QString("INSERT INTO rating_criteria VALUES (5,'%1')").arg(i18n("Ease of Preparation") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (1,'%1')").arg(i18n("Overall")) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (2,'%1')").arg(i18n("Taste") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (3,'%1')").arg(i18n("Appearance") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (4,'%1')").arg(i18n("Originality") ) );
database->exec( TQString("INSERT INTO rating_criteria VALUES (5,'%1')").arg(i18n("Ease of Preparation") ) );
database->exec( "UPDATE db_info SET ver='0.87',generated_by='Krecipes SVN (20051014)'" );
}
if ( qRound(version*100) < 90 ) {
if ( tqRound(version*100) < 90 ) {
database->exec("UPDATE db_info SET ver='0.9',generated_by='Krecipes 0.9'");
}
if ( qRound(version*100) < 91 ) {
if ( tqRound(version*100) < 91 ) {
database->exec("CREATE index parent_id_index ON categories USING BTREE(parent_id)");
database->exec("UPDATE db_info SET ver='0.91',generated_by='Krecipes SVN (20060526)'");
}
if ( qRound(version*100) < 92 ) {
if ( tqRound(version*100) < 92 ) {
database->transaction();
//==================add a columns to 'units' to allow unit abbreviations
database->exec( "ALTER TABLE units RENAME TO units_copy" );
int nextval = -1;
QSqlQuery getID( "SELECT nextval('units_id_seq')", database );
TQSqlQuery getID( "SELECT nextval('units_id_seq')", database );
if ( getID.isActive() && getID.first() )
nextval = getID.value( 0 ).toInt();
if ( nextval == -1 )
kdDebug() << "Database update failed! Unable to update units sequence." << endl;
database->exec( "CREATE TABLE units (id SERIAL NOT NULL PRIMARY KEY, name CHARACTER VARYING, name_abbrev CHARACTER VARYING, plural CHARACTER VARYING, plural_abbrev CHARACTER VARYING )" );
QSqlQuery copyQuery = database->exec( "SELECT id,name,plural FROM units_copy" );
TQSqlQuery copyQuery = database->exec( "SELECT id,name,plural FROM units_copy" );
if ( copyQuery.isActive() ) {
while ( copyQuery.next() ) {
QSqlQuery query(QString::null,database);
TQSqlQuery query(TQString::null,database);
query.prepare( "INSERT INTO units VALUES(?, ?, ?, ?, ?)" );
query.addBindValue( copyQuery.value( 0 ) );
query.addBindValue( copyQuery.value( 1 ) );
query.addBindValue( QVariant() );
query.addBindValue( TQVariant() );
query.addBindValue( copyQuery.value( 2 ) );
query.addBindValue( QVariant() );
query.addBindValue( TQVariant() );
query.exec();
emit progress();
@ -417,14 +417,14 @@ void PSqlRecipeDB::portOldDatabases( float version )
database->exec( "DROP TABLE units_copy" );
database->exec( "ALTER TABLE units_id_seq1 RENAME TO units_id_seq" );
database->exec( "ALTER SEQUENCE units_id_seq RESTART WITH "+QString::number(nextval) );
database->exec( "ALTER SEQUENCE units_id_seq RESTART WITH "+TQString::number(nextval) );
database->exec("UPDATE db_info SET ver='0.92',generated_by='Krecipes SVN (20060609)'");
if ( !database->commit() )
kdDebug()<<"Update to 0.92 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 93 ) {
if ( tqRound(version*100) < 93 ) {
database->transaction();
database->exec( "ALTER TABLE ingredient_list ADD COLUMN substitute_for INTEGER" );
@ -434,7 +434,7 @@ void PSqlRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.93 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 94 ) {
if ( tqRound(version*100) < 94 ) {
database->transaction();
database->exec( "ALTER TABLE units ADD COLUMN type INTEGER NOT NULL DEFAULT '0'" );
@ -444,56 +444,56 @@ void PSqlRecipeDB::portOldDatabases( float version )
kdDebug()<<"Update to 0.94 failed. Maybe you should try again."<<endl;
}
if ( qRound(version*100) < 95 ) {
if ( tqRound(version*100) < 95 ) {
database->exec( "DROP TABLE ingredient_weights" );
createTable( "ingredient_weights" );
database->exec( "UPDATE db_info SET ver='0.95',generated_by='Krecipes SVN (20060726)'" );
}
}
void PSqlRecipeDB::addColumn( const QString &new_table_sql, const QString &new_col_info, const QString &default_value, const QString &table_name, int col_index )
void PSqlRecipeDB::addColumn( const TQString &new_table_sql, const TQString &new_col_info, const TQString &default_value, const TQString &table_name, int col_index )
{
QString command;
TQString command;
command = QString(new_table_sql).arg(table_name+"_copy").arg(QString::null);
command = TQString(new_table_sql).arg(table_name+"_copy").arg(TQString::null);
kdDebug()<<"calling: "<<command<<endl;
QSqlQuery query( command, database );
TQSqlQuery query( command, database );
command = "SELECT * FROM "+table_name+";";
query.exec( command );
if ( query.isActive() ) {
while ( query.next() ) {
QStringList dataList;
TQStringList dataList;
for ( int i = 0 ;; ++i ) {
QVariant variant = query.value(i);
if ( variant.type() == QVariant::Invalid ) break;
TQVariant variant = query.value(i);
if ( variant.type() == TQVariant::Invalid ) break;
dataList << "'"+variant.toString()+"'";
}
command = "INSERT INTO "+table_name+"_copy VALUES("+dataList.join(",")+");";
kdDebug()<<"calling: "<<command<<endl;
QSqlQuery insert_query( command, database );
TQSqlQuery insert_query( command, database );
emit progress();
}
}
query.exec( "DROP TABLE "+table_name+";" );
query.exec( QString(new_table_sql).arg(table_name).arg(new_col_info+",") );
query.exec( TQString(new_table_sql).arg(table_name).arg(new_col_info+",") );
query.exec( "SELECT * FROM "+table_name+"_copy;" );
if ( query.isActive() ) {
while ( query.next() ) {
QStringList dataList;
TQStringList dataList;
for ( int i = 0 ;; ++i ) {
if ( i == col_index )
dataList << default_value;
QVariant variant = query.value(i);
if ( variant.type() == QVariant::Invalid ) break;
TQVariant variant = query.value(i);
if ( variant.type() == TQVariant::Invalid ) break;
dataList << "'"+variant.toString()+"'";
}
command = "INSERT INTO "+table_name+" VALUES(" +dataList.join(",")+");";
QSqlQuery insert_query( command, database );
TQSqlQuery insert_query( command, database );
kdDebug()<<"calling: "<<command<<endl;
emit progress();
@ -507,10 +507,10 @@ int PSqlRecipeDB::lastInsertID()
return last_insert_id;
}
int PSqlRecipeDB::getNextInsertID( const QString &table, const QString &column )
int PSqlRecipeDB::getNextInsertID( const TQString &table, const TQString &column )
{
QString command = QString( "SELECT nextval('%1_%2_seq');" ).arg( table ).arg( column );
QSqlQuery getID( command, database );
TQString command = TQString( "SELECT nextval('%1_%2_seq');" ).arg( table ).arg( column );
TQSqlQuery getID( command, database );
if ( getID.isActive() && getID.first() ) {
last_insert_id = getID.value( 0 ).toInt();
@ -521,38 +521,38 @@ int PSqlRecipeDB::getNextInsertID( const QString &table, const QString &column )
return last_insert_id;
}
void PSqlRecipeDB::givePermissions( const QString & /*dbName*/, const QString &username, const QString &password, const QString & /*clientHost*/ )
void PSqlRecipeDB::givePermissions( const TQString & /*dbName*/, const TQString &username, const TQString &password, const TQString & /*clientHost*/ )
{
QStringList tables;
TQStringList tables;
tables << "ingredient_info" << "ingredient_list" << "ingredient_properties" << "ingredients" << "recipes" << "unit_list" << "units" << "units_conversion" << "categories" << "category_list" << "authors" << "author_list" << "prep_methods" << "db_info" << "ingredient_groups" << "ingredient_weights" << "prep_method_list" << "yield_types" << "ratings" << "rating_criteria" << "rating_criterion_list";
//we also have to grant permissions on the sequences created
tables << "authors_id_seq" << "categories_id_seq" << "ingredient_properties_id_seq" << "ingredient_weights_id_seq" << "ingredients_id_seq" << "prep_methods_id_seq" << "recipes_id_seq" << "units_id_seq" << "ingredient_groups_id_seq" << "yield_types_id_seq" << "ingredient_list_id_seq" << "ratings_id_seq" << "rating_criteria_id_seq";
QString command;
TQString command;
kdDebug() << "I'm doing the query to create the new user" << endl;
command = "CREATE USER " + username;
if ( !password.isEmpty() )
command.append( "WITH PASSWORD '" + password + "'" );
command.append( ";" );
QSqlQuery permissionsToSet( command, database );
TQSqlQuery permissionsToSet( command, database );
kdDebug() << "I'm doing the query to setup permissions\n";
command = QString( "GRANT ALL ON %1 TO %2;" ).arg( tables.join( "," ) ).arg( username );
command = TQString( "GRANT ALL ON %1 TO %2;" ).arg( tables.join( "," ) ).arg( username );
permissionsToSet.exec( command );
}
void PSqlRecipeDB::empty( void )
{
QSqlRecipeDB::empty();
TQSqlRecipeDB::empty();
QStringList tables;
TQStringList tables;
tables << "authors_id_seq" << "categories_id_seq" << "ingredient_properties_id_seq" << "ingredient_weights_id_seq" << "ingredients_id_seq" << "prep_methods_id_seq" << "recipes_id_seq" << "units_id_seq" << "ingredient_groups_id_seq" << "yield_types_id_seq" << "ingredient_list_id_seq" << "prep_method_list_id_seq" << "ratings_id_seq" << "rating_criteria_id_seq";
QSqlQuery tablesToEmpty( QString::null, database );
for ( QStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) {
QString command = QString( "DELETE FROM %1;" ).arg( *it );
TQSqlQuery tablesToEmpty( TQString::null, database );
for ( TQStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) {
TQString command = TQString( "DELETE FROM %1;" ).arg( *it );