Next Previous Contents

11. PostgreSQL ªº Perl ¸ê®Æ®w¤¶­± (Database Interface, DBI)

11.1 PostgreSQL ªº PERL 5 ¤¶­±

PERL ¬O¡¥Practical Exptraction and Report Language¡¦ªºÂ²¼g¡C¥@¤W©Ò¦³³nµw¥ó¥­¥x³£¥i¨Ï¥Î Perl¡C§A©Ò¦bµøµ¡ 95/NT¡BÄ«ªG³Áª÷¶ð iMac¡B©Ò¦³ Unix ¡]Solaris¡BHPUX¡BAIX¡BLinux¡BIrix¡BSCO µ¥µ¥¡^¡B¤j«¬¹q¸£ MVS¡B®à­±ªº OS/2¡BOS/400¡BAmdahl UTS ©M¨ä¥L«Ü¦h¹q¸£¡CPerl ¬Æ¦Ü¥i¦b«Ü¦h¤£¬y¦æ©M¤£¬°¤Hª¾ªº¾Þ§@¨t²Î©Mµw¥ó°õ¦æ¡I¡I©Ò¥H¡A¦b¬Ý¨ì Perl ¦b¤@­Ó¨u¨£ªº¾Þ§@¨t²Î¤W°õ¦æ®É¡A¤£¥²¤jÅå¤p©Ç¡C§A¥i¥H·Q¹³¨ì Perl ªº¨Ï¥ÎªÌ©M¶}µo¤H­ûªº¼Æ¶q¡C

PostgreSQL ªº Perl ¤¶­±¤w¥]¬A¦b PostgreSQL ªº´²§G¤¤¡C½Ð°Ñ¬Ý src/pgsql_perl5 ¥Ø¿ý¡C

11.2 Perl ¸ê®Æ®w¤¶­± DBI

¦ó¿× DBI¡H

Perl ¸ê®Æ®w¤¶­±¡]DBI¡^¬O Perl »y¨¥ªº¤@­Ó¸ê®Æ®w¦s¨úÀ³¥Îµ{¦¡¤¶­±¡]API¡^¡CPerl DBI API ³W®æ©w¸q¤F¤@²Õ¨ç¼Æ¡BÅܼƩMºD¨Ò¡A¥H´£¨Ñ¤@­Ó¤@­P¦Ó¿W¥ß©ó¹ê»Ú©Ò¥Îªº¸ê®Æ®w¤¶­±¡C¦³Ãö DBI ªº³o¤@¬qªº¸ê®Æ¬O¨Ó¦Û¡¥DBI FAQ¡¦¤å¥ó¡A§@ªÌ¬O Alligator Descartes¡A¨ÃÀò­ã¦b¦¹½Æ»s¡C

PostgreSQL ªº DBI ÅX°Êµ{¦¡ DBD-Pg-0.89

¦b¦¹¨ú±o DBD-Pg-0.89.tar.gz¡J

¨t²Î»Ý¨D¡J

DBI ªº§Þ³N¤ä´©

½Ð§â·N¨£©M¿ù»~³ø§i±H¨ì

½Ð§â¥H perl -v¡Bperl -V ªº¿é¥X¡BPostgreSQL ªºª©¥»¡BDBD-Pg ªºª©¥»¡BDBI ªºª©¥»¥]¬A¦b¿ù»~³ø§i¤¤¡C

¦ó¿× DBI¡BDBperl¡BOraperl ©M *perl¡H

ºK¿ý¦Û Tim Bunce¡ADBI ªº³]­pªÌ©M§@ªÌ¡J

¡§DBI ¬O Perl »y¨¥ªº¤@ºØÀ³¥Îµ{¦¡¤¶­±¡]API¡^¡CPerl DBI API ³W®æ©w¸q¤F ¤@²Õ¨ç¼Æ¡BÅܼƩMºD¨Ò¡A¥Î©ó´£¨Ñ¤@­Ó¤@­P¦Ó¿W¥ß©ó¹ê»Ú©Ò¥Îªº¸ê®Æ®w¤¶­±¡C¡¨

