duave
3rd April 2011, 22:53
Hey guys,
I'm having this trouble in QT - I was wondering if somebody could explain to me what's going on.
I'm using this code:
timingDatabase = QSqlDatabase::addDatabase("QSQLITE", "timing");
timingDatabase.setDatabaseName("../config.db");
if (!timingDatabase.open())
{
qDebug() << timingDatabase.lastError();
}
if (!timingDatabase.tables().contains("timing"))
ConstructTimeSettingsTable();
and also
void TimingSettings::ConstructTimeSettingsTable()
{
qDebug() << timingDatabase.tables();
QSqlQuery timeQuery;
timeQuery.exec("CREATE TABLE timing ("
"line1 STRING, "
"line2 STRING, "
"line3 STRING"
");");
qDebug() << timeQuery.lastError();
qDebug() << "Construct function entered.";
}
If I am correct - my program should run the Construct...() if the timing table does not exist (i.e. the first time the program is ran).. However, that is not the case - this is the output I am getting from my qDebug everytime I run the program:
()
QSqlError(1, "Unable to execute statement", "table timing already exists")
Construct function entered.
(1) the first "()" is what timingDatabase.tables() - as in there are no tables in the database, am I right?
(2) if the timingDatabase.tables() is NULL, why is the timingQuery.exec unable to run because the table already exists..?
(3) I've also written debugging code to try to write to and from the database - but the code does not do anything.
If you guys could point me in the right direction of what is wrong with my code, it would be much appreciated.
I'm having this trouble in QT - I was wondering if somebody could explain to me what's going on.
I'm using this code:
timingDatabase = QSqlDatabase::addDatabase("QSQLITE", "timing");
timingDatabase.setDatabaseName("../config.db");
if (!timingDatabase.open())
{
qDebug() << timingDatabase.lastError();
}
if (!timingDatabase.tables().contains("timing"))
ConstructTimeSettingsTable();
and also
void TimingSettings::ConstructTimeSettingsTable()
{
qDebug() << timingDatabase.tables();
QSqlQuery timeQuery;
timeQuery.exec("CREATE TABLE timing ("
"line1 STRING, "
"line2 STRING, "
"line3 STRING"
");");
qDebug() << timeQuery.lastError();
qDebug() << "Construct function entered.";
}
If I am correct - my program should run the Construct...() if the timing table does not exist (i.e. the first time the program is ran).. However, that is not the case - this is the output I am getting from my qDebug everytime I run the program:
()
QSqlError(1, "Unable to execute statement", "table timing already exists")
Construct function entered.
(1) the first "()" is what timingDatabase.tables() - as in there are no tables in the database, am I right?
(2) if the timingDatabase.tables() is NULL, why is the timingQuery.exec unable to run because the table already exists..?
(3) I've also written debugging code to try to write to and from the database - but the code does not do anything.
If you guys could point me in the right direction of what is wrong with my code, it would be much appreciated.