Difference between revisions of "SQLite/ja"

From Free Pascal wiki
Jump to navigationJump to search
Line 55: Line 55:
 
これらの手順は、特にSQLiteデータベースのSQLDBコンポーネント、特にTSQLite3Connectionの利用に焦点を当てている。SQLDBコンポーネントやそれらの使用方法についてより包括的に理解するには、[[SqlDBHowto|SqlDBHowto/ja]]を参照のこと。これには、LazarusのSQLDBコンポーネントに関する一般的な概要や有用な情報が含まれている。
 
これらの手順は、特にSQLiteデータベースのSQLDBコンポーネント、特にTSQLite3Connectionの利用に焦点を当てている。SQLDBコンポーネントやそれらの使用方法についてより包括的に理解するには、[[SqlDBHowto|SqlDBHowto/ja]]を参照のこと。これには、LazarusのSQLDBコンポーネントに関する一般的な概要や有用な情報が含まれている。
  
[[SQLdb_Tutorial1]]では、SQLite/SQLDB(およびFirebird/SQLDB、PostgreSQL/SQLDBなど、SQLDBがサポートするほとんどのRDBMS)向けに書かれたGUIデータベース対応プログラムのチュートリアルを見ることができる。
+
[[SQLdb_Tutorial1/ja]]では、SQLite/SQLDB(およびFirebird/SQLDB、PostgreSQL/SQLDBなど、SQLDBがサポートするほとんどのRDBMS)向けに書かれたGUIデータベース対応プログラムのチュートリアルを見ることができる。
  
 
LazarusのSQLdbタブから3つのコンポーネントの組み合わせを使用する: TSQLite3Connection、TSQLTransaction、TSQLQueryである。TSQLQueryはTDatasetとして機能し、最も単純な場合にはテーブルの1つを表します。単純化のために、既存のSQLiteデータベースファイルがすでに存在しており、新しいものを作成する必要がないことを確認してください。
 
LazarusのSQLdbタブから3つのコンポーネントの組み合わせを使用する: TSQLite3Connection、TSQLTransaction、TSQLQueryである。TSQLQueryはTDatasetとして機能し、最も単純な場合にはテーブルの1つを表します。単純化のために、既存のSQLiteデータベースファイルがすでに存在しており、新しいものを作成する必要がないことを確認してください。

Revision as of 12:52, 26 March 2024

English (en) español (es) français (fr) 日本語 (ja) polski (pl) русский (ru) 中文(中国大陆)‎ (zh_CN)

Databases portal

References:

Tutorials/practical articles:

Databases

Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos

SQLite と FPC/Lazarus によるサポートについて

SQLiteは、FPCとLazarusアプリケーションで使用できる組み込み(非サーバー)の単一ユーザーデータベースである。さまざまなドライバーを使用して、FPC/LazarusプログラムからSQLiteにアクセスできる。すべてのドライバーは、動作するために実行可能ディレクトリ(プロジェクトディレクトリまたはLazarusプロジェクト設定に依存する)にSQLiteライブラリ/dllが必要である(および実行可能ファイルと一緒に配布される)。

Win64: FPC/Lazarus Win64に関しては、特定のFPC/Lazarus Win64バージョンを使用しないようにすることに関する警告がある。

SQLite への直接アクセス

LiteDAC(SQLite Data Access Components)は、Lazarus(およびFree Pascal)からWindows、Mac OS X、iOS、Android、Linux、FreeBSDの32ビットおよび64ビットプラットフォームに対して、SQLiteへのネイティブ接続を提供するコンポーネントのライブラリである。LiteDACは、プログラマーが追加のライブラリをデプロイすることなく、真にクロスプラットフォームなデスクトップおよびモバイルSQLiteデータベースアプリケーションを開発できるように設計されている。

商業的な製品のトライアルバージョンを以下でダウンロードできる: Lazarus components

ビルトインの SQLDB

FPC/Lazarusには、組み込みのSQLDBコンポーネントが含まれており、これにはSQLiteデータベースへのサポート(TSQLite3Connection/ja)が含まれている。これはComponent Palette/jaSQLdb tab/jaからアクセスでき、例えばTDBGrid/jaなどのデータベースコンポーネントを使用したGUIを作成することができる。SQLDBを使用する利点は、プログラムをあまり変更することなく、FirebirdやPostgreSQLなどの異なるデータベースに簡単に変更できる。

詳細は以下を参照のこと

Spatialiteサポート

