#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* 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;
}
isc_stmt_handle hStmt = NULL;
char* sql = "INSERT INTO sample1 VALUES ( 1, 'item' )";
if (isc_dsql_allocate_statement(status, &hDb, &hStmt)) {
cerr << "Failed to allocate statement. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_dsql_prepare(status, &hTrn, &hStmt, 0, sql, 1, NULL)) {
cerr << "Failed to prepare statement. status="
<< isc_sqlcode(status) << endl;
return 1;
}
if (isc_dsql_execute(status, &hTrn, &hStmt, 1, NULL)) {
cerr << "Failed to execute statement. 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;
}
isc_dsql_free_statement(status, &hStmt, DSQL_close);
if (isc_detach_database(status, &hDb)) {
cerr << "Failed to detach database. status="
<< isc_sqlcode(status) << endl;
return 1;
}
return 0;
}