Difference between revisions of "SQLdb Programming Reference/ja"

From Free Pascal wiki
Jump to navigationJump to search
Line 25: Line 25:
  
 
===TSQLTransaction===
 
===TSQLTransaction===
Documentation: [http://www.freepascal.org/docs-html/fcl/sqldb/tsqltransaction.html TSQLTransaction]
+
ドキュメンテーション: [http://www.freepascal.org/docs-html/fcl/sqldb/tsqltransaction.html TSQLTransaction]
  
This object represents a transaction on the database. In practice, at least one transaction needs to be active for a database, even if you only use it for reading data.
+
このオブジェクトは、データベース上のトランザクションを表す。実際には、データを読み取るだけでも、少なくとも1つのトランザクションがアクティブである必要がある。
When using a single transaction, set the TConnection.Transaction property to the transaction to set the default transaction for the database; the corresponding TSQLTransaction.Database property should then automatically point to the connection.
+
単一のトランザクションを使用する場合は、TConnection.Transactionプロパティをトランザクションに設定して、データベースのデフォルトのトランザクションを設定する。対応するTSQLTransaction.Databaseプロパティは、自動的に接続を指すようになる。
  
Setting a [[TSQLTransaction]] to .Active/calling .StartTransaction starts a transaction; calling .Commit or .RollBack commits (saves) or rolls back (forgets/aborts) the transaction. You should surround your database transactions with these unless you use .Autocommit or CommitRetaining.
+
TSQLTransactionを.Activeに設定する/.StartTransactionを呼び出すと、トランザクションが開始される。.Commitまたは.RollBackを呼び出すと、トランザクションがコミット(保存)されるか、ロールバック(忘却/中止)される。.AutocommitまたはCommitRetainingを使用しない限り、データベースのトランザクションをこれらで囲む必要がある。
  
 
===TSQLQuery===
 
===TSQLQuery===

Revision as of 14:28, 2 April 2024

English (en) español (es) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

データベースのポータル

参照:

チュートリアル/練習となる記事:

各種データベース

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

ドキュメンテーション

公式ドキュメントを参照されたい SQLDB documentation

この記事はSQLDbについて詳細を説明しようとしているが、公式のドキュメントがより権威的である。

クラス構造

以下の図は、SQLdbに関連する主要なコンポーネントの階層と必要なリンクを示すことを試みている。これは完全ではなく、"適切な"図の構造を使用していないため、あまり深く読み込まないでいただきたい。実際に何が起こっているのかを理解するために、ソースコードを調べる必要がある部分を見つけるのに役立つことを望む。

Laz SqlDB components.png

注意

  • TDatabaseからTTransactionへのリンクはTransactionsであり、これは多くのトランザクションが1つのデータベースに可能であることを示している。しかし、TSQLConnectionからTSQLTransactionへの新しいリンクがTransactionとして定義されており、1つのデータベースに対して1つのトランザクションしかない。これは実際には以前のリンクを隠していないが、新しいリンクのみが公開されており、親リンクを使用することはおそらく適切ではない。
  • 継承されたリンクのうち、一部は新しい型に型変換する必要がある。SQLQuery.Transaction.Commitを呼び出すことはできない。CommitはTSQLTransactionでのみ定義されている。SQLTransaction.Commitまたは"(SQLQuery.Transaction as TSQLTransaction).Commit"を呼び出すこと。

インタラクション

TConnection

TConnectionはSQLデータベースへの接続を表す。日常的には、特定のデータベース用の派生クラス(例:Interbase/Firebirdの場合はTIBConnection)を使用するが、データベースファクトリー/データベース非依存のアプリケーションを作成しようとしている場合はTConnectionを使用することも可能だ(注:TSQLConnectorの使用がおそらくより適切である)。 このオブジェクトでは、ホスト名、ユーザー名、パスワードなどの接続関連の項目を指定する。 最後に、.Activeまたは.Connectedプロパティを使用して接続または切断できる。

ほとんどのデータベースは、同じプログラムやユーザーからの複数の同時接続を許可している。

TSQLTransaction

ドキュメンテーション: TSQLTransaction

このオブジェクトは、データベース上のトランザクションを表す。実際には、データを読み取るだけでも、少なくとも1つのトランザクションがアクティブである必要がある。 単一のトランザクションを使用する場合は、TConnection.Transactionプロパティをトランザクションに設定して、データベースのデフォルトのトランザクションを設定する。対応するTSQLTransaction.Databaseプロパティは、自動的に接続を指すようになる。

TSQLTransactionを.Activeに設定する/.StartTransactionを呼び出すと、トランザクションが開始される。.Commitまたは.RollBackを呼び出すと、トランザクションがコミット(保存)されるか、ロールバック(忘却/中止)される。.AutocommitまたはCommitRetainingを使用しない限り、データベースのトランザクションをこれらで囲む必要がある。

TSQLQuery

Documentation: TSQLQuery documentation

See Working With TSQLQuery for more details.

TSQLQuery is an object that embodies a dataset from a connection/transaction pair using its SQL property to determines what data is retrieved from the database into the dataset.

When working with it, you therefore need to at least specify the transaction, connection amd SQL properties. The TSQLQuery is an important part in the chain that links databound controls to the database. As said, the SQL property determines what SELECT query is run against the database to get data. FPC will try to determine what corresponding SQL INSERT, UPDATE and DELETE statements should be used in order to process user/program generated data changes. If necessary, the programmer can fine tune this and manually specify the InsertSQL, UpdateSQL and DeleteSQL properties.

DataSource

A TDataSource object keeps track of where in a dataset (such as TSQLQuery) data bound components are. The programmer should specify the corresponding TSQLQuery object for this to work.

Databound controls such as DBGrid

These controls must be linked to a DataSource. They will often have properties that indicate what fields in the DataSource they show.

Data modules

Data modules can be used to store non-visual components such as T*Connection, TSQLTransaction, TSQLQuery etc. Data modules also let you share components between forms.

See SQLdb Tutorial4.