Firebird .Net Data Provider メモ

ADO .NET Data Providerを用いてFireBirdのデータベースを作成し,テーブルを定義する.サンプルコード.

//FireBird & FireBird .NET Data Provider
FireBird Version 1.5
FireBird .NET Data Provider Version 1.5.3
//開発環境
Visual Studio .NET 2003
.NET Framework 1.1

//FbConnection, FbTransaction, FbCommand
using namespace FirebirdSql::Data::Firebird;

String *dbHostName = S"localhost";
String *dbFilaPath = S"D:/test_dir/TEST_ADO.FDB";
String *userName = S"SYSDBA";
String *password = S"masterkey";

try
{
	////////////////////////////////////////////////////////////////
	//データベース作成.
	Hashtable *newDBParam = new Hashtable();
	newDBParam->Item[S"DataSource"] = dbHostName;
	newDBParam->Item[S"Database"] = dbFilaPath;

	newDBParam->Item[S"User"] = userName;
	newDBParam->Item[S"Password"] = password;

	newDBParam->Item[S"Port"] = __box(3050);
	newDBParam->Item[S"Charset"] = S"SJIS_0208";
	newDBParam->Item[S"PageSize"] = __box(8192);

	FbConnection::CreateDatabase(newDBParam);

	////////////////////////////////////////////////////////////////
	//テーブル作成.
	FbConnection *fbConnection1 = new FbConnection();
	FbTransaction *fbTransaction1;
	FbCommand *fbCommand1;

	//接続文字列.
	String *params[] = {dbHostName, dbFilaPath, userName, password};
	String *connectionString = String::Format(S"DataSource={0};Database={1};User={2};Password={3};Port=3050;Charset=SJIS_0208", params);

	fbConnection1->ConnectionString = connectionString;
	fbConnection1->Open();

	fbTransaction1 = fbConnection1->BeginTransaction();

	//コマンド実行."CREATE TABLE"
	fbCommand1 = fbConnection1->CreateCommand();
	fbCommand1->Transaction = fbTransaction1;
	fbCommand1->CommandType = CommandType::Text;
	fbCommand1->CommandText = S"CREATE TABLE WORD_LIST (ID INTEGER NOT NULL PRIMARY KEY, HYOKI VARCHAR(128) NOT NULL, YOMI VARCHAR(128) NOT NULL, HINSHI VARCHAR(32) NOT NULL);";
	fbCommand1->ExecuteNonQuery();

	fbTransaction1->Commit();
	fbConnection1->Close();
}
catch(FbException *e)
{
	MessageBox::Show(String::Format(S"データベース操作にて例外が発生しました.\r\n{0}", e->Message));
}
catch(Exception *e)
{
	MessageBox::Show(String::Format(S"データベース操作にて例外が発生しました.\r\n{0}\r\n{1}", e->GetType()->FullName, e->Message));
}
catch(...)
{
	MessageBox::Show(S"その他の例外が発生しました.");
}