Spatialiteは、SQLiteにGIS(地理情報システム)機能を追加したもので、SQLDB内から使用することができる。詳細については、Spatialiteを参照のこと。

SQLiteの暗号化のサポート

最近のFree Pascal Compiler(FPC)のバージョンでは(2012年3月に実装された)、SQLDBはSQLite3の拡張バージョンのいくつかをサポートしており、これによりSQLiteデータベースファイルをAESアルゴリズムを使用して暗号化することができる。暗号化キーを設定するには、パスワードプロパティを使用する。

Examples:

  • SQLCipher: オープンソース、例えば、Windows用バイナリは無料ではない(自身でコンパイルする必要がある)
  • System.Data.SQLite: オープンソース、Windows (32, 64, CE) バイナリが利用できる。コンパイルされたバイナリの1つをダウンロードし、SQLite.Interop.dllをsqlite3.dllにリネームする(もし静的にリンクしているのであれば、System.Data.SQLite.DLLをsqlite3.dllにリネームする必要がある)
  • wxSQLite3: オープンソース、Linuxに対するいくつかのバイナリが利用できる(例えば: https://launchpad.net/ubuntu/oneiric/+package/libwxsqlite3-2.8-0)

sqlite3backup

sqlite3backupは、FPCに提供されているユニットであり、Lazarusには含まれていないが、プログラムで使用することができる。これは、SQLite3のバックアップ/リストア機能を提供する。sqlite3backupは、SQLDBのsqlite3connを使用する。

Zeos

Zeos

SQLitePass

SqlitePass components. Status: unknown.

TSQLite3Dataset と TSQLiteDataset

TSQLiteDataset(sqlitedsユニット)およびTSQLite3Dataset(sqlite3dsユニット)パッケージも提供されてる。APIリファレンス、チュートリアルに関しては使用法は以下を参照のこと sqlite4fpc homepage

TSQLiteDatasetとTSQLite3Datasetは、それぞれ2.8.xおよび3.x.xのSQLiteデータベースにアクセスする、TDataSetの派生クラスである。新しいプロジェクトでは、SQLite 3.xが現在のバージョンであるため、TSQLite3Datasetを使用することが一般的である。

他のFPC/LazarusのSQLiteドライバやアクセス方法と比較した場合の主な利点と欠点は次のとおりである:

利点:

  • 柔軟性: プログラマーはSQL言語を使用するかどうかを選択できる。これにより、シンプルなテーブルレイアウトやSQL/sqliteで許可されている任意の複雑なレイアウトで作業できる。

欠点:

  • 他のデータベースに変更する際、SQLDBやZeosコンポーネントを使用する場合よりも、変更がより困難になる。
Light bulb  Note: 上記の情報から、多くのユーザーはSQLDBやZeosを利用することが一般的である。これらのツールを利用することで、SQLiteデータベースへの簡単な接続や操作が可能になる。

SQLiteでSQLdbコンポーネントを使用する

これらの手順は、特にSQLiteデータベースのSQLDBコンポーネント、特にTSQLite3Connectionの利用に焦点を当てている。SQLDBコンポーネントやそれらの使用方法についてより包括的に理解するには、SqlDBHowto/jaを参照のこと。これには、LazarusのSQLDBコンポーネントに関する一般的な概要や有用な情報が含まれている。

SQLdb_Tutorial1/jaでは、SQLite/SQLDB(およびFirebird/SQLDB、PostgreSQL/SQLDBなど、SQLDBがサポートするほとんどのRDBMS)向けに書かれたGUIデータベース対応プログラムのチュートリアルを見ることができる。

LazarusのSQLdbタブから3つのコンポーネントの組み合わせを使用する: TSQLite3Connection、TSQLTransaction、TSQLQueryである。TSQLQueryはTDatasetとして機能し、最も単純な場合にはテーブルの1つを表します。単純化のために、既存のSQLiteデータベースファイルがすでに存在しており、新しいものを作成する必要がないことを確認してください。 TSQLite3Connectionは、自分で宣言したい場合やFreePascalで作業している場合は、sqlite3connユニットで見つけることができる。

通常通り、これらの3つのコンポーネントは互いに接続される。TSQLQueryでは、DatabaseとTransactionのプロパティを設定する。TSQLTransactionでは、Databaseのプロパティを設定する。TransactionとConnectionのコンポーネントではあまりすることはない。興味深いことのほとんどは、TSQLQueryで行われます。以下のようにコンポーネントを設定する:

TSQLite3Connection:

  • DatabaseName: このプロパティをSQLiteファイルのファイル名(絶対パス!)に設定します。残念ながら、単純に相対パスを使用してデザイン時とランタイム時で変更せずに動作する方法はない。***これはまだ真実か?ポストビルドのシェルスクリプトでdbファイルを単にコピーするか、シンボリックリンクを作成できない?***。デザイン時に含まれている内容に関係なく、常に正しいファイルへのパスがアプリケーション起動時にプログラムによって設定されていることを確認する必要がある。

注意: フルライブラリパスを設定するには(Linux/OSXのアプリケーションディレクトリなど、OSがそれを見つけられない場所にsqliteのdll/so/dylibを配置した場合)、SQLiteLibraryNameプロパティを設定できます(任意の接続が確立される前に、たとえばメインフォームのOnCreateイベント内で)以下のように:

SQLiteLibraryName:='./sqlite3.so';

TSQLQuery:

  • SQL: Set it to some simple select query on one of your tables. For example, if you have a table 'foo' and want this dataset to represent this table then just use the following:
    SELECT * FROM foo
    
  • Active: Set this to True from within the IDE to test whether it is all set up correctly. This will also automatically activate the transaction and the connection objects. If you receive an error then either the DatabaseName of the connection is not correct or the SQL query is wrong. Later, when we are done adding the fields (see below) set them all to inactive again, we don't want the IDE to lock the SQLite database (single user!) when testing the application.
  • Probably not necessary for proper operation - will need to be checked (June 2012) Now we can add Fields to our TSQLQuery. While the components are still set to active do a right click and "edit fields...". Click the "+" button and add fields. It will list all fields your SQL query returned. Add every field you will need, you can also add lookup fields here; in this case just make sure you have already defined all needed fields in the other datasets before you start adding lookup fields that refer to them. If your table has many columns and you don't need them all you can just leave them out, you can also make your SQL a bit more specific.
  • In your code you need to call SQLQuery.ApplyUpdates and SQLTransaction.Commit, TSQLQuery.AfterPost and AfterInsert events are a good place for this when using it with data aware controls but of course you can also postpone these calls to a later time. If you don't call them, the database will not be updated.
  • "Database is locked": The IDE might still be locking the database (SQLite is a single user database), you probably forgot to set the components to inactive and disconnected again after you were done defining all the fields of your TSQLQuery objects. Use the Form's OnCreate event to set the path and activate the objects at runtime only. Most of the things you set in the TSQLQuery from within the IDE don't require (and some don't even allow) them to be active at design time, the only exception is defining the fields where it wants to read the table design, so inactive at design time should be the normal state.
  • Your tables should all have a primary key and you must make sure that the corresponding field has pfInKey and nothing else in its PoviderFlags (these flags control how and where the field is used when automatically constructing the update and delete queries).
  • If you are using lookup fields
    • make sure the ProviderFlags for the lookup field is completely empty so it won't attempt to use its name in an update query. The lookup field itself is not a data field, it only acts on the value of another field, the corresponding key field, and only this key field will later be used in the update queries. You can set the key field to hidden because usually you don't want to see it in your DBGrid but it needs to be defined.
    • LookupCache must be set to True. At the time of this writing for some reason the lookup field will not display anything otherwise (but still work) and strangely the exact opposite is the case when working with the TSQLite3Dataset or other TXXXDataset components, here it must be set to False. I'm not yet sure whether this is intended behavior or a bug.

After the above is all set up correctly, you should now be able to use the TSQLQuery like any other TDataset, either by manipulating its data programmatically or by placing a TDatasouce on the Form, connecting it to the TSQLQuery and then using data contols like TDBGrid etc.

Creating a Database

The TSQLite3Connection.CreateDB method inherited from the parent class actually does nothing; to create a database if no file exists yet, you simply have to write table data as in the following example:

(Code extracted from sqlite_encryption_pragma example that ships with Lazarus 1.3 onwards)

var
  newFile : Boolean;
begin

  SQLite3Connection1.Close; // Ensure the connection is closed when we start

  try
    // Since we're making this database for the first time,
    // check whether the file already exists
    newFile := not FileExists(SQLite3Connection1.DatabaseName);

    if newFile then
    begin
      // Create the database and the tables
      try
        SQLite3Connection1.Open;
        SQLTransaction1.Active := true;

        // Here we're setting up a table named "DATA" in the new database
        SQLite3Connection1.ExecuteDirect('CREATE TABLE "DATA"('+
                    ' "id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,'+
                    ' "Current_Time" DateTime NOT NULL,'+
                    ' "User_Name" Char(128) NOT NULL,'+
                    ' "Info" Char(128) NOT NULL);');

        // Creating an index based upon id in the DATA Table
        SQLite3Connection1.ExecuteDirect('CREATE UNIQUE INDEX "Data_id_idx" ON "DATA"( "id" );');

        SQLTransaction1.Commit;

        ShowMessage('Succesfully created database.');
      except
        ShowMessage('Unable to Create new Database');
      end;
    end;
  except
    ShowMessage('Unable to check if database file exists');
  end;
 end;

Creating user defined collations

// utf8 case-sensitive compare callback function
function UTF8xCompare(user: pointer; len1: longint; data1: pointer; len2: longint; data2: pointer): longint; cdecl;
var S1, S2: AnsiString;
begin
  SetString(S1, data1, len1);
  SetString(S2, data2, len2);
  Result := UnicodeCompareStr(UTF8Decode(S1), UTF8Decode(S2));
end;

// utf8 case-insensitive compare callback function
function UTF8xCompare_CI(user: pointer; len1: longint; data1: pointer; len2: longint; data2: pointer): longint; cdecl;
var S1, S2: AnsiString;
begin
  SetString(S1, data1, len1);
  SetString(S2, data2, len2);
  Result := UnicodeCompareText(UTF8Decode(S1), UTF8Decode(S2));
end;

// register collation using SQLite3 API (requires sqlite3dyn unit):
sqlite3_create_collation(SQLite3.Handle, 'UTF8_CI', SQLITE_UTF8, nil, @UTF8xCompare_CI);
// or using method of TSQLite3Connection:
CreateCollation('UTF8_CI',1,nil,@UTF8xCompare_CI);  

// now we can use case-insensitive comparison in SQL like:
// SELECT * FORM table1 WHERE column1 COLLATE UTF8_CI = 'á'

// but this does not work for LIKE operator
// in order to support also LIKE operator we must overload default LIKE function using sqlite3_create_function()
// http://www.sqlite.org/lang_corefunc.html#like

Creating user defined functions

// example overloading default LOWER() function with user supplied function
// to run this demo, you must add units 'sqlite3dyn' and 'ctypes' to your uses-clause
// and add a const 'SQLITE_DETERMINISTIC' with value $800

procedure UTF8xLower(ctx: psqlite3_context; N: cint; V: ppsqlite3_value); cdecl;
var S: AnsiString;
begin
  SetString(S, sqlite3_value_text(V[0]), sqlite3_value_bytes(V[0]));
  S := UTF8Encode(AnsiLowerCase(UTF8Decode(S)));
  sqlite3_result_text(ctx, PAnsiChar(S), Length(S), sqlite3_destructor_type(SQLITE_TRANSIENT));
end;

// register function LOWER() using SQLite3 API (requires sqlite3dyn unit):
sqlite3_create_function(SQLite3.Handle, 'lower', 1, SQLITE_UTF8 or SQLITE_DETERMINISTIC, nil, @UTF8xLower, nil, nil);

SQLite3 and Dates

  • SQLite 3 doesn't store dates as a special DateTime value. It can stores them as strings, doubles or integers - see http://www.sqlite.org/datatype3.html#datetime.
  • In strings, the date separator is '-' as per SQL standard/ISO 8601. Thus, if you do an INSERT using the built-in DATE function, it will store it as something like 'YYYY-MM-DD'.
  • Reading a DateTime value can cause problems for DataSets if they are stored as strings: the .AsDateTime qualifier can stall on an SQLite 'string date' but this can be overcome by using something like strftime(%d/%m/%Y,recdate) AS sqlite3recdate in your SQL SELECT statement, which forces SQLite3 to return the date record in a specified format. (the format string %d/%m/%d corresponds to your locale date format which .AsDateTime will understand) ==> Please open a bug report with an example application demonstrating the problemif this is the case
  • When comparing dates stored as strings (using for example the BETWEEN function) remember that the comparison will always be a string comparison, and will therefore depend on how you have stored the date value.

Default values in local time instead of UTC

CURRENT_TIME, CURRENT_DATE and CURRENT_TIMESTAMP return current UTC date and/or time. For local date and/or times we can use:

 DEFAULT (datetime('now','localtime')) for datetime values formated YYYY-MM-DD HH:MM:SS
 DEFAULT (date('now','localtime')) for date value formated YYYY-MM-DD
 DEFAULT (time('now','localtime')) for time value formated HH:MM:SS

SQLDB And SQLite troubleshooting

  • Keep in mind that for designtime support to work (fields etc) Lazarus must find sqlite3.dll too.
  • The same goes for the database filename. Always use absolute path if you use components to extract e.g. fieldnames at designtime. Otherwise the IDE will create an empty file in its directory. In case of trouble, check if the lazarus/ directory doesn't hold a zero byte copy of the database file.
  • If you have master/detail relationship, you need to refresh master dataset after each insert, in order to get value for slave dataset foreign key field. You can do that in AfterPost event of the master dataset, by calling one of the following overloaded procedures:
interface
    procedure RefreshADatasetAfterInsert(pDataSet: TSQLQuery);overload;
    procedure RefreshADatasetAfterInsert(pDataSet: TSQLQuery; pKeyField: string);overload;  
 
implementation
 
procedure RefreshADatasetAfterInsert(pDataSet: TSQLQuery; pKeyField: string);
//This procedure refreshes a dataset and positions cursor to last record
//To be used if Dataset is not guaranteed to be sorted by an autoincrement primary key
var
  vLastID: Integer;
  vUpdateStatus : TUpdateStatus;
begin
  vUpdateStatus := pDataset.UpdateStatus;
  //Get last inserted ID in the database
  pDataset.ApplyUpdates;
  vLastID:=(pDataSet.DataBase as TSQLite3Connection).GetInsertID;
  //Now come back to respective row
  if vUpdateStatus = usInserted then begin
    pDataset.Refresh;
    //Refresh and go back to respective row
    pDataset.Locate(pKeyField,vLastID,[]);
  end;
end;
 
procedure RefreshADatasetAfterInsert(pDataSet: TSQLQuery);
//This procedure refreshes a dataset and positions cursor to last record
//To be used only if DataSet is guaranteed to be sorted by an autoincrement primary key
var
  vLastID: Integer;
  vUpdateStatus : TUpdateStatus;
begin
  vUpdateStatus := pDataset.UpdateStatus;
  pDataset.ApplyUpdates;
  vLastID:=(pDataSet.DataBase as TSQLite3Connection).GetInsertID;
  if vUpdateStatus = usInserted then begin
    pDataset.Refresh;
    //Dangerous!
    pDataSet.Last;
  end;
end;

procedure TDataModule1.SQLQuery1AfterPost(DataSet: TDataSet);
begin
  RefreshADatasetAfterInsert(Dataset as TSQLQuery); //If your dataset is sorted by primary key
end;  

procedure TDataModule1.SQLQuery2AfterPost(DataSet: TDataSet);
begin
  RefreshADatasetAfterInsert(Dataset as TSQLQuery, 'ID'); //if you are not sure that the dataset is always sorted by primary key
end;

Vacuum and other operations that must be done outside a transaction

SQLDB seems to always require a connection, but some operations like Pragma and Vacuum must be done outside a transaction. The trick is to end transaction, execute what you must and start transaction again (so that sqldb doesn't get confused:)

  // commit any pending operations or use a "fresh" sqlconnection
  Conn.ExecuteDirect('End Transaction');  // End the transaction started by SQLdb
  Conn.ExecuteDirect('Vacuum');
  Conn.ExecuteDirect('Begin Transaction'); //Start a transaction for SQLdb to use

TSQLite3Dataset を使う

この節では、SQLite データベースへアクセスするために、どのように TSQLite2Dataset または TSQLite3Dataset コンポーネント を用いるかを詳しく説明しています。 Luiz Américo による luizmed(at)oi(dot)com(dot)br

要求事項

  • sqlite2 データベースのためには(レガシー):
    • FPC 2.0.0 以上
    • Lazarus 0.9.10 以上
    • SQLite runtime library 2.8.15 以上*
  • Sqlite2 はもはやメインテナンスされておらず、sqlite のサイトでバイナリファイルを見つけることはできません。
  • sqlite3 データベースのためには:
    • FPC 2.0.2 以上
    • Lazarus 0.9.11 (svn revision 8443) 以上
    • SQLite runtime library 3.2.1 以上 (www.sqlite.org から入手してください。)

Lazarus のプロジェクトを作る前に、次の事を確認してください。:

  • SQLite ライブラリが
    • システム PATH にある
    • 実行ファイルの出力されるディレクトリと Lazarus(または現在のプロジェクトの)ディレクトリにある - このオプションは Windows のみです。
  • Linuxでは、cmemを メインプログラムの uses の最初のユニットにしているかどうか
    • Debian や Ubuntu またその他の Debian-like ディストロにおいては、Lazarus IDE に libsqlite-dev/libsqlite3-dev, not only sqlite/sqlite3 パッケージをインストールする必要があります。(OpenSuSe にも適用してください。)

使い方 (基本)

/components/sqlite にあるパッケージをインストールしてください。(ここにその方法があります。)

設計時に下記のプロパティをセットして下さい。

  • FileName: sqliteファイルへのパス[必須]
  • TableName: sql文で使うテーブル名[必須]
  • SQL: SQLのSELECT文 [必要に応じて]
  • SaveOnClose: デフォルト値はfalse。つまり変更は保存されない。trueに変更可能。 [必要に応じて]
  • Active: 設計時またはプログラムのスタート時に設定[必須]

テーブルを作成する(Dataset)

コンポーネントアイコンをダブルクックするか、右マウスボタンのクリックで現れるポップアップメニューより、'Create Table' を選択します。 簡単な説明のあるテーブルエディタが表示されます。

下記は TSqliteDataset と TSqlite3Dataset でサポートされているすべてのフィールドの型です。

  • Integer
  • AutoInc
  • String
  • Memo
  • Bool
  • Float
  • Word
  • DateTime
  • Date
  • Time
  • LargeInt
  • Currency

データを取得する

テーブルを生成した後か、以前作ったテーブルで作業する場合、Open 手続きでデータセットを開いて下さい。 SQL プロパティがセットされていない場合、すべてのフィールドのすべてのレコードを取得するためには、次のような1文をSQLにセットします。:

SQL := 'Select * from TABLENAME';

データファイル上に変更を適用する

ApplyUpdates 関数を使うために, データセットは、主キーの条件を満たす少なくとも1つのフィールドを持っていなければなりません。(値は、UNIQUE であり、NULL ではない必要があります。)

変更を適用するために2つの方法があります。

  • PrimaryKey プロパティに主キーになっているフィールド名を設定する。
  • AutoIncフィールドを加える。(これは TSqliteDataset が自動的にそれを主キーとしてみなすので、より簡単です。)

2つの条件のうち1つをセットしたら、以下を呼び出してください。

ApplyUpdates;
Light bulb  Note: もし、両方の条件がセットされたら、主キーに相当するフィールドが更新の適用に使われます。
Light bulb  Note: 主キーではないフィールドを主キーに設定することは、ApplyUpdate がコールされたときにデータのロスを引き起こします。ですから、選択されたフィールドは、 Null でなく Unique であることを、それを使う前に確認してください。
Master/detail のサンプル

master/detail 関係の様々なサンプル (例えば、顧客と注文の間の関係):

注意事項

  • 10000レコードまではテストして、上手く動きますが、TSqliteDataset はすべてのデータをメモリ上に置くため、必要なデータのみ受け取るようにしてください。(特にMemoフィールドなどに注意).
  • 同じデータファイルに(同じファイル名のプロパティに)、いくつかのテーブル、データセットを持たせることができます。
  • いくつかのデータセット(違うフィールドの組み合わせの)を同じテーブルから作ることができます。
  • SQL文 で WHERE を使ってデータをフィルタすることが可能です。また、データセットのクローズおよび再オープン(あるいは、RefechData メソッドを呼ぶこと)ができます。しかし、この場合、並び順やフィールドの数は同じでなくてはなりません。
  • 複数のテーブルから aliases や join , views などを使って複雑な SQL 文が実行可能です(これらは同じデータファイルにある必要があることに注意)。しかしこの場合、ApplyUpdate は動作しません。もし複雑なクエリをつかって、データファイルに更新を加えたければ私(Luiz Américo)にメールしてください。そうすれば、どういうふうにおこなうか、ヒントをお伝えすることができます。
  • TSqliteDataset で生成されていない sqlite のデータファイルにファイル名を設定するときおよび、そのファイルを開くとき、一部のフィールドが正しい型を検出することが、許可されていません。これらは、string フィールドとして扱われます。

一般的なサンプルが、SVNディレクトリの fpc/fcl-db/src/sqlite にあります。

関連情報