²³æ¦a»¡¡ADBI ®e³\¥Î®a³z©ú¦a (transparently) ¦s¨ú¦hºØ¸ê®Æ®w¡C©Ò¥H¡A¦pªG§A³s±µ¨ì Oracle¡BInformix¡BmSQL¡BSybase ©Î¥ô¦ó¸ê®Æ®w¡A§A¤£»Ý­nª¾¹D 3GL ¼h­±¤º¸Ìªº¾÷¨î¡CDBI ©Ò©w¸qªº API ¥i¥Î©ó©Ò¦³³o¨Ç¸ê®Æ®w¡C

³o¼Ëªº¦n³B¬O§A±o¨ì¦b¤@½g perl ¤â½Z¤¤³s±µ¨â­Ó¤£¦P¥Xª©°Ó¤£¦Pªº¸ê®Æ®w¡A¨Ò¦p¦b¤@­Óµ{¦¡¤¤Åª¨ú¦b¤@­Ó Oracle ¸ê®Æ®wªº¸ê®Æ¤Î±N¥¦´¡¤J¨ì Informix ¸ê®Æ®w¤¤¡CDBI ¼h­±®e³\§A²³æ¤Î¦³¤O¦a°µ¨ì¡C

DBperl ¬O³o­Ó¤¶­±³W®æªºÂ¦W¡C¥¦²{¦b¤@¯ë¥Î©ó¥Nªí¥Î©ó perl4 ªº¸ê®Æ®w¤¶­±¼Ò²Õ¡A¦p oraperl¡Bisqlperl¡Bingperl ¤§Ãþ¡C³o¨Ç¤¶­±¨S¦³¼Ð·Çªº API¡A¤@¯ë¤w¨S¦³¤ä´©¡C

³o¬O DBperl ¼Ò²Õªº¦W³æ¡A©Ò¹ïÀ³ªº DBI ¼Ò²Õ¤Î§Þ³N¤ä´©¸ê°T¡C¦³Ãö DBI ÅX°Êµ{¦¡ªº°ÝÃDÀ³¸Ó¦b dbi-users ³q°T½×¾Â´£¥X¡C list.

     ¼Ò²Õ¦WºÙ      ©Ò»Ý¸ê®Æ®w        §@ªÌ           DBI
    ----------- -----------------   ------          ---
    Sybperl     Sybase              Michael Peppler DBD::Sybase
                                    <mpeppler@datamig.com>
                                    http://www.mbay.net/~mpeppler
    Oraperl     Oracle 6 & 7        Kevin Stock     DBD::Oracle
                                    <dbi-users@fugue.com>
    Ingperl     Ingres              Tim Bunce &     DBD::Ingres
                                    Ted Lemon
                                    <dbi-users@fugue.com>
    Interperl   Interbase           Buzz Moschetti  DBD::Interbase
                                    <buzz@bear.com>
    Uniperl     Unify 5.0           Rick Wargo      None
                                    <rickers@coe.drexel.edu>
    Pgperl      Postgres            Igor Metz       DBD::Pg
                                    <metz@iam.unibe.ch>
    Btreeperl   NDBM                John Conover    SDBM?
                                    <john@johncon.com>
    Ctreeperl   C-Tree              John Conover    None
                                    <john@johncon.com>
    Cisamperl   Informix C-ISAM     Mathias Koerber None
                                    <mathias@unicorn.swi.com.sg>
    Duaperl     X.500 Directory     Eric Douglas    None
                User Agent
¤£¹L¡A³¡¤À DBI ¼Ò²Õ¦³ DBperl ¼ÒÀÀ¼h (emulation layers)¡A¦]¦¹¡ADBD:Oracle ·|¦³ Oraperl ¼ÒÀÀ¼h¡AÅý§AµL»Ý§ó§ï²{¦sªº Oraperl ¤â½Z«K¯à°õ¦æ¡C³o¼ÒÀÀ¼h§â Oraperl API ©I¥s½Ķ¦¨ DBI ©I¥s¨Ã³q¹L DBI °õ¦æ¡C

³o¦Cªí¬O¼ÒÀÀ¼hªº¸ê®Æ¡J

    ¼Ò²Õ            ¼ÒÀÀ¼h              ª¬ªp
    ------          ---------------     ------
    DBD::Oracle     Oraperl             §¹¦¨
    DBD::Informix   Isqlperl            ¶}µo¤¤
    DBD::Sybase     Sybperl             ¥i¥Î¡H¡]¦³«ÝÅçÃÒ¡^
    DBD::mSQL       Msqlperl            ¦b DBD::mSQL-0.61 ¤¤¹êÅç©Ê±À¥X
Msqlperl ¼ÒÀÀ¬O¯S®í±¡ªp¡CMsqlperl ¬O mSQL ¸ê®Æ®wªº perl5 ÅX°Êµ{¦¡¡A¦ý¤£¨Ì±q DBI ³W®æ¡C¤j®aÀ³¨Ï¥Î DBD::mSQL¡A¦Ó¤£À³¥Î Msqlperl¡CMsqlperl ¥i±q CPAN ¤U¸ü¡J

DBI ³W®æ

³o¸Ì¦³¤@¨Ç DBI ªº¸ê®Æ¨Ó·½¡C

³o·|³sµ²¨ì¤G­Ó³W®æ¡A§Y¶}µo¶¤¥î§V¤Oµo®i¤@­Óí©wªº¤¶­±´Á¶¡¡A¥¿§Ö³t§ó§ïªº·s DBI ³W®æ¯ó®×¡A©M DBperl ³W®æµo®i¦Ó¨Ó¡A¥Ø«eªº DBI ¤¶­±¡C

«áªÌÀ³¥u³Qµø¬°¾ú¥v¬ö¿ý¡A¦Ó¤£¥i¥Î§@µ{¦¡³]­p»¡©ú®Ñ©Î¥ô¦ó¨ãÅv«Â©Êªº¤å¥ó¡C¤£¹L¡A¥¦ÁÙ¬O¤Q¤À¦³¥Îªº°Ñ¦Ò¸ê®Æ¡C

POD ¤å¥ó POD ¬O´O¤J¨ì perl µ{¦¡¤¤¥Î¥H¡§§Y³õ¡¨¸ÑÄÀµ{¦¡½Xªº¤@¬q¤å¥ó¡A¥Î¥H´£¨Ñ ¦³¥Îªº¸ê®Æµ¹µ{¦¡³]­p®v©M¼Ò²Õªº¥Î®a¡CDBI ©MÅX°Êµ{¦¡ªº POD ¥¿¶V¨Ó¶V¬y¦æ¡A­n¾\Ū¦³Ãö¤å¥ó¡A½Ð¨Ï¥Î¥H¤U«ü¥O¡C

DBI ³W®æ ½Ð¨Ï¥Î¥H¤U«ü¥O¾\Ū DBI ³W®æªº POD

perldoc DBI

Oraperl DBD::Oracle ¤¤ Oraperl ¼ÒÀÀ¼hªº¨Ï¥ÎªÌ¥i¥Î¥H¤U«ü¥O¾Ç²ß¦p¦ó¥Î Oraperl ¤¶­±½s¼gµ{¦¡¡J

perldoc Oraperl

³o¼Ë·|²£¥Í¤@¥÷¥Ñ Kevin Stock ¬° perl4 ©Ò¼gªº­ì¸Ë oraperl man page §ó·sª©¡C³o¸Ì·|¥þ­±¦C¥X¤Î¤¶²Ð oraperl API¡C

DBD::mSQL DBD::mSQL ¼Ò²Õªº¥Î®a¥iÄy¥H¤U«ü¥O¾\Ū¤@¨Ç¸ÓÅX°Êµ{¦¡ªº¨p®a¨ç¼Æ (private functions) ©M©Çéqªº¸ê®Æ¡J

perldoc DBD::mSQL

±`¨£°ÝÃD (FAQ) POD ¤å¥ó¤¤¤]¥]§t±`¨£°ÝÃD¡C­n¾\Ūªº¸Ü½Ð¿é¤J¡J

perldoc DBI::FAQ

¹ï¤£¬O¥Ã¤[©Î¤£¯à¤è«K¦a³s±µ¤W¤¬Ápºôªº¤H¨Ó»¡³o¤ñ¸û¤è«K¡J

POD ªº¤@¯ë¸ê®Æ ¦³Ãö POD ¦p¦ó¼¶¼g POD¡A¤Î¤@¯ë¨Ó»¡ªº POD ­õ¾Ç¡A¥iÄy¦¹¾\Ū¡J

perldoc perlpod

¦w¸Ë¤F Tk ¼Ò²Õªº¥Î®a¥i¯à·|¹ï¤@­Ó¦W¬° tkpod¡A¨Ï¥Î Tk ªº POD ¾\Ū¾¹¦³¿³½ì¡C¥¦·|§â POD ½s±Æ¨ì¤@­Ó¤è«K¤Î¥i¾\Ūªº§Î¦¡¡J

¶¢½Í¡B¤p¹D®ø®§©MÆ[¹î¡J ¦b DBI ªº³q«H½×¾Â¤¤¦³¤£¦P¤H´£¥Xªº¤@³s¦ê°¸µMªº¶¢½Í¡C

¡§DBI¡X¡Xperl5 ¸ê®Æ®w¤¶­±¡¨ ¥»¤å¥ó¥Ñ Alligator Descartes ©M Tim Bunce ©Ò¼g¡AÃö©ó DBI ªºµ²ºc¡C¥¦¦b¡§The Perl Journal¡¨²Ä¤­´Á¥Xª©¡C¥¦¼g±o·¥¤§¦n¡C½Ð¶R³o¥»Âø»x¡C¨Æ¹ê¤W¡A½Ð¨C´Á³£¶R¡C¡§The Perl Journal¡¨ªº¤¬Ápºôºô§}¬O¡J

¡§DBperl¡¨ ³o¤å³¹¦b¤@¤E¤E¤»¦~¤Q¤@¤ëªº¡§Dr. Dobbs Journal¡¨µoªí¡A¤º®eÃö©óDBperl¡C

¡§The Perl5 Database Interface¡¨ ³o¬O¤@¥»¥Ñ Alligator Descartes ¼g¡A¥Ñ O'Reilly and Associates ¥Xª©ªº®Ñ¡C

³q«H½×¾Â Ted Lemon Á`¦@ºÞ²z¤T­Ó DBI ªº³q«H½×¾Â¡C¥¦­Ì³£¥i¦b¸Uºûºô¤W­q¾\©Î¨ú®ø ­q¾\¡J

³o¨Ç¥i¥[¤Jªº½×¾Â¬O¡J

dbi-announce ³o³q«H½×¾Â¥u¬O§@¥X«Å§G¡C¦pªG§A¤£¯à¦¨¥\¨Ï¥Î¥H¤Wºô§}ªºªí®æ¡A½Ð´`¥H¤U³~®|­q¾\³o½×¾Â¡J

dbi-dev ³o³q«H½×¾Â¥Øªº¬OÅý¶}µo¤H­û°Q½×¦³Ãö DBI ¤¶­±¡BAPI ©MÅX°Êµ{¦¡¾÷¨îªº·N¨£©M·§©À¡C¥u¹ï¶}µo¤H­û©Î¦³¿³½ìªº¤H¦³¥Î¡C¦pªG§A¤£¯à¦¨¥\¨Ï¥Î¥H¤Wºô§}ªºªí®æ¡A½Ð´`¥H¤U³~®|­q¾\³o½×¾Â¡J

dbi-users ³o³q«H½×¾Â¬O¥Î§@¿ù»~³ø§i¡B°ÝÃD°Q½×©M¤@¯ë°ÝÃD¡C¦pªG§A¤£¯à¦¨¥\¨Ï¥Î¥H¤Wºô§}ªºªí®æ¡A½Ð´`¤U³~®|­q¾\³o½×¾Â¡J

³q«HÀx¦s³B (Mailing List Archives)¡J

½sĶ¿ù»~©Î¡u´ú¸Õ¥¢±Ñ¡v

¦pªGµo¥Í°T®§ÂàÀx (core dump)¡A¹Á¸Õ¨Ï¥Î Devel::CoreStack ¼Ò²Õ¨Ó²£¥Í°T®§ÂàÀxªº°ïÅ|°lÂÜ (stack trace)¡CDevel::CoreStack ¥i¦b CPAN §ä¨ì¡J

§â°ïÅ|°lÂÜ¡B¼Ò²Õª©¥»¡Bperl ª©¥»¡B´ú¸Õ­Ó®×¡B¾Þ§@¨t²Îª©¥»¤Î¥ô¦ó¨ä¥L¾A¥Îªº¸ê®Æ¹q¶l¨ì dbi-users ³q«H½×¾Â¡C±H¥Xªº¸ê®Æ¶V»ô¥þ¡A¶}µo¤H­û¶V§Ö¸Ñ¨M°ÝÃD¡C¦pªG§A¤£§i¶D§Ú­Ì¡A¤£­n´Á±æ±o¨ìµª®×¡C

µøµ¡ 95/NT ¦³¨S¦³ DBI ¤ä´©¡H

DBI ©M DBD::Oracle ªº Win32 ª©¥»¤w¦¨¬° DBI ªº¼Ð·Ç³¡¤À¡C¦]¦¹¡A¤ñ DBI 0.81 °ªªºª©¥»À³¸Ó·|¥¿±`¹B§@¡C³z¹L ODBC¡A§A¥i¥H¦s¨ú·L³n Access ©M SQL-Server ¸ê®Æ®w¡C¦b DBI-0.79¡]¤Î¥H«á¡^¦³¤@­Ó¹êÅç©Ê½èªº Win32::ODBC DBI ¼ÒÀÀ¼h¡C¥¦¦W¬° DBI::W32ODBC¡C§A»Ý­n¨Ï¥Î Win32::odbc ¼Ò²Õ¡C

¦ó¿× DBM¡H¬°¦ó­n¥Î DBI¡H

UNIX ­ì¥»¬O¨Ï¥Î²³æ¥HÀɮ׬°°ò¦ªº¡u¸ê®Æ®w¡v¡A§Y dbm ¨t²Î¡Cdbm ®e³\§A¦bÀɮקֳt¦a¦s¨ú¸ê®Æ¡C¤£¹L¡A¥¦¦³¼Æ­ÓÄY­«ªº¯ÊÂI¡C

Àɮ׫ÊÂê (File Locking)

dbm ¨t²Î¤£®e³\¯S§O¥þ­±ªºÀɮ׫ÊÂê¯à¤O¡A¤]¨S¦³­×¥¿¦P®É¼g¤J¸ê®Æ®w¤Þ°_ªº°ÝÃDªº¯à¤O¡C

ÀH·Nªº¸ê®Æµ²ºc

dbm ¨t²Î¥u®e³\³æ¤@©T©wªº¸ê®Æµ²ºc¡JÃì-¼Æ­È¹ï (key-value pair)¡C¨º¼Æ­È¥i¥H¬O½ÆÂøªºª«¥ó¡A¦p¤@­Ó C ªº struct¡A¦ýÃ쥲¶·¬O¿W¤@µL¤Gªº¡C³o¹ï dbm ¨t²Îªº¥Î³~³y¦¨«Ü¤j­­¨î¡C

¤£¹L¡Adbm ¨t²Î¤´¬°¨Ï¥Î²³æ¸ê®Æ¤Î¸ê·½¦³­­ªº¥Î®a´£¨Ñ¤F¦³¥Îªº¥\¯à¡A¦]¬°¥¦§Ö³t¡B¥þ­±¤Î¸g¹L·¥ÄYÂÔªº´ú¸Õ¡C¦s¨ú dbm ¨t²Îªº¼Ò²Õ²{¤w¸g AnyDBM_File ¼Ò²Õ¾ã¦X¨ì Perl ªº®Ö¤ß´²§G¤¤¡C

Á`¬A¤@¥y¡A¹ïªñ¥G¬O°ßŪªº¸ê®Æ®w©Î¤p«¬¦Ó²³æªº¸ê®Æ¨Ó»¡¡Adbm ¬O¤@­Ó«D±`¥O¤Hº¡·Nªº¸Ñ¨M¤èªk¡C¤£¹L¡A¹ï§ó±j¤j©M¥i¼W´î (scalable) ªº¸ê®Æ¶°¨Ó»¡¡A¥Î®a³Ì¦n¨Ï¥Î DBI¡C¦Ü©ó¥þ­±ªº¥æ©ö«ÊÂê (transactional locking)¡A´N§ó¤£¥Î»¡¤F¡CÓ

DBI ¬O§_¤ä´©<³o¶µ¥\¯à>¡H

®Ú¾Ú©Ò´£¥Xªº¥\¯à¬O¤@­Ó¨Ã¤£¼Ð·Ç¡A¦Ó¥u¬°³¡¤À¸ê®Æ®w©Ò¿W¦³ªº°²³]¡Aµª®×¬O§_¡C

DBI ¤Ï¬M¤@­Ó³q¥Î¦Ó¥i¦b¤j³¡¤À¸ê®Æ®w¨Ï¥Îªº API¡A¦Ó¨S¦³¸ê®Æ®w¿W¦³ªº¥\¯à¡C

¤£¹L¡A¦pªGÅX°Êµ{¦¡ªº§@ªÌ¦³¿³½ì¡A¥L­Ì¥i¥HÄy DBI ¤¶­±©Ò©w¸qªº func method ¨Ó¥[¤W¸ê®Æ®w¿W¦³ªº¥\¯à¡C©R¥O½Zªº¶}µo¤H­û­nª`·NÄy func methods ´£¨Ñªº¥\¯à¤@¯ë¤£¯à¦b¤£¦P¸ê®Æ®w¶¡²¾´Ó¡C

¹ï CGI ¨Ó»¡¡Adbi ¦³¨S¦³¥Î¡H

¤@­Ó¦r¡J¦³¡IDBI ¹ï CGI µ{¦¡³]­p«D±`¦³¥Î¡I¨Æ¹ê¤W¡ACGI ¬O DBI ³Ì­«­nªº¥Î³~¤§¤@¡C

DBI Åý CGI µ{¦¡³]­p®v³]­p¥\¯à±j¤jªº¤¬Ápºô«eºÝ¸ê®Æ®wµ¹¥L­Ìªº¥Î®a¡A±q¦Ó´£¨Ñ¤j¶q«ö¦¸§Ç±Æ¦Cªº¸ê®Æ¡CDBI ¤]®e³\¦bºô¯¸ªº¸ê®Æ®w¦øªA¾¹¶W¹L­t²ü®É¡AºÞ²z¤H­û¦bµL¶·§ó§ï CGI ©R¥O½Zªº±¡ªp¤U±N¤§¤É¯Å¡C

§Ú¦p¦ó¥[§Ö CGI »P DBD Oracle ªº³s±µ³t«×¡H

Apache httpd ºÞ²z¤@²Õ¤l httpd (httpd children) ¨ÓªA°È«È¤á¡CÄyµÛ Doug MacEachern ªº Apache mod_perl ¼Ò²Õ¡Aperl ½Ķ¾¹¤w´O¤J¨ì¤l httpd ¤¤¡CCGI¡BDBI ©M§A³ßÅwªº¼Ò²Õ·|¦b¨à¤l½Ï¥Í®É¸ü¤J¡C³o¨Ç¼Ò²Õª½¨ì¦bºÏºÐ¤Wªºª©¥»³Q§ó§ï®É¤~·|¦A³Q¸ü¤J¡C­nª¾¹D§ó¦h¦³Ãö Apache ªº¸ê®Æ¡A½Ð¬Ý Apache ­p¹ºªººô¯¸¡J

¦p¦ó¨Ï DBI ©M CGI «ùÄò³s±µ¡H

ÄyµÛ Edmund Mergl ªº Apache::DBI ¼Ò²Õ¡A¨C­Ó¤l httpd ·|§â¸ê®Æ®wµn¤JÀx¦s¦bÂø´ê (hash) ¤¤¡C¦pªG§AªºÀ³¥Îµ{¦¡¥u¦³¤@­Ó¸ê®Æ®w¥Î®a¡A¨C¤@­Ó¨à¤l³£¥i¶}©l³s³s¡C¥Ø«e¡A¨à¤l¤§¶¡¨Ã¤£·|¤À¨É¸ê®Æ®w³s±µ¡CApache::DBI ¥i±q CPAN ¤U¸ü¡J

¡§§Ú¦b«ü¥O¦æ°õ¦æ¤@­Ó perl ©R¥O½Z®É¡A¨ÃµL°ÝÃD¡C¤£¹L¡A·í§Ú¦b http °õ¦æ¥¦®É¡A¥¦·|¥¢±Ñ¡I¡¨¦ó¸Ñ¡H

°ò¥»¤W¡A³o«Ü¦³¥i¯à¬O¦]¬°±q«ü¥O¦æ°õ¦æ©R¥O½Zªº¨Ï¥ÎªÌ¤w§âÀô¹ÒÅܼƳ]©w¦n¡A¥H DBD::Oracle ¨Ó»¡¡A§Y $ORACLE_HOME, $ORACLE_SID ©Î TWO_TASK¡Chttpd ¦æµ{³q±`¬O¥H nobody ªº¨­¥÷°õ¦æ¡A§Y¨S¦³¤F³]©w¦nªºÀô¹Ò¡C¥ô¦ó¦b³o±¡ªp¤U¹Á¸Õ°õ¦æªº¤â½Z³£·|¥¿½T¦a¥¢±Ñ¡C­n¸Ñ¨M³o°ÝÃD¡A¦b§Aªº©R¥O½Zªº¶}ÀY¥Î¤@­Ó BEGIN() °Ï¶ô³]©wÀô¹Ò¡C³o¼Ë«K·|¸Ñ¨M°ÝÃD¡C¦P¼Ë¦a¡A§A­nÀˬd§Aªº httpd ¿ù»~¬ö¿ýÀÉ¥H´M§ä½u¯Á¡A¥H¤Î¾\Ū¡§Idiot's Guide To Solving Perl / CGI Problems¡¨©M¡§Perl CGI Programming FAQ¡¨¥H´M§ä§ó¦h¸ê®Æ¡C³o°ÝÃD¤j·§¤£·|©M DBI ¦³Ãö¡C½Ð¨â¥÷¤å¥ó³£¤p¤ß¾\Ū¡I

¨Ï¥Î DBI ®É¡A§Ú¯à§_¶i¦æ¦h¬y³B²z (multi-threading)¡H

¥Ø«e¤£¯à¡CPerl ¨Ã¤£¤ä´©¦h¬y³B²z¡C¤£¹L¡A¾Ú¦ô­p¡A¦h¬y³B²z·|¦¨¬° 5.005 ª©ªº°ò¥»´²§Gªº¤@³¡¤À¡A§Y¤£¤[¤§«á¡ADBI ¥i¯à·|¤ä´©¦h¬y³B²z¡C­n¬Ý¤@¨Ç¨Ï¥Î¦h¬y SELECT ¥y¤lªº Oracle OCI ½d¨Òµ{¦¡¡A½Ð°Ñ¾\¡J

§Ú¦p¦ó¥Î DBI ©I¥s¤ºÀxµ{§Ç (stored procedure)¡H

°²³]§A¦b¥Ø¼Ð¸ê®Æ®w¡A¨Ò¦p¤@­Ó Oracle ¸ê®Æ®w¤¤«Ø¥ß¤F¤ºÀxµ{§Ç¡A§A¥i¨Ï¥Î $dbh->do ¨Ó¨Ïµ{§Ç¥ß§Y°õ¦æ¡C¨Ò¦p¡J

$dbh->do( "BEGIN someProcedure END" );

¦b DBI ¤¤¡A§Ú¦p¦ó¨ú¦^¤ºÀxµ{§Çªºªð¦^­È¡H

°OµÛÁÙ­nÀˬd¿ù»~¡I

    $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;

§Ú¥i§_¥Î DBI ¨Ó¥á±ó¤@­Ó¸ê®Æ®w¡H

¹ï DBI ¨Ó»¡¡A­n¾A·í¦a¤ä´©¸ê®Æ®wªº«Ø¥ß©M¥á±ó¤Ó©â¶H¤F¡C¨Ò¦p¡AOracle ®Ú¥»¤£¤ä´©¥á±ó¸ê®Æ®w¡I¦¹¥~¡A¦b Oracle ¤¤¡A¸ê®Æ®w¦øªA¾¹°ò¥»¤W´N¬O¸ê®Æ®w¡A¦ý¦b mSQL¡A§Y¨Ï¨S¦³¸ê®Æ®w¡A¦øªA¾¹¤]¯à¶¶§Q¦a°õ¦æ¡C³o°ÝÃD²o³s¤Ó¼s¤F¡C¥¿¦]¦p¦¹¡A³¡¤ÀÅX°Êµ{¦¡³z¹L¨p®a func ¤èªk¨Ó«Ø¥ß©M§R°£¸ê®Æ®w¡C§A­nÀˬdÅX°Êµ{¦¡ªº¤å¥ó¨Ó¤F¸Ñ¥¦¦³¨S¦³¤ä´©³o¾÷¨î¡C

DBI «ç¼Ë³B²z NULL ­È¡H

DBI ³Q«ü©w§â NULL ­È·í§@ undef ­È³B²z¡CNULL ¥i¥H NULL ªº¼Æ­È¨Ó¥[¤J¨ì¸ê®Æ®w¤¤¡A¨Ò¦p¡J

    $rv = $dbh->do( "INSERT INTO table VALUES( NULL )" );
¤£¹L·í¬d¸ß®É¡ANULL ­n©M undef ¤ñ¸û¡C³o¬O©Ò¦³ÅX°Êµ{¦¡³£¾A¥Îªº¼Ð·Ç¡C

³o¨Ç func ¤èªk¬O°µ¤°»òªº¡H

DBI §â func ¤èªk©w¸q¬°¸ê®Æ®w¿W¦³¥\¯àªº¶i¤JÂI¡A¨Ò¦p«Ø¥ß©M¥á±ó¤@­Ó¸ê®Æ®w¡C¨Ï¥Î³o¨ÇÅX°Êµ{¦¡¿W¦³¤èªk¤Q¤À²³æ¡A¨Ò¦p¡A­n¨Ï¥Î¤@­Ó createDatabase ¤èªk¿é¤J¤@­Ó¤Þ¼Æ (argument) ¡A§Ú­Ì·|¼g¡J

    $rv = $dbh->func( 'argument', 'createDatabase' );
³n¥ó¶}µo¤H­û­nª`·N func ¤èªk¤£¯à¦b¤£¦P¸ê®Æ®w¶¡²¾´Ó¡C

°Ó·~¤ä´©¤Î°V½m

Perl5 ¸ê®Æ®w¤¶­±¬O¦Û¥Ñ³nÅé¡C¥¦¨Ã¨S¦³¥ô¦ó¾á«O (warranty)¡C¤£¹L¡A¦³¨Ç¾÷ºc´£¨Ñ¤F DBI ªº§Þ³N¤ä´©©Î°ö°V­p¹º¡C

PERL CLINIC : Perl Clinic ¥H¦X¬ù§Î¦¡¬° Perl¡BDBI¡BDBD::Oracle ©M Oraperl ´£¨Ñ°Ó·~¤ä´©¡C³o¨Ç¤ä´©¬O¥Ñ DBI §@ªÌ Tim Bunce ¤u§@ªº¤½¥q´£¨Ñªº¡C±ýª¾¸Ô±¡¡A½Ð¬Ý¡J


Next Previous Contents