perldoc DBI::FAQ
"DBIはPerl言語でデータベースにアクセスするためのアプリケーションプログラムインターフェース(API)です。DBI APIの仕様は、実際にデータベースを使用するために、独立した一貫性のあるデータベースインターフェースを供給する機能、変数、方法のセッを定義します。"
シンプル言語であるDBIインターフェースは、ユーザーがマルチタイプのデータベースに直接アクセスすることを可能にします。そして、もしオラクル、Informix、mSQL、サイベースあるいは他のどんなデータベースに接続するときも、あなたは3GLレイヤーの基本構造を知る必要はありません。DBIによって定義されるAPIは、これらすべてのデータベースタイプで動作します。
同様の利点が、perlスクリプト内で異なるベンダーの2つの異なるデータベースに接続することを可能にすることによってえられます。すなわち1つのプログラムでオラクルデータベースからデータを読みたい、Informixデータベースにデータをインサートしたいと言ったような。 DBIはこのようなシンプルで効果的な方法を可能します。
これはその原理を説明した図式です。
DBperlはインターフェースの仕様としては古い名前です。oraperl, isqlperl, ingperl等々は普通perl4モジュールのデータベースインターフェースを意味します。これらのインターフェースはスタンダードなAPIではなく、一般的にサポートもされていません。
これはDBperlモジュールのリストです。それぞれDBIに対応するものと、サポートの情報です。どうぞ記述してください。ここにリストされた著者は一般的に同じデータベースに関してDBIモジュールをメンテナンスしません。これらのemailアドレスは公開され、以下にリストされたperl4モジュールに接続するための質問のためのみに使用されるべきです。DBIドライバーに関する質問はdbi-usersメーリングリストに直接質問してください。
| Module Name | Database Required | Author | DBI |
| Sybperl | Sybase | Michael Peppler | DBD::Sybase <mpeppler@itf.ch> |
| Oraperl | Oracle 6 & 7 | Kevin Stock <dbi-users@fugue.com> | DBD::Oracle |
| Ingperl | Ingres | Tim Bunce & Ted Lemon <dbi-users@fugue.com> | DBD::Ingres |
| Interperl | Interbase | Buzz Moschetti <buzz@bear.com> |
DBD::Interbase |
| Uniperl | Unify 5.0 | Rick Wargo <rickers@coe.drexel.edu> |
None |
| Pgperl | Postgres | Igor Metz <metz@iam.unibe.ch> | DBD::Pg |
| Btreeperl | NDBM | John Conover <john@johncon.com> |
SDBM? |
| Ctreeperl | C-Tree | John Conover <john@johncon.com> |
None |
| Cisamperl | Informix C-ISAM | Mathias Koerber <mathias@unicorn.swi.com.sg> |
None |
| Duaperl | X.500 Directory | Eric Douglas User Agent |
None |
しかしながらいくつかのDBIモジュールはDBperlエミュレーション層を持ちます。それでDBD::OracleがOraperlのエミュレーション層となり、引き継いだoraperlスクリプトを変更せず稼動させることが出来ます。そのエミュレーション層はDBIでコールされるoraperl APIを変換し、DBIスイッチを通してそれらを実行します。
これはエミュレーション層の情報のテーブルです。:
| Module | Emulation Layer | Status |
| DBD::Oracle | Oraperl | Complete |
| DBD::Informix | Isqlperl | Under development |
| DBD::Sybase | Sybperl | Working? ( Needs verification ) |
| DBD::mSQL DBD::mSQL-0.61 |
Msqlperl | Experimentally released with |
Msqlperlエミュレーションは特別なケースです。MsqlperlはmSQLデータベースのためのperl5ドライバーです。しかし、DBIの仕様と一致していません。 その使用はDBD::mSQLの好意に反対を唱えられています。MsqlperlはCPAN viaからダウンロードすることが出来ます。:
http://www.perl.com/cgi-bin/cpan_mod?module=Msqlperl
ftp://ftp.demon.co.uk/pub/perl/db
広範囲にわたるPerlアーカイブネットワークのリソースのローカルミラーサイトは普通遅れがあるので、ドライバーのバージョンアップを入手するために使用されるべきです。CPANはTom Christiansenのすばらしい複合プログラムを経由してアクセス出来ます。
http://www.perl.com/CPAN/
より明確なバージョン情報と正確なドラバーのURLに関してはDBIドライバーリストを参照してください。DBIモジュールのページは以下のURLで参照することが出来ます。
http://www.hermetica.com/technologia/perl/DBI
http://www.hermetica.com/technologia/perl/DBI/doc/dbispec
このリンクで2つの入手可能な詳述情報があります。新しいDBIのドラフトの仕様は開発チームが安定したインターフェースを目指して、迅速にドキュメントに反映されているものと、現在のDBIインターフェースを含まない古い歴史的なDBperlの仕様とがあります。
後のドキュメントは歴史的な興味のみとしてみなされるべきです。そしてそれはプログラミングのマニュアル、あるいはある程度の常識をもった著作物として使われるべきです。しかしながら、それはまだとても役に立つ参考文献です。
perldoc DBI
command.
perldoc Oraperl
これはperl4に関するKevin Stockによって書かれたオリジナルoraperlのmanページをコピーしたものを更新したものです。oraperl APIは完全にリストされ、そこに記述されています。
perldoc DBD::mSQL
perldoc DBI::FAQ
これはインターネットに接続できない人にとってより便利かもしれません。
perldoc perlpod
インストールされているTkモジュールの使用方法はtkpodと呼ばれる使用可能なTkをベースとしたPODリーダーがあることで、習得することに興味がわくかもしれない。そしてそれは使用でき、参照できるPODフォーマットです。
http://www.hermetica.com/technologia/perl/DBI/tidbits
単純なポイントを解明する試みが、かなり広範囲のドキュメントを立案することになってしまう、DBIメーリングリスト上で、種々の人々からの一連の時折のとりとめもなく書かれたものがあります。 品質の面でしばしば変化しますが、インターフェースの働きの中でいくらかの洞察を供給します。
http://www.tpj.com
しかしながら、私たちは完全性の目的のために参考文献を含めます。
おそらくこれはその書籍の目次となるでしょう。
* Introduction
+ Databases
+ CGI / WWW
+ perl
* Basic Database Concepts
+ Types of Database
o Flat File
o AnyDBM
o RDBMS
+ Using Which Database For What...
* SQL
+ Why SQL?
+ Structuring Information In Databases
+ Retrieving Data From Databases
+ Manipulating Data and Data Structures
* DBI Architecture
* Programming with DBI
+ DBI Initialization
+ Handles
o Driver Handles
o Database Handles
o Statement Handles
+ Connection and Disconnection
+ Handling Errors
+ Issuing Simple Queries
+ Executing Atomic Statements
+ Statement MetaData
+ More perl-ish Statements
+ Binding
+ Transaction Handling
+ Utility Methods
+ Handle Attributes and Dynamic Variables
* DBI and ODBC
* The Database Drivers
+ DBD::Oracle and oraperl
+ DBD::Informix and isqlperl
+ DBD::mSQL and Msqlperl
* Case Studies
+ DBI and the WWW
+ Data Migration and Warehousing
+ Administration Software
* Appendix: API Reference / Specification
* Appendix: Resources
http://www.hermetica.com/technologia/perl/DBI
http://www.fugue.com/dbi
ユーザーが参加出来るリストです。:
もしあなたがWWWページ上からの操作で成功しなかった場合は、以下のような書式でリストにsubscribeしてください。:
Email: 'dbi-announce-request@fugue.com' with a message body of
'subscribe'
もしあなたがWWWページ上からメーリングリストへの登録が成功しなかった場合、以下の方法でリストにsubscribeしてください。
Email: 'dbi-dev-request@fugue.com' with a message body of
'subscribe'
もしあなたがWWWページ上での登録出来なかった場合は、次のようにリストにsubscribeしてください。:
Email: 'dbi-users-request@fugue.com' with a message body of
'subscribe'
http://outside.organic.com/mail-archives/dbi-users/
3つのメーリングリストのアーカイブとユーザーがブラウザに対してセットアップした多くの古いトラヒックのいくつかはhypermailで探してください。
http://www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest
As per the US archive above.
http://www.hermetica.com/technologia/perl/DBI
もしその問題が既に分かっている問題ならば、あなたはおそらくそれがフィックスするまで待たなければならないでしょう。もしあなたが本当にそれをフィックスさせたいなら次のことにトライしてください。
私たちはするべき真の仕事をしようと勤めています。私たちは問題に対応するためにメーリングリスト読むようにしています。また私たちは、ここではあなたの好むプラットフォームにアクセスしたことがないかもしれませんし、とにかくサポートすることは出来ません。厳しく聞こえたらすみません。しかしながらそのようにしてください!
しかしながらあなたがたは私たちがどんな方法でもやるべき種類のことをするとき、3amでこれらのクリエイティブな特徴をキャッチできるかもしれません。そして5分内にpatchを得ることが出来るかもしれません。DBIの活動における環境は、私たちが類似した環境で作業してからユーザーの問題を認識することにあります。
もしあなたが著者にメールする予定ならば、出来るだけたくさんの情報を提供してください。 すなわち:
http://www.perl.com/cgi-bin/cpan_mod?module=Devel::CoreStack
Win32ポートのDBIとDBD::Oracleは現在DBIのスタンダードです。0.81以降のバージョンのDBIは快適に動作するはずです。DBD::Oracleのパッチが必要ですのでWin32のportingページを読んでください。
http://www.hermetica.com/technologia/perl/DBI/win32
Contributed by Tim Bunce and Jeff Urlwin
DBI-0.79(以降)で供給されたWin32::ODBCモジュールに対する実験DBIの’エミュレーションレイヤー’です。 Supplied with DBI-0.79 ( and later ) is an experimental DBI 'emulation layer' for the Win32::ODBC module. It's called DBI::W32ODBC and is, at the moment, very minimal. You will need the Win32::ODBC module available from:
http://www.roth.net
Given its status, problem reports without fixes are likely to be ignored. You will also need the Win32 DBI patch kit as supplied by Jeff Urlwin, which you can locate by reading the previous question's answer.
Jeff Urlwin is currently working hard on the ODBC layer.
To get back to the question, theoretically, yes, you can access Microsoft Access and SQL-Server databases from DBI via ODBC!
http://www.hermetica.com/technologia/perl/DBI/DBD
If not, no. A complete absence of a given database driver from that page means that no-one has announced any intention to work on it.
A corollary of the above statement implies that if you see an announcement for a driver not on the above page, there's a good chance it's not actually a DBI driver, and may not conform to the specifications. Therefore, questions concerning problems with that code should not really be addressed to the DBI Mailing Lists.
``UNIX was originally blessed with simple file-based ``databases'', namely
the dbm system. dbm lets you store data in files, and retrieve
that data quickly. However, it also has serious drawbacks.
File Locking
The dbm systems did not allow particularly robust file locking
capabilities, nor any capability for correcting problems arising through
simultaneous writes [ to the database ].
Arbitrary Data Structures
The dbm systems only allows a single fixed data structure:
key-value pairs. That value could be a complex object, such as a
[ C ] struct, but the key had to be unique. This was a large
limitation on the usefulness of dbm systems.
However, dbm systems still provide a useful function for users with
simple datasets and limited resources, since they are fast, robust and
extremely well-tested. Perl modules to access dbm systems have now
been integrated into the core Perl distribution via the
AnyDBM_File module.''
To sum up, DBM is a perfectly satisfactory solution for essentially read-only databases, or small and simple datasets. However, for more powerful and scaleable datasets, not to mention robust transactional locking, users are recommended to use DBI.
func methods private to DBD::mSQL. You can read more about these private methods in the DBD::mSQL POD that can be found by typing:
perldoc DBD::mSQL
provided you have DBD::mSQL correctly installed.
From the current author's point of view, if the dataset is relatively small, being tables of less than 1 million rows, and less than 1000 tables in a given database, then mSQL is a perfectly acceptable solution to your problem. This database is extremely cheap, is wonderfully robust and has excellent support. More information is available on the Hughes Technology WWW site at:
http://www.hughes.com.au
If the dataset is larger than 1 million row tables or 1000 tables, or if you have either more money, or larger machines, I would recommend Oracle7 RDBMS. Oracle's WWW site is an excellent source of more information.
http://www.oracle.com
Informix is another high-end RDBMS that is worth considering. There are several differences between Oracle and Informix which are too complex for this document to detail. Information on Informix can be found on their WWW site at:
http://www.informix.com
In the case of WWW fronted applications, mSQL may be a better option due to slow connection times between a CGI script and the Oracle RDBMS and also the amount of resource each Oracle connection will consume. mSQL is lighter resource-wise and faster.
These views are not necessarily representative of anyone else's opinions, and do not reflect any corporate sponsorship or views. They are provided as-is.
DBI reflects a generic API that will work for most databases, and has no database-specific functionality.
However, driver authors may, if they so desire, include hooks to
database-specific functionality through the func method defined in the DBI API. Script developers should note that use of
functionality provided via
the func methods is unlikely to be portable across databases.
DBI confers the ability to CGI programmers to power WWW-fronted databases to their users, which provides users with vast quantities of ordered data to play with. DBI also provides the possibility that, if a site is receiving far too much traffic than their database server can cope with, they can upgrade the database server behind the scenes with no alterations to the CGI scripts.
Contributed by John D. Groenveld
The Apache httpd maintains a pool of httpd children to service client requests.
Using the Apache mod_perl module by Doug MacEachern, the perl interpreter is embedded with the httpd children. The CGI, DBI, and your other favorite modules can be loaded at
the startup of each child. These modules will not be reloaded unless
changed on disk.
For more information on Apache, see the Apache Project's WWW site:
http://www.apache.org
The mod_perl module can be downloaded from CPAN via:
http://www.perl.com/cgi-bin/cpan_mod?module=mod_perl
Contributed by John D. Groenveld
Using Edmund Mergl's Apache::DBI module, database logins are stored in a hash with each of these httpd child. If your application is based on a single database user, this
connection can be started with each child. Currently, database connections
cannot be shared between httpd children.
Apache::DBI can be downloaded from CPAN via:
http://www.perl.com/cgi-bin/cpan_mod?module=Apache::DBI
httpd, it fails!'' Why?
$ORACLE_HOME, $ORACLE_SID or TWO_TASK.
The httpd process usually runs under the user id of nobody, which implies there is no configured environment. Any scripts attempting
to execute in this situation will correctly fail.
To solve this problem, set the environment for your database in a BEGIN { }
block at the top of your script. This will solve the problem.
Similarly, you should check your httpd error logfile for any clues, as well as the ``Idiot's Guide To Solving Perl
/ CGI Problems'' and ``Perl CGI Programming FAQ'' for further information.
It is unlikely the problem is DBI-related.
The ``Idiot's Guide To Solving Perl / CGI Problems'' can be located at:
http://www.perl.com/perl/faq/index.html
as can the ``Perl CGI Programming FAQ''. Read BOTH these documents carefully!
For some OCI example code for Oracle that has multi-threaded SELECT
statements, see:
http://www.hermetica.com/technologia/oracle/oci/orathreads.tar.gz
$dbh->do to immediately execute the procedure. For example,
$dbh->do( "BEGIN someProcedure END" );
Contributed by Jeff Urlwin
$sth = $dbh->prepare( "BEGIN foo(:1, :2, :3); END;" );
$sth->bind_param(1, $a);
$sth->bind_param_inout(2, \$path, 2000);
$sth->bind_param_inout(3, \$success, 2000);
$sth->execute;
Remember to perform error checking, though!
Some drivers, therefore, support database creation and deletion through the
private func methods. You should check the documentation for the drivers you are using
to see if they support this mechanism.
commit or rollback a statement with DBI?
NULL values handled by DBI?
NULL values in DBI are specified to be treated as the value undef.
NULLs can be inserted into databases as NULL, for example:
$rv =
$dbh->do( "INSERT INTO table VALUES( NULL )" );
but when queried back, the NULLs should be tested against undef. This is standard across all drivers.
func methods all about?
func method is defined within DBI as being an entry point for database-specific
functionality, eg, the ability to create or drop databases. Invoking these driver-specific
methods is simple, for example, to invoke a createDatabase method that has one argument, we would write:
$rv =
$dbh->func( 'argument', 'createDatabase' );
Software developers should note that the func methods are non-portable between databases.
However, some organizations are providing either technical support or training programs on DBI. The present author has no knowledge as to the quality of these services. The links are included for reference purposes only.
http://www.perl.co.uk/tpc
for more details.
http://www-ccs.cs.umass.edu/db.html http://www.odmg.org/odmg93/updates_dbarry.html http://www.jcc.com/sql_stnd.html
This document is Copyright (c)1997 Alligator Descartes. All rights reserved. Permission to distribute this document, in full or in part, via email, Usenet, ftp archives or http is granted providing that no charges are involved, reasonable attempt is made to use the most current version and all credits and copyright notices are retained ( the AUTHOR and COPYRIGHT sections ). Requests for other distribution rights, including incorporation into commercial products, such as books, magazine articles or CD-ROMs should be made to Alligator Descartes <descarte@hermetica.com>.