int MainWindow::openDatabase()
{
if (dbopen == true )
{
return 0;
}
else
{
// Create connection to database server
nksalvoDB.setDatabaseName( cwdir+"/nksalvo.db" );
if ( !nksalvoDB.open() )
{
"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;
}
}
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;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks