#include <QDebug>
#include <QtSql>
int main(int argc, char *argv[])
{
// db.setHostName("localhost");
// db.setDatabaseName("data.db");
db.setDatabaseName(":memory:");
if (!db.open()) {
qWarning("Can't open database");
} else {
query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
query.exec("insert into person values(101, 'Danny', 'Young')");
query.exec("insert into person values(102, 'Christine', 'Holand')");
query.exec("insert into person values(103, 'Lars', 'Gordon')");
query.exec("insert into person values(104, 'Roberto', 'Robitaille')");
query.exec("insert into person values(105, 'Maria', 'Papadopoulos')");
select.exec("select * from person");
qDebug() << select.record().value(1).toString();
qDebug() << db.lastError();
}
Principal w;
w.show();
return a.exec();
}
#include <QDebug>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
// db.setHostName("localhost");
// db.setDatabaseName("data.db");
db.setDatabaseName(":memory:");
if (!db.open()) {
qWarning("Can't open database");
} else {
QSqlQuery query;
query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
query.exec("insert into person values(101, 'Danny', 'Young')");
query.exec("insert into person values(102, 'Christine', 'Holand')");
query.exec("insert into person values(103, 'Lars', 'Gordon')");
query.exec("insert into person values(104, 'Roberto', 'Robitaille')");
query.exec("insert into person values(105, 'Maria', 'Papadopoulos')");
QSqlQuery select;
select.exec("select * from person");
qDebug() << select.record().value(1).toString();
qDebug() << db.lastError();
qDebug() << QSqlDatabase::drivers();[/INDENT]
}
Principal w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks