Cyrebo
14th April 2013, 17:23
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:
#include <QtSql>
#define Path_to_DB "/media/.../dbpath"
.....
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(Path_to_DB);
QFileInfo checkFile(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;
}
QSqlQuery query;
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:
#include <QtSql>
#define Path_to_DB "/media/.../db2path"
......
ui->setupUi(this);
db2 = QSqlDatabase::addDatabase("QSQLITE");
db2.setDatabaseName(Path_to_DB);
QFileInfo checkFile(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;
}
........
QSqlQuery query;
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.
The working db:
#include <QtSql>
#define Path_to_DB "/media/.../dbpath"
.....
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(Path_to_DB);
QFileInfo checkFile(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;
}
QSqlQuery query;
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:
#include <QtSql>
#define Path_to_DB "/media/.../db2path"
......
ui->setupUi(this);
db2 = QSqlDatabase::addDatabase("QSQLITE");
db2.setDatabaseName(Path_to_DB);
QFileInfo checkFile(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;
}
........
QSqlQuery query;
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.