Sign in Join
Wiki copytemporary

ODBCConn/ja: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-**ODBCConn** ユニットはOpen Database Connectivity (ODBC)データソースにSQLbの接続を実装している。
1+---
2+[[Portal:Databases/ja|**データベースのポータル**]]
3+参照: · [[Databases/ja|Databases 概要]] · [[Database libraries/ja|ライブラリ]] · [[Database field type/ja|フィールドの型]] · [[Data Controls tab/ja|コントロール]] · [[Lazarus DB Faq/ja|FAQ]] · [[SqlDBHowto/ja]] · [[Working With TSQLQuery/ja|TSQLQuery の利用]] · [[How to write in-memory database applications in Lazarus/FPC/ja|メモリ上で動作するデータベースの作り方]] · チュートリアル/練習となる記事: · [[Lazarus Database Overview/ja|概要]] · [[SQLdb Tutorial0/ja|0 - データベースのセットアップ]] · [[SQLdb Tutorial1/ja|1 - 開始]] · [[SQLdb Tutorial2/ja|2 - 編集]] · [[SQLdb Tutorial3/ja|3 - クエリ]] · [[SQLdb Tutorial4/ja|4 - データモジュール]] · [[SQLdb Programming Reference/ja]] · 各種データベース · [[Advantage Database Server/ja|Advantage]] \- [[MySQLDatabases/ja|MySQL]] \- [[mssqlconn/ja|MSSQL]] \- [[postgres/ja|Postgres]] \- [[Firebird/ja|Interbase]] \- [[Firebird/ja|Firebird]] \- [[Oracle/ja|Oracle]] \- ODBC \- [[TParadox/ja|Paradox]] \- [[SQLite/ja|SQLite]] \- [[Lazarus Tdbf Tutorial/ja|dBASE]] \- [[MS Access/ja|MS Access]] \- [[Zeos tutorial/ja|Zeos]]
4+
5+**ODBCConn** ユニットはOpen Database Connectivity (ODBC)データソースにSQLbの接続を実装している。
26
37## 概要
48
59### ODBC
610
7-ODBC (Open Database Connectivity) とは単純なAPIである、ODBC APIを用いて、さまざまなデータベース全体に接続することのできる技術である。
11+ODBC (Open Database Connectivity) とは単純なAPIである、ODBC APIを用いて、さまざまなデータベース全体に接続することのできる技術である。
812
9-さまざまなプラットフォームに向けて、ODBCの実装があり、ほとんどのデータベースマネジメントシステムにドライバがある。 公式のODBCドキュメンテーションは\[<http://msdn.microsoft.com/en-us/library/ms710252(VS.85>).aspx MSDN ODBC site\]である。
13+さまざまなプラットフォームに向けて、ODBCの実装があり、ほとんどのデータベースマネジメントシステムにドライバがある。 公式のODBCドキュメンテーションは[MSDN ODBC site](<http://msdn.microsoft.com/en-us/library/ms710252\(VS.85\).aspx>)である。
1014
1115### TODBCConnection
1216
13-FreePascal ships with ODBC headers; they are in the `odbcsql` and `odbcsqldyn` units. [[TODBCConnection]] is an [[TSQLConnection]] descendant providing a nice OOP wrapper for ODBC using the SQLdb framework.
17+FreePascalには `odbcsql` と `odbcsqldyn` ユニットが付属する。
18+```
19+[[TSQLConnection]] の派生、[[TODBCConnection]] はSQLDBフレームワークを用いるときにODBCによいOOPラッパを提供する。
20+```
1421
15-In Lazarus, you can find the `TODBCConnection` component on the SQLdb component tab. You can also use the `TODBCConnection` component in your code by adding `ODBCConn` to your uses clause.
22+LazarusではSQLdbコンポーネントタブで `TODBCConnection` が見つかる。 Uses句で`ODBCConn`をコードに加えることにより`TODBCConnection`を用いることもできる。
1623
17-![](/wiki-images/c/c1/Sqldbcomponents-n.png)
24+[![sqldbcomponents-n.png](/wiki-images/5/5b/sqldbcomponents-n.png)](</File:sqldbcomponents-n.png>)
1825
19-What has been implemented:
26+実装されているもの:
2027
21-- executing queries and retrieving result sets
22-- most field types, including blobs
23-- query parameters (string and integer types)
24-- preparing queries
25-- UpdateIndexDefs (so you can use ApplyUpdates)
28+ * クエリを実行し結果セットを取得する
29+ * Blobを含むほとんどのフィールド型
30+ * クエリのパラメータ(文字列と整数型)
31+ * クエリを準備する
32+ * UpdateIndexDefs (このためApplyUpdatesを用いることができる)
2633
27-What is left to be implemented:
34+実装されていないもの:
2835
29-- proper transaction support; currently each connection corresponds to one transaction
30-- some field types
31- - SQL_TYPE_UTC* (these are mentioned in the ODBC docs, but seem not to be used in implementations)
32- - SQL_INTERVAL_* (what would be the corresponding TFieldType?)
33- - SQL_GUID (TGUIDField was not implemented, until recently)
36+ * 適当なトランザクションサポート; 現在は各々の接続が1つのトランザクションに対応している
37+ * いくつかのフィールド型
38+ * SQL_TYPE_UTC* (ODBCのドキュメントには触れられているが、実装はされていないようだ)
39+ * SQL_INTERVAL_* (どのTFieldTypeに対応するのだろうか?)
40+ * SQL_GUID (TGUIDFieldは近年まで実装されていなかった)
3441
3542### なぜ ODBC なのか ?
3643
37-FreePascal ships with components for connecting to several databases, such as MySQL, PostGreSQL, Firebird, Microsoft SQL Server (since 2.6.1), Oracle, etc.
44+Free Pascalには、例えばMySQL、PostgreSQL、Firebird、Microsoft SQL Server (2.6.1以降)、Oracleなどのいくつかのデータベースに接続するためのコンポーネントが同梱されている。
3845
39-For those databases missing from the list, like [[MS Access]] and perhaps Microsoft SQL Server, ODBC is an acceptable and well established solution. (VB.net/C# developers are recommended to use SQLClient rather than OLEDB or ODBC for the ultimate in performance, but here in Lazarus ODBC will work adequately and reliably)
46+これらのデータベースから漏れているもの、例えば [[MS Access]] そしておそらくMicrosoft SQL Serverのようなものにとって、ODBCは広く受け入れられ、よく確立したソリューションである (VB.Net/C#開発者はOLEDBもしくはODBCよりもSQLClientを最速のパフォーマンスのために用いることが薦められているが、LazarusのODBCは十分で、信頼性に足るものである)。
4047
41-The TODBCConnection component was developed originally to circumvent the strict MySQL license for applications that are not GPLed or do not obey MySQL AB's [FLOSS exception](http://www.mysql.com/company/legal/licensing/foss-exception.html).
48+TODBCConnectionはアプリケーションに対するGLPではない厳格なMySQLのライセンスを回避して独自に開発され、MySQL ABには従わない。 [FLOSS exception](<http://www.mysql.com/company/legal/licensing/foss-exception.html>).
4249
4350## ODBC と ODBC ドライバをインストールする
4451
45-Before you can connect to your database using ODBC, you need to install
52+ODBCを用いてデータベースに接続する前に、以下をインストールする必要がある
4653
47-- an ODBC Driver Manager
48-- an ODBC driver specific to the DBMS you want to connect to
54+ * ODBCドライバマネージャ
55+ * 接続したいデータベースに対する特定のODBCドライバ
4956
50-This section will give a brief overview of the steps involved. However, please consult the relevant documentation for a definitive reference.
57+この節ではこれに関する仕方を概観するが、それぞれのドキュメントを参照されたい。
5158
5259### ODBC ドライバマネージャ
5360
5461#### Windows
5562
56-Windows has an ODBC Driver Manager built in, which allows DSNs to be set up, and other configuration. It is found in the *Control Panel*, in later Windows versions with categorised sections it was moved into the *Administrative Tools* area. Or you may simply click the Start button and enter *ODBC* into the Run box (in Windows 7 this appears as "*Search programs and files*").
63+WindowsはODBCドライバマネージャが組み込まれており、それを用いてDSNをセットアップ、設定できる。これは近年のWindowsでは _コントロールパネル_ の _Windowsツール_ に移動している。もしくはスタートボタンを押し、 _ODBC_ と入力する(Windows 7ではこれは"_管理ツール_ "で見つかる)
5764
58-You can, of course, create a desktop shortcut to the ODBC dialog if you find yourself using it frequently.
65+もちろん頻繁に使うのであればODBCダイアログをデスクトップのショートカットにしてもよい。
5966
60-![](/wiki-images/3/39/WinXPODBCDataSourceAdministratorDrivers.png)
67+[![WinXPODBCDataSourceAdministratorDrivers.png](/wiki-images/3/39/WinXPODBCDataSourceAdministratorDrivers.png)](</File:WinXPODBCDataSourceAdministratorDrivers.png>)
6168
6269#### Unices
6370
64-Two popular ODBC Driver Managers for Unix-based platforms are [unixODBC](http://www.unixodbc.org) and [iODBC](http://www.iodbc.org). `ODBCConn` is known to work with unixODBC; iODBC compatibility still has to be tested.
71+Unixベースのプラットフォームには2つのよく知られたODBCドライバマネージャがあり、それらは [unixODBC](<http://www.unixodbc.org>) と [iODBC](<http://www.iodbc.org>) である。`ODBCConn` はunixODBCと動くことが知られており、iODBCの互換性はまだテストが必要である。
6572
6673##### Debian
6774
68-For Debian, you can install the *unixodbc* package:
69-
70-``` bash
75+Debianでは _unixodbc_ をインストールすることができる。
76+```
7177aptitude install unixodbc
72-aptitude install unixodbc-bin # if you want some GUI tools
78+ aptitude install unixodbc-bin # もしGUIツールを望むなら
7379```
7480
75-The `odbcsqldyn` unit, and hence `odbcconn`, will search for a file called `libodbc.so`. It will *not* accept a file named like `libodbc.so.1` or `libodbc.so.1.0.0`. Debian's *unixodbc* package does not create a symlink with the name `/usr/lib/libodbc.so`; you must either
81+`odbcsqldyn` ユニットそして `odbcconn`は`libodbc.so`というファイルを探す。 それは`libodbc.so.1` や `libodbc.so.1.0.0`といったファイル名を _許容しない_ 。
7682
77-- create the link yourself: `ln -s libodbc.so.1 /usr/lib/libodbc.so`, or
78-- install the *unixodbc-dev* package, which does create the symlink.
83+Debianの _unixodbc_ パッケージは`/usr/lib/libodbc.so`というシンボリックリンクを生成しないので、
7984
80-If you installed the *unixodbc-bin* package, you can run the `ODBCConfig` program to configure ODBC drivers and DSNs.
85+ * 自分自身でシンボリックリンク: `ln -s libodbc.so.1 /usr/lib/libodbc.so` を作るか、
86+ * _unixodbc-dev_ パッケージをインストールするそれはシンボリックリンクを生成してくれる。
8187
82-![](/wiki-images/b/bf/ODBCDataSourceAdministratorAbout.PNG)
88+もし _unixodbc-bin_ パッケージをインストールしたなら、`ODBCConfig`プログラムを実行してODBCドライバとDSNの設定ができる。
8389
90+
91+[![ODBCDataSourceAdministratorAbout.PNG](/wiki-images/b/bf/ODBCDataSourceAdministratorAbout.PNG)](</File:ODBCDataSourceAdministratorAbout.PNG>)
92+
8493##### Ubuntu
8594
86-For Ubuntu, follow the instruction for Debian. Note: the *unixodbc-bin* package might not be available from the default package repository.
95+UbuntuではDebianでのやり方に従うこと。 Note: _unixodbc-bin_ パッケージはデフォルトのパッケージレポジトリからは得られないかもしれない。
8796
8897### ODBC Drivers
8998
90-訳注:以下にリンクがありますが、保存の時にはじかれましたので、https://は省いてあります You can download latest ODBC drivers using the following links:
99+最新のODBCドライバは以下のリンクからダウンロードできる。訳注:以下にリンクがありますが、保存の時にはじかれましたので、<https://は省いてあります>
91100
92-www.devart.com/odbc/sqlserver/download.html Download SQL Server 32/64 bit ODBC driver - latest version of SQL Server ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with SQL Server 2014\2012\2008 R2\\ 2008\2005 (including Express edition), SQL Server 2000 (including MSDE), SQL Server 7, SQL Server Compact 4.0\3.5\3.1. Works on all Lazarus versions.
101+www.devart.com/odbc/sqlserver/download.html Download SQL Server 32/64 bit ODBC driver - latest version of SQL Server ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with SQL Server 2014\2012\2008 R2\ 2008\2005 (including Express edition), SQL Server 2000 (including MSDE), SQL Server 7, SQL Server Compact 4.0\3.5\3.1. Works on all Lazarus versions.
93102
94-www.devart.com/odbc/oracle/download.html Download Oracle 32/64 bit ODBC driver - latest version of Oracle ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with Oracle servers: 12c, 11g, 10g, 9i, 8i, 8.0, including Oracle Express Edition 11g and 10g. Oracle Clients: 12c, 11g, 10g, 9i, 8i, 8.0. Works on all Lazarus versions.
103+www.devart.com/odbc/oracle/download.html Download Oracle 32/64 bit ODBC driver - latest version of Oracle ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with Oracle servers: 12c, 11g, 10g, 9i, 8i, 8.0, including Oracle Express Edition 11g and 10g. Oracle Clients: 12c, 11g, 10g, 9i, 8i, 8.0. Works on all Lazarus versions.
95104
96-www.devart.com/odbc/mysql/download.html Download MySQL 32/64 bit ODBC driver - latest version of MySQL ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with MySQL servers: 6.0, 5.6, 5.5, 5.1, 5.0, 4.1, 4.0, and 3.23. MariaDB 5.x Works on all Lazarus versions.
105+www.devart.com/odbc/mysql/download.html Download MySQL 32/64 bit ODBC driver - latest version of MySQL ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with MySQL servers: 6.0, 5.6, 5.5, 5.1, 5.0, 4.1, 4.0, and 3.23. MariaDB 5.x Works on all Lazarus versions.
97106
98-www.devart.com/odbc/postgresql/download.html Download PostgreSQL 32/64 bit ODBC driver - latest version of PostgreSQL ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with PostgreSQL server versions since 7.1 up to 9.4. Works on all Lazarus versions.
107+www.devart.com/odbc/postgresql/download.html Download PostgreSQL 32/64 bit ODBC driver - latest version of PostgreSQL ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with PostgreSQL server versions since 7.1 up to 9.4. Works on all Lazarus versions.
99108
100-www.devart.com/odbc/postgresql/download.html Download SQLite 32/64 bit ODBC driver - latest version of SQLite ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with SQLite versions since 3.0 and higher. Works on all Lazarus versions.
109+www.devart.com/odbc/postgresql/download.html Download SQLite 32/64 bit ODBC driver - latest version of SQLite ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with SQLite versions since 3.0 and higher. Works on all Lazarus versions.
101110
102-www.devart.com/odbc/firebird/download.html Download Firebird 32/64 bit ODBC driver - latest version of Firebird ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with Firebird versions 3, 2.x, 1.x. Works on all Lazarus versions.
111+www.devart.com/odbc/firebird/download.html Download Firebird 32/64 bit ODBC driver - latest version of Firebird ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with Firebird versions 3, 2.x, 1.x. Works on all Lazarus versions.
103112
104-www.devart.com/odbc/interbase/download.html Download Interbase 32/64 bit ODBC driver - latest version of Interbase ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with all Interbase versions. Works on all Lazarus versions.
113+www.devart.com/odbc/interbase/download.html Download Interbase 32/64 bit ODBC driver - latest version of Interbase ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with all Interbase versions. Works on all Lazarus versions.
105114
106-www.devart.com/odbc/sqlazure/download.html Download SQL Azure 32/64 bit ODBC driver - latest version of SQL Azure ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with all SQL Azure versions. Works on all Lazarus versions.
115+www.devart.com/odbc/sqlazure/download.html Download SQL Azure 32/64 bit ODBC driver - latest version of SQL Azure ODBC driver which supports Windows, Mac OS X, Linux both on 32 and 64 versions. Compatible with all SQL Azure versions. Works on all Lazarus versions.
107116
108117## ODBC データソースに接続する
109118
110-The parameters for connecting to an ODBC data source are described in a *connection string*. This is a string of the form `NAME=VALUE;NAME=VALUE`.
119+ODBCデータソースに接続するためのパラメータは _接続文字列_ と呼ばれる。 これは`NAME=VALUE;NAME=VALUE`の形の文字列である。
111120
112-`TODBCConnection` provides a wrapper around this connection string. Some of its properties are mapped to name-value pairs in the connection string, and custom parameters can be specified in the `Params` property (which is a `TStrings`).
121+`TODBCConnection` はこの接続文字列に対するラッパを提供する。 接続文字列の中でいくつかのプロパティは名前-値の組で表される。独自のパラメータは `Params` プロパティ(それは`TStrings`である)で指定される。
113122
114-Before going to the details of this wrapper, you must first have a basic understanding of how an ODBC data source is identified.
123+このラッパに進む前に、どのようにODBCデータソースが認識されるか基本的な理解が必要となる。
115124
116125### DSN 経由で ODBC 接続
117126
118-An ODBC driver manager provides alternative ways to make DSN shortcuts for a set of parameters:
127+ODBCドライバマネージャはいくつかのパラメータに代わって、DSNショートカットを作る別の手段を提供する:
119128
120-- DSN (**D**ata**S**ource **N**ame): a system or user defined data source, identified by a (unique) name. DSNs can be configured using the ODBC Data Source Administrator or by manually editing the `odbc.ini` file (or registry).
121-- File DSN: a file which contains connection parameters. An ODBC Data Source Administrator usually allows you to create File DSNs from the GUI.
129+ * DSN (**D** ata**S** ource **N** ame): (固有の)名前によって識別されるシステム、もしくはユーザーによって定義されたデータソースである。DSNはODBCデータソースアドミニストレータを用いて、手動で `odbc.ini` ファイル(またはレジストリ)を編集することで設定できる。
130+ * File DSN: 接続パラメータを含むファイルである。ODBCデータソースアドミニストレータはたいていGUIによってファイルDSNを作れるようにする。
122131
123-The parameters in a DSN or File DSN can always be combined with additional parameters in the connection string, for example to specify a password.
132+DSNやファイルDSNは接続文字列に追加のパラメータを結合することができ、例えば、パスワードがあげられる。
124133
125-By setting up a DSN the connection details can be verified to work within the manager dialog, and then the named DSN is all that is needed to use the connection later. The connection details are therefore *decoupled* from your application, as only the DSN name is used in your software - the DSN acting as a go-between.
134+DSNを設定することで、接続の細目がデータソースアドミニストレータのダイアログで確認することができ、そして名付けられたDSNが、のちの接続に用いるのに必要な唯一のものとなる。ゆえに接続の細目は、アプリケーションより _分離_ されソフトウエアにおいてはDSN名だけが用いられる - DSNは仲介者としてふるまう。
126135
127-An advantage to using a named DSN is that you may easily switch between databases using the ODBC Manager, without changing your code. This is useful in commercial development to test for bugs using a number of sets of your clients' data.
136+名前DSNを用いる利点はODBCマネージャを用いて、コードを変えることなく、データベースを簡単に切り替えられる点にある。これは顧客の多くのデータを用いながら、バグテストを巣つために業務用の開発を行うときに便利である。
128137
129138### DSN なしで
130139
131-You may also connect via ODBC without using a DSN, simply supplying all the details in the Connection String that you would otherwise set up in a DSN (driver,server,database,login details). This more direct method avoids the need to set up a DSN when installing your application on a new machine.
140+またDSNなしでODBC経由で接続もでき、DSNで設定させる接続文字列(ドライバ、サーバ、データベース、ログイン情報)のすべての詳細を単に示してやればよい。この直接的方法はアプリケーションを新しい端末にインストールするときにDSNを設定する必要をなくす。
132141
133-The ODBC specification defines a few parameters that can be used in a connection string:
142+ODBCの仕様は接続文字列の中で用いられるようにいくつかのパラメータを定義している:
134143
135-- Two special parameters, `DSN` and `FILEDSN`, allow one to select a set of pre-defined parameters, as described above.
136-- The `DRIVER` specifies which ODBC driver to use. Obviously, this is a very important parameter.
137-- The `UID` and `PWD` parameters are used to supply a username and password.
144+ * 2つの特別なパラメータ `DSN` と `FILEDSN` は上述のあらかじめ定義されたパラメータを選択することを可能にする
145+ * `DRIVER` はどのODBCドライバが用いられるか特定する。これは明らかに重要なパラメータである。
146+ * `UID` と `PWD` はユーザー名とパスワードを供給するために用いられる。
138147
139-All other parameters are driver dependent. Please refer to the documentation of the specific driver to learn more about available parameters and their names.
148+その他のパラメータはドライバ固有のものである。 用いられるパラメータとその名前についての詳細を知るには、そのドライバのドキュメントを参照されたい。
140149
141150### TODBCConnection プロパティ
142151
143-The following table describes the mapping of `TODBCConnection` properties to ODBC connection string parameters:
144-
145-**Property**
146-
147-**Type**
148-
149-**Connection string parameter**
150-
151-`Driver`
152-
153-`string`
154-
155-`DRIVER`
156-
157-`DatabaseName`
158-
159-`string`
160-
161-`DSN`, *not* to something like `DATABASENAME`, which is not part of the ODBC standard
162-
163-`FileDSN`
164-
165-`string`
166-
167-`FILEDSN`
168-
169-`Password`
170-
171-`string`
172-
173-`PWD`
174-
175-`UserName`
176-
177-`string`
178-
179-`UID`
180-
181-`HostName`
182-
183-`string`
184-
185-*none*; there is no corresponding parameter in the ODBC standard
186-
187-`Params`
188-
189-`TStrings`
190-
191-Use this to specify custom parameters. Each item must be of the form `NAME=VALUE`.
192-
193-One important parameter that can be used is **`AUTOCOMMIT`** which determines if SQL statements are directly executed (without possibility of a rollback) (default setting, or set explicitly using `AUTOCOMMIT=1`) or whether you need to manually call StartTransaction and Commit, CommitRetaining or Rollback (set using `AUTOCOMMIT=0`)
152+以下はODBC接続文字列に対する `TODBCConnection ` プロパティで用いられるのマッピングを現した表である:
194153
195-Note that `TODBCConnection` will take care of escaping parameter values in the connection string (when required).
154+プロパティ | 型 | 接続文字列パラメータ
155+---|---|---
156+`Driver` | `string` | `DRIVER`
157+`DatabaseName` | `string` | `DSN`, ODBC標準の一部である `DATABASENAME`, _ではない_
158+`FileDSN` | `string` | `FILEDSN`
159+`Password` | `string` | `PWD`
160+`UserName` | `string` | `UID`
161+`HostName` | `string` | _none_ ; ODBC標準にはないパラメータであるthere is no corresponding parameter in the ODBC standard
162+`Params` | `TStrings` | 独自のパラメータとして用いること。それぞれの項目は`NAME=VALUE`型になってなければならない。 ここで用いられる1つの重要なパラメータは **`AUTOCOMMIT`** で、これはSQL文が直接実行される(ロールバックの可能性なしに)(デフォルト値、もしくは明示的に `AUTOCOMMIT=1`が用いられる) または手動で、StartTransaction、Commit、CommitRetainingまたはRollbackしなければならない (`AUTOCOMMIT=0`を用いた場合)
163+
164+注意: `TODBCConnection` は必要な時には接続文字列中のエスケープパラメータを考慮してくれる。
196165
197-The `LoginPrompt` boolean property is not implemented yet. It would require finding the correct window handle, so a driver can show a GUI dialog to specify parameters. Note that this is not controlled by the connection string, but rather by the last parameter to the ODBC API function `SQLDriverConnect`.
166+`LoginPrompt` ブール値プロパティは未だに実装されていない。 正しいウインドウハンドルを見出して、ドライバがパラメータを特定するためのGUIダイアログを示すことができる。 これは接続文字列によって制御されないことに注意すること。しかし、`SQLDriverConnect`ODAC API関数に対する最後のパラメータによる。
198167
199168## 例
200169
201-In this section, examples are given of connecting to certain DBMSs using their specific ODBC drivers.
170+この節ではそれぞれ特定のODBCドライバを用いて、そのDBMSに接続する方法について例示する。
202171
203172### Excel に接続する
204173
205-Probably works on Windows only.
206-
207-To avoid errors like: Could not start transaction! ODBC error details: LastReturnCode: SQL_ERROR; Record 1: SqlState: HYC00; NativeError: 106; Message: \[Microsoft\]\[ODBC Excel Driver\]Optional feature not implemented ;
174+おそらくWindowsでのみ動く
208175
209-... you'll have to enable autocommit, something like
176+このようなエラーを避けるために: トランザクションを開始できませんでした! ODBCエラー: LastReturnCode: SQL_ERROR; Record 1: SqlState: HYC00; NativeError: 106; Message: [Microsoft][ODBC Excel
210177
211-``` pascal
178+... 以下のようにオートコミットを有効にしなければならない、
179+```
212180ODBCConnection1.Params.Add('AUTOCOMMIT=1');
213181```
214182
215183### MySQL に接続する
216184
217-For a reference of supported parameters by the MyODBC driver, see [1](https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html).
218-
219-Additionally you may check this www.devart.com/odbc/mysql/docs/using_odbc_driver.htm mysql odbc connection guide. It has a detail explanation of how to connect to MySQL using ODBC.
185+MyODBCドライバにより、サポートされるパラメータリファレンスに関しては、[[1]](<https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html>) を参照されたい。
220186
221-The driver name differs a bit depending on the platform and MyODBC version; examples are :
187+加えてここを見ること www.devart.com/odbc/mysql/docs/using_odbc_driver.htm。MySQLにODBCドライバを用いて接続する詳細がある。
222188
223-``` pascal
224- { properties of connection object, i.e. conn: TODBCConnection; }
225- conn.Driver := 'MySQL'; // (Unix)
226- conn.Driver := 'MySQL ODBC 3.51 Driver'; // (Windows)
227- conn.Driver := 'MySQL Connector/ODBC v5'; // (Windows)
228- // note: driver name doesn't need {} like it does in SQL Connection Strings elsewhere
189+ドライバの名前はプラットフォームとMyODBCのバージョンによって変わるが、例としては:
229190```
230-
231-Other parameters (when not using a DSN) :
191+{ properties of connection object, i.e. conn: TODBCConnection; }
192+ conn.Driver := 'MySQL'; // (Unix)
193+ conn.Driver := 'MySQL ODBC 3.51 Driver'; // (Windows)
194+ conn.Driver := 'MySQL Connector/ODBC v5'; // (Windows)
195+ // 注意: ドライバ名は他に随所あるSQL 接続文字列のように{}を必要としない。
196+```
232197
233-``` pascal
234- conn.UserName := 'myUsername';
235- conn.Password := 'myPassword';
236- // conn.Params (TStrings) set using .add method :
237- conn.Params.Add('server=example.com');
238- conn.Params.Add('port=3306');
239- conn.Params.Add('database=myDatabase');
240- conn.Params.Add('charset=utf8');
198+他のパラメータ (DSNを用いない場合) :
241199```
200+conn.UserName := 'myUsername';
201+ conn.Password := 'myPassword';
202+ // conn.Params (TStrings) set using .add method :
203+ conn.Params.Add('server=example.com');
204+ conn.Params.Add('port=3306');
205+ conn.Params.Add('database=myDatabase');
206+ conn.Params.Add('charset=utf8');
207+```
242208
243209### MS Access に接続する
244210
245-Please see [[MS Access]].
211+Please see [[MS Access]].
246212
247213### Connecting to Microsoft SQL Server
248214
249-> **Note:** Newer versions than FPC 2.6.0 and Lazarus versions using those support a direct SQLDB connection to MS SQL Server; see [[Lazarus Database Overview|MSSQL]]
250-
251-Use this www.devart.com/odbc/sqlserver/docs/using_odbc_driver.htm mssql odbc driver connection examples which include step by step tutorial and connection strings.
215+![Light bulb](https://upload.wikimedia.org/wikipedia/commons/d/d8/Nuvola_apps_ktip.png) **Note:** FPC 2.6.0、Lazarusより新しいバージョンではMS SQL Server に直接接続をサポートしている。[[Lazarus Database Overview|MSSQL]]を参照されたい
252216
253-See www.connectionstrings.com/sql-server#p7 for more details on connection strings.
217+MS SQLのODBCドライバ接続の詳細と接続文字列の例は www.devart.com/odbc/sqlserver/docs/using_odbc_driver.htmを参照されたい。
254218
255-Microsoft SQL Server ODBC connection string example:
219+www.connectionstrings.com/sql-server#p7 には接続文字列の詳細がある。
256220
257-``` pascal
258-Server=<server name>; // or <server name>\<instance name>
259-Database=<database name>;
221+Microsoft SQL Server ODBC 接続文字列例:
260222```
223+Server=<server name>; // または<server name>\<instance name>
224+ Database=<database name>;
225+```
261226
262227### Oracle に接続する
263228
264-Use this www.devart.com/odbc/oracle/docs/using_odbc_driver.htm odbc oracle connection guide to perform easy and painless connection to Oracle.
265-
266-Oracle ODBC connection string example:
229+簡便で苦痛の少ない接続のためには www.devart.com/odbc/oracle/docs/using_odbc_driver.htm を参照されたい。
267230
268-``` pascal
231+Oracle ODBC 接続文字列例:
232+```
269233Login Prompt=False;
270-Data Source=ORCL;
271-User ID=scott;
272-Password=tiger
234+ Data Source=ORCL;
235+ User ID=scott;
236+ Password=tiger
273237```
274238
275239### PosgreSQLに接続する
276240
277-Use this www.devart.com/odbc/postgresql/docs/using_odbc_driver.htm postgresql odbc connection guide to perform easy and painless connection to PostgreSQL database.
278-
279-PostgreSQL ODBC connection string example:
241+簡便で苦痛の少ない接続のためには www.devart.com/odbc/postgresql/docs/using_odbc_driver.htm を参照されたい。
280242
281-``` pascal
243+PostgreSQL ODBC 接続文字列例:
244+```
282245Login Prompt=False;
283-Data Source=localhost;
284-User ID=postgres;
285-Password=postgres;
286-Database=postgres;
287-Schema=public
246+ Data Source=localhost;
247+ User ID=postgres;
248+ Password=postgres;
249+ Database=postgres;
250+ Schema=public
288251```
289252
290253### SQLite に接続する
291254
292-Use this www.devart.com/odbc/sqlite/docs/using_odbc_driver.htm sqlite odbc connection guide to perform easy and painless connection to SQLite database.
293-
294-SQLite ODBC connection string example:
255+簡便で苦痛の少ない接続のためには www.devart.com/odbc/sqlite/docs/using_odbc_driver.htm を参照されたい。
295256
296-``` pascal
257+SQLite ODBC 接続文字列例:
258+```
297259Login Prompt=False;
298-Database=c:\test.db3
260+ Database=c:\test.db3
299261```
300262
301263### Firebird に接続する
302264
303-Use this www.devart.com/odbc/firebird/docs/using_odbc_driver.htm firebird odbc connection guide to perform easy and painless connection to Firebird database.
304-
305-Firebird ODBC connection string example:
265+簡便で苦痛の少ない接続のためには www.devart.com/odbc/firebird/docs/using_odbc_driver.htm を参照されたい。
306266
307-``` pascal
267+Firebird ODBC 接続文字列例:
268+```
308269Data Source=127.0.0.1;
309-User ID=sysdba;
310-Password=masterkey;
311-Client Library=fbclient.dll;
312-Database=c:\fbd.fdb
270+ User ID=sysdba;
271+ Password=masterkey;
272+ Client Library=fbclient.dll;
273+ Database=c:\fbd.fdb
313274```
314275
315276#### Named DSN
316277
317-On Windows, you can use something like this with an existing named DSN:
318-
319-``` pascal
320- { properties of connection object, i.e. conn: TODBCConnection; }
321- conn.DatabaseName := '<Your_DSN_Name>';
322- { Leave all other conn. properties empty }
278+Windowsではあらかじめ存在するDNSでこのように書ける:
323279```
324-
325-#### DSN-less
280+{ properties of connection object, i.e. conn: TODBCConnection; }
281+ conn.DatabaseName := '<Your_DSN_Name>';
282+ { Leave all other conn. properties empty }
283+```
326284
327-Without a DSN:
285+#### DSN-なし
328286
329-``` pascal
330- { properties of connection object, i.e. conn: TODBCConnection; }
331- conn.Driver := 'SQL Server';
332- // note: driver name doesn't need {} like it does in SQL Connection Strings elsewhere
333- { Leave Hostname and DatabaseName properties empty }
334- { set conn.Params (TStrings) : }
335- conn.Params.Add('Database=<yourdatabasename>');
336- conn.Params.Add('Server=.\SQLEXPRESS');
337- conn.Params.Add('Trusted_Connection=Yes'); // or 'Integrated Security=SSPI'
287+DSNなし:
338288```
339-
340-Note: In this example, we connect to the local machine (server=.), on the instance SQLEXPRESS. You can use a hostname instead of ., and you can omit the instance to connect to the default instance. See MS documentation for details.
289+{ properties of connection object, i.e. conn: TODBCConnection; }
290+ conn.Driver := 'SQL Server';
291+ // 注意: 随所にあるSQL接続文字列例と異なり、ドライバ名は{}を必要としない。
292+ { HostnameとDatabaseNameは空にしておく}
293+ { set conn.Params (TStrings) : }
294+ conn.Params.Add('Database=<yourdatabasename>');
295+ conn.Params.Add('Server=.\SQLEXPRESS');
296+ conn.Params.Add('Trusted_Connection=Yes'); // or 'Integrated Security=SSPI'
297+```
341298
342-Using a trusted connection (also known as integrated security or SSPI) means you login using your Windows user credentials. You can omit the Trusted_Connection line, but then you need to specify user ID (Uid=...) and password (Pwd=...).
299+注意: この例では、インスタンスSQLEXPRESSでローカル端末(server=)に接続している。それに代わりホスト名を用いることができ、デフォルトインスタンスを省略できる。詳しくはMSのドキュメントを参照されたい。
343300
344-#### DSN example
301+信頼性のある接続(統合化セキュリティまたはSSPIとして知られる)はWindowsのユーザー認証でログインすることを意味する。Trusted_Connection lineを省略できるが、ユーザ-ID、(Uid=...)、パスワード(Pwd=...)は指定する必要がある。
345302
346-The example code below selects the rows from a MS SQL Server table called 'journal_entries' and displays all the values of column 'journal_entry' in a Memo control called Memo1.
303+#### DSN 例
347304
348-``` pascal
305+この例ではMS SQL Serverテーブル'journal_entries'という名前のレコードを選択してMemo1という名前のMemoコントロールに'journal_entries'の列の値のすべてを表示する
306+```
349307// uses ODBCConn, sqldb;
350-procedure TForm1.Button1Click(Sender: TObject);
351-var
352- S: String;
353- conn : TODBCConnection; // uses ODBCConn
354- query: TSQLQuery; // uses sqldb
355- transaction: TSQLTransaction; // uses sqldb
356-
357-begin
358- conn := TODBCCOnnection.Create(nil);
359- query := TSQLQuery.Create(nil);
360- transaction := TSQLTransaction.Create(nil);
361- try
362- try
363- conn.DatabaseName := 'sqlserverdsn'; {replace this with your DSN, if you use any}
364- conn.UserName:= 'sa'; //replace with your user name
365- conn.Password:= 'thepassword'; //replace with your password
366- // You can override the properties defined in the DSN, e.g.
367- //conn.Params.Add('Database=some_other_db');
368-
369- conn.Transaction := transaction;
370- query.DataBase := conn;
371- { To avoid "could not retrieve primary key metadata":
372- - either use query.UsePrimaryKeyAsKey:=false
373- or (preferred)
374- - query.PacketRecords to -1
375- If you are using SQL Server, you could alternatively enable MARS in your SQL Native Client ODBC driver.
376- See http://bugs.freepascal.org/view.php?id=13241 }
377- query.PacketRecords:=-1; //retrieve all data at once
378- query.SQL.Text := 'select journal_entry from journal_entries';
379- query.Open;
380- S := '';
381- while not query.EOF do
382- begin
383- S := S + query.FieldByName('journal_entry').AsString + #13#10;
384- query.Next;
308+ procedure TForm1.Button1Click(Sender: TObject);
309+ var
310+ S: String;
311+ conn : TODBCConnection; // uses ODBCConn
312+ query: TSQLQuery; // uses sqldb
313+ transaction: TSQLTransaction; // uses sqldb
314+
315+ begin
316+ conn := TODBCCOnnection.Create(nil);
317+ query := TSQLQuery.Create(nil);
318+ transaction := TSQLTransaction.Create(nil);
319+ try
320+ try
321+ conn.DatabaseName := 'sqlserverdsn'; {replace this with your DSN, if you use any}
322+ conn.UserName:= 'sa'; //自身の名前に変えること
323+ conn.Password:= 'thepassword'; //自身のパスワードに変えることreplace with your password
324+ // DSNで定義するプロパティをオーバーライドできる
325+ //例えば、conn.Params.Add('Database=some_other_db');
326+
327+ conn.Transaction := transaction;
328+ query.DataBase := conn;
329+ { "could not retrieve primary key metadata"を避けるため:
330+ - query.UsePrimaryKeyAsKey:=falseと
331+ (好ましくは)
332+ - query.PacketRecords to -1
333+ もしSQL Server, これに代わりSQL Native Client ODBC ドライバでMARSを有効にする。
334+ http://bugs.freepascal.org/view.php?id=13241を参照されたい。}
335+ query.PacketRecords:=-1; //retrieve all data at once
336+ query.SQL.Text := 'select journal_entry from journal_entries';
337+ query.Open;
338+ S := '';
339+ while not query.EOF do
340+ begin
341+ S := S + query.FieldByName('journal_entry').AsString + #13#10;
342+ query.Next;
343+ end;
344+ finally
345+ query.Free;
346+ conn.Free;
347+ transaction.Free;
348+ end;
349+ except
350+ on E: Exception do
351+ ShowMessage(E.message);
385352 end;
386- finally
387- query.Free;
388- conn.Free;
389- transaction.Free;
353+ Memo1.Text:= S;
390354 end;
391- except
392- on E: Exception do
393- ShowMessage(E.message);
394- end;
395- Memo1.Text:= S;
396-end;
397355```
398356
399-In fact it is possible to use conn.Params for all parts of the connection string, if we modify the above - this time showing the SQL Server version in a pop-up message :
400-
401-``` pascal
402- conn.Params.Add('Driver=SQL Server');
403- conn.Params.Add('Server=OURBIGSERVER');
404- conn.Params.Add('Database=TestDataBase');
405- conn.Params.Add('Integrated Security=SSPI'); // use Windows logon credentials
406- // no other conn. properties set, apart from conn.Transaction := transaction;
407-
408- query.DataBase := conn;
409- query.SQL.Text := 'select @@version';
410- query.Open;
411- showmessage(query.Fields[0].AsString); // Fields are numbered starting from 0
357+実際接続文字列のすべての部分にconn.Paramsを用いることができる。上記を改造すると、今回はSQL Serverバージョンがポップアップメッセージを出す:
412358```
413-
414-Functions are supported - e.g. '`SELECT * FROM MyTestFunc()`' - but there may be issues with *Stored Procedures* that return recordsets. For example, if '`EXEC MyStoredProcedure`' returns data rows (verified in SQL Server Management Studio or with the *SqlCmd* DOS command: `C:\>sqlcmd -S MyServer -E -d MyDataBase -Q "exec MySP"`) then `query.open` will give an error : "Cannot open a non-select statement" (this may be fixed after FPC 2.6)
359+conn.Params.Add('Driver=SQL Server');
360+ conn.Params.Add('Server=OURBIGSERVER');
361+ conn.Params.Add('Database=TestDataBase');
362+ conn.Params.Add('Integrated Security=SSPI'); // use Windows logon credentials
363+ // conn.Transaction := transaction;以外の他の conn. プロパティはセットされない
364+
365+ query.DataBase := conn;
366+ query.SQL.Text := 'select @@version';
367+ query.Open;
368+ showmessage(query.Fields[0].AsString); // Fields are numbered starting from 0
369+```
415370
416-To call a Stored Procedure or to issue other SQL commands that return no rowsets (CREATE,INSERT,UPDATE,DELETE), use `query.ExecSQL` instead of `query.Open`
371+関数がサポートされる、例えば '`SELECT * FROM MyTestFunc()`'- しかし、レコードセットを返す _ストアドプロシージャ_ 問題が起きるかもしれない。 例えば、'`EXEC MyStoredProcedure`'がデータ行を返し、(SQL Server Management Studioや _SqlCmd_ DOSコマンド`C:\>sqlcmd -S MyServer -E -d MyDataBase -Q "exec MySP"`)、次いで`query.open`を行うと以下のエラーが出る: "Cannot open a non-select statement" (おそらくFPC 2.6以降で修正される)
417372
418-Stored Procedure parameters work, e.g. '`EXEC MySP @param1=23`'
373+行のセットを返さないストアドプロシージャまたは他のSQLコマンド(CREATE,INSERT,UPDATE,DELETE)を呼ぶときには、`query.Open`の代わりに `query.ExecSQL`を用いること。
419374
420-The use of *Parameters* is recommended to avoid *SQL injection vulnerabilities*. In this case the SQL statement isn't built with values directly, but a named placeholder is used instead - and then the parameter is specified separately. Using this method it isn't possible to inject malicious SQL commands into variable fields in an attempt to tamper with the database; the server then knows specifically what part of the statement is a value and what is command. For example, instead of building a WHERE clause directly with the value 95 (`'... WHERE field2>95'`), instead use a named parameter like 'testval' -
375+ストアドプロシージャパラメータは例えば'`EXEC MySP @param1=23`'で動く。
421376
422-``` pascal
423- query.SQL.Text := 'select * from mytable where field2>:testval';
424- query.Params.ParamByName('testval').AsString := '95';
425- query.open;
377+パラメータを用いることは、 _SQLインジェクションの脆弱性_ を回避するために推奨される。この場合、SQLステートメントは値を直接生み出さないが、指名された代理人が用いられる。そしてパラメータは別個に指定される。この方法を用いることはデータベースを改竄するための試みにおける、様々なフィールドへの悪意のあるSQLコマンドを挿入することが不可能となる。そしてサーバはステートメントのどの部分が値で何がコマンドであるかが区別がつくようになる。例えば、直接95を組み立てるWHERE句に代わって、指名されたパラメータ'testval'を用いることである。
426378```
379+query.SQL.Text := 'select * from mytable where field2>:testval';
380+ query.Params.ParamByName('testval').AsString := '95';
381+ query.open;
382+```
427383
428384## ODBCデバッグとエラー
429385
430386### トランザクションの問題
431387
432-In Lazarus 1.2.4 (FPC 2.6.4), ODBC transaction behaviour has changed. This may cause previously working code to stop working.
388+Lazarus 1.2.4 (FPC 2.6.4)では ODBC トランザクションの振る舞いが変わった。transaction behaviour has changed. これは以前は動いていたコードが動かなくなる可能性を示唆する。
433389
434-For a solution, see [[User Changes 2.6.4|User_Changes_2.6.4#TODBCConnection_.28odbcconn.29_No_longer_autocommit]]
390+解決には[[User Changes 2.6.4|User_Changes_2.6.4#TODBCConnection_.28odbcconn.29_No_longer_autocommit]]を参照されたい。
435391
436392### エラーメッセージ
437393
438-Each ODBC API call also returns a succes code; if there is an error, more information can be retrieved using calls to `SQLGetDiagRec`. (For the sake of completeness: diagnostic records are also available when an API call returns `SQL_SUCCES_WITH_INFO`.)
394+ODBC APIはいずれもsuccessコードを返す。もしエラーがあったら、`SQLGetDiagRec`を呼ぶことでより詳細な情報が取得できる。(完全性のおかげで: APIコールが`SQL_SUCCES_WITH_INFO`も返すときに診断レコードが利用可能である)
439395
440-`TODBCConnection` checks the return code of each ODBC call and contructs an `EODBCException`. The `message` of this exception consists of:
396+`TODBCConnection`は各種ODBCコールの戻り値を監視し、`EODBCException`を構築する。 この例外の`message`は
441397
442-- a message identifying what the `TODBCConnection` was doing when the error occurred
443-- the return code of the ODBC API call (e.g. `SQL_ERROR`)
444-- a number of diagnostic records (obtained using `SQLGetDiagRec`); each record consists of three fields:
445- - a 5-character error code identifying the error
446- - a 'native error code'
447- - a message describing the error
398+ * エラーが発生したとき`TODBCConnection`が何をしていたか特定するメッセージ
399+ * ODBC APIコールの戻り値
400+ * 診断レコードの数値(`SQLGetDiagRec`を使って得られる); 各々のレコードは3つのフィールドからなる:
401+ * エラーを特定する5文字のエラーコード
402+ * 'ネイティブエラーコード'
403+ * エラーを述べるメッセージ
448404
449-#### Function sequence error
405+#### ファンクションシークエンスエラー
450406
451-If you get a 'Function sequence error' in the finalization section of the `ODBCConn` unit, then you probably did not properly clean up all you queries and connections.
407+もし、`ODBCConn`の最終セクションでファンクションシークエンスエラー('Function sequence error')が生じたら、おそらくすべてのクエリと接続が閉じていない。
452408
453409#### Rollback が効かない
454-
455-If you issue
456-
457-``` pascal
410+```
458411TSQLTransaction.Rollback
459412```
460413
461-commands but your SQL is committed regardless, your ODBC connection probably is in AUTOCOMMIT mode; see [[ODBCConn|the remarks about the AUTOCOMMIT connection parameter]] on how to correct this.
414+の問題に遭遇しているが、SQLはそれにもかかわらずコミットしているのには、ODBC接続はおそらくAUTOCOMMITモードになっている。これをどのようにして修正するには、[[ODBCConn|the remarks about the AUTOCOMMIT connection parameter]] を参照されたい。
462415
463416### 追跡
464417
465-Most ODBC managers have a tracing option in which all ODBC API calls are logged to a trace log. This can be very useful for debugging an ODBC application. The ODBC Data Source Administration GUI of both Windows and unixODBC have a tab where you can configure the tracing option.
418+ほとんどのODBCマネージャは追跡ログへすべてのODBC APIコールのログを記録する、追跡オプションを持っている。 これはODBCアプリケーションををデバッグするときに非常に有用である。 Windows、unixODBCの双方のデータソースアドミニストレーション GUIは追跡オプションを設定するタブを有している。
466419
467-Of course the trace log is mainly useful for developers that are familiar with the ODBC API, but it can help to identify the problem. Also, you can attach a trace log if you report a problem to the bug tracker.
420+もちろんODBC APIに詳しい開発者だけでなく、それは問題を特定するのに役立たせることもできる。また、バグトラッカーに問題を報告するにも追跡ログを活用することができる。
468421
469422## 以下も参照のこと
470423
471-- [[MS Access]] Using ODBC to access Microsoft Access databases
424+ * [[MS Access]] Using ODBC to access Microsoft Access databases
472425
473426---
474-*From the Free Pascal wiki, page "ODBCConn/ja", as it stood on 2024-04-03 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](/wiki-contact).*
427+*From the Free Pascal wiki, page "ODBCConn/ja", as the Internet Archive kept it on 2025-01-17, last changed on 2024-09-25. 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](/wiki-contact).*

Back to history