Created
September 2, 2011 10:54
-
-
Save olegwtf/1188372 to your computer and use it in GitHub Desktop.
test firebird + qt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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