Skip to content

Instantly share code, notes, and snippets.

@olegwtf
Created September 2, 2011 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegwtf/1188372 to your computer and use it in GitHub Desktop.
Save olegwtf/1188372 to your computer and use it in GitHub Desktop.
test firebird + qt
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <QSqlError>
#include <QVariant>
int main()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QIBASE");
if (!db.isValid()) {
qDebug() << "Invalid db";
return 1;
}
db.setHostName("localhost");
db.setDatabaseName("/tmp/test.fdb");
db.setUserName("SYSDBA");
db.setPassword("qolentfireho");
if (!db.open()) {
qDebug() << "Connection error: " << db.lastError().text();
return 1;
}
QSqlQuery query;
query.exec("SELECT id, name FROM table_name");
if (!query.isActive()) {
qDebug() << "Query error: " << query.lastError().text();
return 1;
}
while (query.next()) {
qint64 id = query.value(0).toLongLong();
QString name = query.value(1).toString();
qDebug() << "id=" << id << "; name=" << name;
}
db.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment