C++ (Qt)#include <QApplication>#include <QSqlDatabase>#include <QFileInfo>#include <QDir>#include <QMessageBox>#include <QTimer> void run(){ QSqlDatabase db = QSqlDatabase::addDatabase("QIBASE", "myconnection1"); if (!db.isValid()) { QMessageBox::information(0, "msg", "fail"); return; } QString path = QFileInfo( QApplication::applicationDirPath(), QString("test.fdb")) .absoluteFilePath(); QString cfg = QLatin1String( "server type=Embedded; auto_commit=True; auto_commit_level=4096; " "connection lifetime=1; ISC_DPB_LC_CTYPE=UTF8; DataBase=\"%1\""); db.setUserName("SYSDBA"); db.setPassword("masterkey"); db.setConnectOptions(cfg.arg(path)); db.setDatabaseName(path); if (!db.open()) { QMessageBox::information(0, "msg", "db open fail"); return; } QMessageBox::information(0, "msg", "ok");} int main(int argc, char **argv){ QApplication app(argc, argv); run(); QTimer::singleShot(0, &app, SLOT(quit())); return app.exec();}
C++ (Qt)#include <iostream>#include <ibase.h> #define ERR_STATUS {res = 1; isc_print_status(status);} isc_db_handle db = NULL;isc_tr_handle trans = NULL;ISC_STATUS_ARRAY status; int main(int argc, char **argv){ int res = 0; std::cout << "start" << std::endl; if (isc_attach_database(status, 0, "test.fdb", &db, 0, NULL)) { isc_print_status(status); return 1; } if (isc_start_transaction(status, &trans, 1, &db, 0, NULL)) ERR_STATUS if (isc_dsql_execute_immediate(status, &db, &trans, 0, "CREATE TABLE TEST(id INT)", 1, NULL)) ERR_STATUS if (isc_commit_transaction(status, &trans)) ERR_STATUS if (isc_detach_database(status, &db)) ERR_STATUS std::cout << "end" << std::endl; return res;}