これは、Firebirdインストールディレクトリ(C:\ Program Files \ Firebird \ Firebird_2_5 \ examples)の一部であるコードサンプルに触発された私のソースコードサンプルです。
AnsiString db_path = MainForm->exeFilePath + "\\results.fdb"; // C:\Projects\DBX\bin\results.fdb
if (FileExists(db_path))
{
return;
}
HMODULE dll = LoadLibrary(L"fbclient.dll");
if (dll == NULL)
{
throw Exception(L"Failed to load Firebird client library FBCLIENT.DLL!\r\nApplication will exit now.");
}
Pisc_dsql_execute_immediate pisc_dsql_execute_immediate = (Pisc_dsql_execute_immediate)GetProcAddress(dll, "isc_dsql_execute_immediate");
if (pisc_dsql_execute_immediate == NULL)
{
throw Exception(L"Failed to load 'isc_dsql_execute_immediate' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_commit_transaction pisc_commit_transaction = (Pisc_commit_transaction)GetProcAddress(dll, "isc_commit_transaction");
if (pisc_commit_transaction == NULL)
{
throw Exception(L"Failed to load 'isc_commit_transaction' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_detach_database pisc_detach_database = (Pisc_detach_database)GetProcAddress(dll, "isc_detach_database");
if (pisc_detach_database == NULL)
{
throw Exception(L"Failed to load 'isc_detach_database' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
Pisc_sqlcode pisc_sqlcode = (Pisc_sqlcode)GetProcAddress(dll, "isc_sqlcode");
if (pisc_sqlcode == NULL)
{
throw Exception(L"Failed to load 'isc_sqlcode' entry point in FBCLIENT.DLL. It seems like Firebird installation is corrupted. "
"Contact system administrator.\r\nApplication will exit now.");
}
ISC_STATUS_ARRAY status; /* status vector */
isc_db_handle newdb = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
AnsiString create_db;
create_db.printf("CREATE DATABASE '%s'", db_path.c_str());
long sqlcode;
UnicodeString msg;
if (pisc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db.c_str(), 1, NULL))
{
// ERROR OCCURRES HERE
sqlcode = pisc_sqlcode(status);
msg.printf(L"Operation 'CREATE DATABASE' failed with sqlcode %ld.\r\nApplication will exit now.", sqlcode);
throw Exception(msg.c_str());
}
pisc_commit_transaction(status, &trans);
pisc_detach_database(status, &newdb);
FreeLibrary(dll);
dll = NULL;
データベースの作成がSQLコード-902で失敗しています。ディレクトリ「C:\ Projects \ DBX \ bin \」が存在し、「results.fdb」という名前のファイルが含まれていません。エラー動作の理由と、それを回避するにはどうすればよいですか?Firebird APIの詳細な説明はどこかにありますか?