#include <iostream>
#include <ibase.h>
using namespace std;
int main(int argc, char* argv[])
{
isc_db_handle hDb = NULL;
isc_tr_handle hTrn = NULL;
ISC_STATUS_ARRAY status;
char* sql1
= "CREATE DATABASE 'E:\\db\\test.fdb' USER 'SYSDBA' PASSWORD 'masterkey'";
if (isc_dsql_execute_immediate(status, &hDb, &hTrn, 0, sql1, 1, NULL)) {
cerr << "Failed to create dadabase. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_detach_database(status, &hDb)) {
cerr << "Failed to detach database. status="
<< isc_sqlcode(status) << endl;
return 1;
}
char* sql2
= "CREATE TABLE sample1 ( ITEM1 NUMERIC(4), ITEM2 CHAR(4) )";
char* dpb = NULL;
short dpbLen = 0;
isc_expand_dpb(&dpb, &dpbLen, isc_dpb_user_name, "SYSDBA",
isc_dpb_password, "masterkey", NULL);
if (isc_attach_database(status, 0, "E:\\db\\test.fdb", &hDb, dpbLen, dpb)) {
cerr << "Failed to attach dadabase. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_start_transaction(status, &hTrn, 1, &hDb, 0, NULL)) {
cerr << "Failed to start transaction. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_dsql_execute_immediate(status, &hDb, &hTrn, 0, sql2, 1, NULL)) {
cerr << "Failed to create table. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_commit_transaction(status, &hTrn)) {
cerr << "Failed to commit transaction. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_detach_database(status, &hDb)) {
cerr << "Failed to detach database. status="
<< isc_sqlcode(status) << endl;
return 1;
}
return 0;
}