QSQLITE database changes not showing up in database
I have two databases im working with. They are both for different form interfaces. One works but the other database doesn't show any changes when I make an update and I get no errors in my code so it's quite difficult to troubleshoot. Here is a listing of my db setup and where I update in both:
The working db:
Code:
#include <QtSql>
#define Path_to_DB "/media/.../dbpath"
.....
{
ui->setupUi(this);
db.setDatabaseName(Path_to_DB);
if(checkFile.isFile())
{
if(db.open())
{
qDebug() << "Connected to database file";
}
}else{
qDebug() << "Database file not found";
}
}
adminDialog::~adminDialog()
{
delete ui;
qDebug() << "Closing connection to Database file on exit...";
db.close();
}
double count;
void adminDialog::on_pushButton_3_clicked()
{
count++;
QString str
= ui
->lineEdit
->text
();
ui->count->display(count);
qDebug() << str;
if(!db.isOpen()){
qDebug() << "No connection to db";
return;
}
QString qry
= QString("INSERT INTO customer (name, size1, size2, size3) VALUES ('%1', NULL, NULL, NULL)").
arg(str
);
query.prepare(qry);
if(query.exec())
{
qDebug() << "Update Complete";
}
else
{
qDebug() << query.lastError();
}
}
db thats not working:
Code:
#include <QtSql>
#define Path_to_DB "/media/.../db2path"
......
ui->setupUi(this);
db2.setDatabaseName(Path_to_DB);
if(checkFile.isFile())
{
if(db2.open())
{
qDebug() << "Connected to database file";
}
}else{
qDebug() << "Database file not found";
}
}
void demo::on_pushButton_clicked()
{
if(!db2.isOpen()){
qDebug() << "No connection to db";
return;
}
........
switch (md_pref)
{
case 1:
query.prepare("UPDATE customer SET size1 = size1 + 1 WHERE name = 'Gary' ");
if(query.exec())
{
qDebug() << "Updated Gary";
}
else
{
qDebug() << query.lastError();
}
break;
.............
}
I'm working on a Linux Kubuntu 12.10 system. I appreciate all help on this thanks.
Re: QSQLITE database changes not showing up in database
What does QSqlQuery::exec() return? What does prepare() return?
Re: QSQLITE database changes not showing up in database
Quote:
Originally Posted by
wysota
Well I get no errors when running just like in the working version. The qDebug outputs updated but nothing actually happens.
Re: QSQLITE database changes not showing up in database
Re: QSQLITE database changes not showing up in database
Quote:
Originally Posted by
wysota
Returns the correct number of rows affected... :confused:
After doing some manual debugging i've seen the following in application output when I change between the windows that connect to the different databases.
Quote:
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Looks like its using the same connection for the two dbs not sure what to actually change though because when I tried changing something it gave me an error saying " Driver not loaded"....
Re: QSQLITE database changes not showing up in database
If you want help then provide something we can compile and test. Otherwise you're on your own.
Re: QSQLITE database changes not showing up in database
It's working now! I hadn't set the default db value that was being updated to 0 like I did in the one that's working lol...smh
P.S. Found that out while I was preparing to upload all my code.