#include <QtGui/QApplication>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
int main(int argc, char *argv[])
{
db.setDatabaseName("test.db");
db.open();
QSqlQuery query
= db.
exec("CREATE TABLE vars " "(id integer primary key,"
"name VARCHAR( 250 ),"
"value VARCHAR( 250 ))");
if(!err.text().size() > 1)
QMessageBox::information(0,
"Error creating Database",err.
text());
query = db.exec("INSERT INTO `vars` ( `name` , `value` ) VALUES ( 'testvar', 'testval');");
err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,
"Error inserting to Database",err.
text());
query = db.exec("SELECT * from vars;");
err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,
"Error inserting to Database",err.
text());
if(!query.isValid()) {
QMessageBox::information(0,
"SELECT query not valid!",err.
text());
}
if(!query.size()>0)
QMessageBox::information(0,
"SELECT result",
"At least one result read!");
else
QMessageBox::information(0,
"SELECT failed",
"Select failed!");
return a.exec();
}
#include <QtGui/QApplication>
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
db.open();
QSqlQuery query = db.exec("CREATE TABLE vars "
"(id integer primary key,"
"name VARCHAR( 250 ),"
"value VARCHAR( 250 ))");
QSqlError err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,"Error creating Database",err.text());
query = db.exec("INSERT INTO `vars` ( `name` , `value` ) VALUES ( 'testvar', 'testval');");
err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,"Error inserting to Database",err.text());
query = db.exec("SELECT * from vars;");
err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,"Error inserting to Database",err.text());
if(!query.isValid()) {
QMessageBox::information(0,"SELECT query not valid!",err.text());
}
if(!query.size()>0)
QMessageBox::information(0,"SELECT result","At least one result read!");
else
QMessageBox::information(0,"SELECT failed","Select failed!");
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks