Here is my database problem, I have a variable database which is a sqlite implementation of a QSQLDatabase object.
I dont know why but I am able to create the file but I the function database->table() returns an empty QStringList
right after fulling it. I tested and I am able to get the lastInsertID using the same object... it is the
database->table() function that does not gives me what I needed...
Here is a part of the code, the important lines are the last ten...
QStringList tables;
tables << "ingredient_info" << "ingredient_list" << "ingredient_properties" << "ingredient_weights" << "ingredients" << "recipes" << "unit_list" << "units" << "units_conversion" << "categories" << "category_list" << "authors" << "author_list" << "db_info" << "prep_methods" << "ingredient_groups" << "yield_types" << "prep_method_list" << "ratings" << "rating_criteria" << "rating_criterion_list";
QStringList existingTableList = database->tables();
for ( QStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) {
bool found = false;
for ( QStringList::Iterator ex_it = existingTableList.begin(); ( ( ex_it != existingTableList.end() ) && ( !found ) ); ++ex_it ) {
found = ( *ex_it == *it );
}
if ( !found ) {
kDebug() << "Recreating missing table: " << *it << "\n";
createTable( *it );
}
}
QSqlQuery query("SELECT lastInsertID()",*database);
if ( query.isActive() && query.first() )
kDebug() << "Test 1 :" << query.value(0).toInt() << endl;
QStringList newTableList = database->tables();
if ( newTableList.isEmpty() ){
kDebug() << "Test 2 :" << endl;
return false;
}
Here is the result :
krecipes(11363) QSqlRecipeDB::connect: "Définition des paramètres. Appel de « db->open() »"
krecipes(11363) QSQLiteDB::executeQuery: SQLite error: no such table: db_info
(Query: "SELECT ver FROM db_info" )
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredient_info"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredient_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredient_properties"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredient_weights"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredients"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "recipes"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "unit_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "units"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "units_conversion"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "categories"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "category_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "authors"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "author_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "db_info"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "prep_methods"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ingredient_groups"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "yield_types"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "prep_method_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "ratings"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "rating_criteria"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Recreating missing table: "rating_criterion_list"
krecipes(11363) QSqlRecipeDB::checkIntegrity: Test 1 : 1
krecipes(11363) QSqlRecipeDB::checkIntegrity: Test 2 :
krecipes(11363): "Impossible d'ouvrir la base de données" . "Arrêt"