b1
17th May 2009, 06:18
G'Day,
I am trying to write a simple app using Sqlite. (normally use MySql). My problem is that it creates the file "nksalvo.db", says that it is open, but the "create" commands fail saying the driver is not loaded. The "table 1 creation" message return the driver name as QSQLITE so it does appear to be loaded.
I am using Qt 4.5.0 statically compiled, on windows ( at the moment - Linux next )
I am guessing the error is somewhere else, but where?
Any pointers would much appreciated...thanks B1.
int MainWindow::openDatabase()
{
if (dbopen == true )
{
return 0;
}
else
{
// Create connection to database server
nksalvoDB = QSqlDatabase::addDatabase( "QSQLITE" );
nksalvoDB.setDatabaseName( cwdir+"/nksalvo.db" );
if ( !nksalvoDB.open() )
{
QMessageBox::critical( this, "NKSalvo Database Error",
"Could not connect to the database!\n"
"\n"
"Reported error:\n"
+nksalvoDB.lastError().driverText()+"\n"
+nksalvoDB.lastError().databaseText()+"\n"
+nksalvoDB.databaseName()+"\n");
dbopen = false;
return 1;
}
createtableqry.prepare( "CREATE TABLE IF NOT EXISTS serialdata (`port` varchar(10) default NULL,"
"`speed` varchar(6) default NULL,`databits` varchar(4) default NULL,"
"`parity` varchar(5) default NULL, `stopbits` varchar(4) default NULL"
"`id` smallint(2) NOT NULL, PRIMARY KEY (`id`)" );
createtableqry.exec();
if (!createtableqry.isActive() )
{
QMessageBox::critical(this, "Salvo Error", "Table 1 Creation Failed! \n"
"\n"+createtableqry.lastError().text()+"\n"+nksalvoDB.driverName() );
dbopen = false;
return 1;
}
createtableqry.prepare( "CREATE TABLE IF NOT EXIST salvodata (butlabel string, butcolour string, row1 string,"
"row2 string, row3 string, row4 string, row5 string,"
"row6 string, row7 string, row8 string, row9 string,"
"row10 string, id int NOT NULL, PRIMARY KEY (`id`))");
createtableqry.exec();
if (!createtableqry.isActive() )
{
QMessageBox::critical(this, "Salvo Error", "Table 2 Creation Failed! \n"
"\n"+createtableqry.lastError().text()+"\n"+nksalvoDB.driverName());
dbopen = false;
return 1;
}
dbopen = true;
return 0;
}
}
I am trying to write a simple app using Sqlite. (normally use MySql). My problem is that it creates the file "nksalvo.db", says that it is open, but the "create" commands fail saying the driver is not loaded. The "table 1 creation" message return the driver name as QSQLITE so it does appear to be loaded.
I am using Qt 4.5.0 statically compiled, on windows ( at the moment - Linux next )
I am guessing the error is somewhere else, but where?
Any pointers would much appreciated...thanks B1.
int MainWindow::openDatabase()
{
if (dbopen == true )
{
return 0;
}
else
{
// Create connection to database server
nksalvoDB = QSqlDatabase::addDatabase( "QSQLITE" );
nksalvoDB.setDatabaseName( cwdir+"/nksalvo.db" );
if ( !nksalvoDB.open() )
{
QMessageBox::critical( this, "NKSalvo Database Error",
"Could not connect to the database!\n"
"\n"
"Reported error:\n"
+nksalvoDB.lastError().driverText()+"\n"
+nksalvoDB.lastError().databaseText()+"\n"
+nksalvoDB.databaseName()+"\n");
dbopen = false;
return 1;
}
createtableqry.prepare( "CREATE TABLE IF NOT EXISTS serialdata (`port` varchar(10) default NULL,"
"`speed` varchar(6) default NULL,`databits` varchar(4) default NULL,"
"`parity` varchar(5) default NULL, `stopbits` varchar(4) default NULL"
"`id` smallint(2) NOT NULL, PRIMARY KEY (`id`)" );
createtableqry.exec();
if (!createtableqry.isActive() )
{
QMessageBox::critical(this, "Salvo Error", "Table 1 Creation Failed! \n"
"\n"+createtableqry.lastError().text()+"\n"+nksalvoDB.driverName() );
dbopen = false;
return 1;
}
createtableqry.prepare( "CREATE TABLE IF NOT EXIST salvodata (butlabel string, butcolour string, row1 string,"
"row2 string, row3 string, row4 string, row5 string,"
"row6 string, row7 string, row8 string, row9 string,"
"row10 string, id int NOT NULL, PRIMARY KEY (`id`))");
createtableqry.exec();
if (!createtableqry.isActive() )
{
QMessageBox::critical(this, "Salvo Error", "Table 2 Creation Failed! \n"
"\n"+createtableqry.lastError().text()+"\n"+nksalvoDB.driverName());
dbopen = false;
return 1;
}
dbopen = true;
return 0;
}
}