00001 #include <QApplication>
00002 #include <QtSql>
00003
00004 #include <iostream>
00005 using namespace std;
00006
00007
00008 #define HOST "127.0.0.1"
00009 #define DB "xe"
00010 #define PORT 1521
00011 #define USER "testbed"
00012 #define PASSWD "secret"
00013
00014 int main(int argc, char *argv[])
00015 {
00016 QApplication app(argc, argv);
00017
00018 QSqlDatabase qDB = QSqlDatabase::addDatabase("QOpenOCCI");
00019
00020 qDB.setHostName(HOST);
00021 qDB.setDatabaseName(DB);
00022 qDB.setPort(PORT);
00023 qDB.setUserName(USER);
00024 qDB.setPassword(PASSWD);
00025
00026
00027 qDB.setConnectOptions("Prefetch_Memory=5242880;Prefetch_Rows=250");
00028
00029 if (qDB.open() == FALSE) {
00030 cerr << "Error: opening DB failed because " << qDB.lastError().text().toStdString() << endl;
00031 return -1;
00032 }
00033
00034 QSqlQuery query(qDB);
00035
00036 if (query.exec("select * from user_tables") == FALSE) {
00037 cerr << "Error: query failed because " << query.lastError().text().toStdString() << endl;
00038 return -1;
00039 }
00040
00041 QSqlRecord rec = query.record();
00042
00043 cout << "Fields: ";
00044 for (int c = 0; c < rec.count(); c++) {
00045 cout << rec.fieldName(c).toStdString() << " ";
00046 }
00047 cout << "\n\n";
00048
00049 while (query.next()) {
00050 for (int c = 0; c < rec.count(); c++) {
00051 cout << query.value(c).toString().toStdString() << " ";
00052 }
00053 cout << endl;
00054
00055 }
00056
00057 return 0;
00058 }