TSQLite3Connection/ja
English · Español · Français · Polski · 日本語
Note: TSQLite3Connection を使う代わりに、プロキシライクな TSQLConnector/ja を使うことで、より一般的なデータベースアプリケーションを作ることができます。
TSQLite3Connection
は SQLite/jaを使うためのデータベース接続コンポーネントです。これらのコンポーネントは、Component Palette/ja の SQLdb tab/ja にあります。
TSQLite3connection は FCL (LCLではなく) の 非ビジュアルコンポーネントであり、Lazarus の GUI と同様に、(例えば) ObjectPascal やコンソールアプリケーションに用いることができます。残念ながら TSQLite3Connection についての FCL ドキュメントはありません。しかし、そのインターフェイスは親クラスの( TSQLConnection/ja )とほぼ同じです。SQLite は組み込みのまたは非サーバー型のデータベースであるので、 その利用にあたっては、.host や .username、また .password の設定は不要です。サンプルとして、ObjectPascal のプログラムではどのように利用するかを以下に示します。 Lazarus GUI より用いる場合は、同様な設定を オブジェクトインスペクターから行えます。
(訳注;以下を実行する前に SQLite をインストールする必要がありますが、その際に、Lazarus と同じcpu向け(つまり、32bit(x86)用か64bit用か) のSQLiteを用いる必要があります。※たぶん) (訳注;2度目の実行時には、「TBLNAMESのテーブルは作成済み」というエラーメッセージが表示されると思います。)
program BasicDBase;
{$mode objfpc} {$ifdef mswindows}{$apptype console}{$endif}
uses
sqldb, sqlite3conn;
var
Connect : TSQLite3Connection;
Trans : TSQLTransaction;
begin
Connect := TSQLite3Connection.Create(nil);
Trans := TSQLTransaction.Create(Connect);
Connect.Transaction := Trans;
Connect.DatabaseName := 'test_dbase';
Trans.StartTransaction; // データベースへの接続を行います。SQLite をインストールしていない場合、EInOutError が起きます。
Connect.ExecuteDirect('create table TBLNAMES (ID integer Primary Key, NAME varchar(40));');
Trans.Commit;
Trans.Free;
Connect.Free;
end.ExecuteDirect() プロシージャは SQLコールに対して限定的なものであるため、実際のアプリケーションでは、おそらく TSQLQuery のようなものが必要となるでしょう。 また、上記デモはエラーチェックをしていないことを念頭においてください。
関連情報
From the Free Pascal wiki, page "TSQLite3Connection/ja", as it stood on 2024-03-31 after a change by Ariben, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
