1DBI::FAQ(3)           User Contributed Perl Documentation          DBI::FAQ(3)
2
3
4

NAME

6       DBI::FAQ -- The Frequently Asked Questions for the Perl5 Database
7       Interface
8

SYNOPSIS

10           perldoc DBI::FAQ
11

VERSION

13       This document is currently at version 0.38, as of February 8th, 2000.
14

DESCRIPTION

16       This document serves to answer the most frequently asked questions on
17       both the DBI Mailing Lists and personally to members of the DBI devel‐
18       opment team.
19

Basic Information & Information Sources

21       1.1 What is DBI, DBperl, Oraperl and *perl?
22
23       To quote Tim Bunce, the architect and author of DBI:
24
25           ``DBI is a database access Application Programming Interface (API)
26             for the Perl Language. The DBI API Specification defines a set
27             of functions, variables and conventions that provide a consistent
28             database interface independant of the actual database being used.''
29
30       In simple language, the DBI interface allows users to access multiple
31       database types transparently. So, if you connecting to an Oracle,
32       Informix, mSQL, Sybase or whatever database, you don't need to know the
33       underlying mechanics of the 3GL layer. The API defined by DBI will work
34       on all these database types.
35
36       A similar benefit is gained by the ability to connect to two different
37       databases of different vendor within the one perl script, ie, I want to
38       read data from an Oracle database and insert it back into an Informix
39       database all within one program. The DBI layer allows you to do this
40       simply and powerfully.
41
42       DBperl is the old name for the interface specification. It's usually
43       now used to denote perl4 modules on database interfacing, such as,
44       oraperl, isqlperl, ingperl and so on. These interfaces didn't have a
45       standard API and are generally not supported.
46
47       Here's a list of DBperl modules, their corresponding DBI counterparts
48       and support information. Please note, the author's listed here gener‐
49       ally do not maintain the DBI module for the same database. These email
50       addresses are unverified and should only be used for queries concerning
51       the perl4 modules listed below. DBI driver queries should be directed
52       to the dbi-users mailing list.
53
54           Module Name Database Required   Author          DBI
55           ----------- -----------------   ------          ---
56           Sybperl     Sybase              Michael Peppler DBD::Sybase
57                                           <mpeppler@itf.ch>
58           Oraperl     Oracle 6 & 7        Kevin Stock     DBD::Oracle
59                                           <dbi-users@perl.org>
60           Ingperl     Ingres              Tim Bunce &     DBD::Ingres
61                                           Ted Lemon
62                                           <dbi-users@perl.org>
63           Interperl   Interbase           Buzz Moschetti  DBD::Interbase
64                                           <buzz@bear.com>
65           Uniperl     Unify 5.0           Rick Wargo      None
66                                           <rickers@coe.drexel.edu>
67           Pgperl      Postgres            Igor Metz       DBD::Pg
68                                           <metz@iam.unibe.ch>
69           Btreeperl   NDBM                John Conover    SDBM?
70                                           <john@johncon.com>
71           Ctreeperl   C-Tree              John Conover    None
72                                           <john@johncon.com>
73           Cisamperl   Informix C-ISAM     Mathias Koerber None
74                                           <mathias@unicorn.swi.com.sg>
75           Duaperl     X.500 Directory     Eric Douglas    None
76                       User Agent
77
78       However, some DBI modules have DBperl emulation layers, so, DBD::Oracle
79       comes with an Oraperl emulation layer, which allows you to run legacy
80       oraperl scripts without modification. The emulation layer translates
81       the oraperl API calls into DBI calls and executes them through the DBI
82       switch.
83
84       Here's a table of emulation layer information:
85
86           Module                  Emulation Layer     Status
87           ------          ---------------     ------
88           DBD::Oracle     Oraperl             Complete
89           DBD::Informix   Isqlperl            Under development
90           DBD::Ingres     Ingperl             Complete?
91           DBD::Sybase     Sybperl             Working? ( Needs verification )
92           DBD::mSQL       Msqlperl            Experimentally released with
93                                               DBD::mSQL-0.61
94
95       The Msqlperl emulation is a special case. Msqlperl is a perl5 driver
96       for mSQL databases, but does not conform to the DBI Specification. It's
97       use is being deprecated in favour of DBD::mSQL. Msqlperl may be down‐
98       loaded from CPAN via:
99
100           http://www.perl.com/cgi-bin/cpan_mod?module=Msqlperl
101
102       1.2. Where can I get it from?
103
104       The Comprehensive Perl Archive Network resources should be used for
105       retrieving up-to-date versions of the DBI and drivers. CPAN may be
106       accessed via Tom Christiansen's splendid CPAN multiplexer program
107       located at:
108
109           http://www.perl.com/CPAN/
110
111       For more specific version information and exact URLs of drivers, please
112       see the DBI drivers list and the DBI module pages which can be found
113       on:
114
115           http://dbi.perl.org/
116           http://www.symbolstone.org/technology/perl/DBI
117
118       This list is automatically generated on a nightly basis from CPAN and
119       should be up-to-date.
120
121       1.3. Where can I get more information?
122
123       There are a few information sources on DBI.
124
125       "Programming the Perl DBI"
126           "Programming the Perl DBI" is the official book on the DBI written
127           by Alligator Descartes and Tim Bunce and published by O'Reilly &
128           Associates.  The book was released on February 9th, 2000.
129
130           The table of contents is:
131
132               Preface
133               1. Introduction
134                   From Mainframes to Workstations
135                   Perl
136                   DBI in the Real World
137                   A Historical Interlude and Standing Stones
138               2. Basic Non-DBI Databases
139                   Storage Managers and Layers
140                   Query Languages and Data Functions
141                   Standing Stones and the Sample Database
142                   Flat-File Databases
143                   Putting Complex Data into Flat Files
144                   Concurrent Database Access and Locking
145                   DBM Files and the Berkeley Database Manager
146                   The MLDBM Module
147                   Summary
148               3. SQL and Relational Databases
149                   The Relational Database Methodology
150                   Datatypes and NULL Values
151                   Querying Data
152                   Modifying Data Within Tables
153                   Creating and Destroying Tables
154               4. Programming with the DBI
155                   DBI Architecture
156                   Handles
157                   Data Source Names
158                   Connection and Disconnection
159                   Error Handling
160                   Utility Methods and Functions
161               5. Interacting with the Database
162                   Issuing Simple Queries
163                   Executing Non-SELECT Statements
164                   Binding Parameters to Statements
165                   Binding Output Columns
166                   do() Versus prepare()
167                   Atomic and Batch Fetching
168               6. Advanced DBI
169                   Handle Attributes and Metadata
170                   Handling LONG/LOB Data
171                   Transactions, Locking, and Isolation
172               7. ODBC and the DBI
173                   ODBC -- Embraced and Extended
174                   DBI -- Thrashed and Mutated
175                   The Nuts and Bolts of ODBC
176                   ODBC from Perl
177                   The Marriage of DBI and ODBC
178                   Questions and Choices
179                   Moving Between Win32::ODBC and the DBI
180                   And What About ADO?
181               8. DBI Shell and Database Proxying
182                   dbish -- The DBI Shell
183                   Database Proxying
184               A. DBI Specification
185               B. Driver and Database Characteristics
186               C. ASLaN Sacred Site Charter
187               Index
188
189           The book should be available from all good bookshops and can be
190           ordered online either <I>via</I> O'Reilly & Associates
191
192               http://www.oreilly.com/catalog/perldbi
193
194           or Amazon
195
196               http://www.amazon.com/exec/obidos/ASIN/1565926994/dbi
197
198       POD documentation
199           PODs are chunks of documentation usually embedded within perl pro‐
200           grams that document the code ``in place'', providing a useful
201           resource for programmers and users of modules. POD for DBI and
202           drivers is beginning to become more commonplace, and documentation
203           for these modules can be read with the "perldoc" program included
204           with Perl.
205
206           The DBI Specification
207               The POD for the DBI Specification can be read with the:
208
209                   perldoc DBI
210
211               command. The Specification also forms Appendix A of "Program‐
212               ming the Perl DBI".
213
214           Oraperl
215               Users of the Oraperl emulation layer bundled with DBD::Oracle,
216               may read up on how to program with the Oraperl interface by
217               typing:
218
219                   perldoc Oraperl
220
221               This will produce an updated copy of the original oraperl man
222               page written by Kevin Stock for perl4. The oraperl API is fully
223               listed and described there.
224
225           Drivers
226               Users of the DBD modules may read about some of the private
227               functions and quirks of that driver by typing:
228
229                   perldoc <driver>
230
231               For example, the DBD::mSQL driver is bundled with driver-spe‐
232               cific documentation that can be accessed by typing
233
234                   perldoc DBD::mSQL
235
236           Frequently Asked Questions
237               This document, the Frequently Asked Questions is also available
238               as POD documentation! You can read this on your own system by
239               typing:
240
241                   perldoc DBI::FAQ
242
243               This may be more convenient to persons not permanently, or con‐
244               veniently, connected to the Internet. The DBI::FAQ module
245               should be downloaded and installed for the more up-to-date ver‐
246               sion.
247
248               The version of DBI::FAQ shipped with the "DBI" module may be
249               slightly out of date.
250
251           POD in general
252               Information on writing POD, and on the philosophy of POD in
253               general, can be read by typing:
254
255                   perldoc perlpod
256
257               Users with the Tk module installed may be interested to learn
258               there is a Tk-based POD reader available called "tkpod", which
259               formats POD in a convenient and readable way. This is available
260               via CPAN as the module called Tk::POD and is highly recom‐
261               mended.
262
263       Driver and Database Characteristics
264           The driver summaries that were produced for Appendix B of "Program‐
265           ming the Perl DBI" are available online at:
266
267               http://dbi.perl.org/
268               http://www.symbolstone.org/technology/perl/DBI
269
270           in the driver information table. These summaries contain standard‐
271           ised information on each driver and database which should aid you
272           in selecting a database to use. It will also inform you quickly of
273           any issues within drivers or whether a driver is not fully compli‐
274           ant with the DBI Specification.
275
276       Rambles, Tidbits and Observations
277               http://dbi.perl.org/tidbits
278               http://www.symbolstone.org/technology/perl/DBI/tidbits
279
280           There are a series of occasional rambles from various people on the
281           DBI mailing lists who, in an attempt to clear up a simple point,
282           end up drafting fairly comprehensive documents. These are quite
283           often varying in quality, but do provide some insights into the
284           workings of the interfaces.
285
286       Articles
287           A list of articles discussing the DBI can be found on the DBI WWW
288           page at:
289
290               http://dbi.perl.org/
291               http://www.symbolstone.org/technology/perl/DBI
292
293           These articles are of varying quality and age, from the original
294           Perl Journal article written by Alligator and Tim, to more recent
295           debacles published online from about.com.
296
297       README files
298           The README files included with each driver occasionally contains
299           some useful information ( no, really! ) that may be pertinent to
300           the user.  Please read them. It makes our worthless existences more
301           bearable. These can all be read from the main DBI WWW page at:
302
303               http://dbi.perl.org/
304               http://www.symbolstone.org/technology/perl/DBI
305
306       Mailing Lists
307           There are three mailing lists for DBI:
308
309               dbi-announce@perl.org     -- for announcements, very low traffic
310               dbi-users@perl.org        -- general user support
311               dbi-dev@perl.org          -- for driver developers (no user support)
312
313           For information on how to subscribe, set digest mode etc, and
314           unsubscribe, send an email message (the content will be ignored)
315           to:
316
317               dbi-announce-help@perl.org
318               dbi-users-help@perl.org
319               dbi-dev-help@perl.org
320
321       Mailing List Archives
322           US Mailing List Archives
323                   http://outside.organic.com/mail-archives/dbi-users/
324
325               Searchable hypermail archives of the three mailing lists, and
326               some of the much older traffic have been set up for users to
327               browse.
328
329           European Mailing List Archives
330                   http://www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest
331
332               As per the US archive above.
333

Compilation Problems

335       2.1. Compilation problems or "It fails the test!"
336
337       First off, consult the README for that driver in case there is useful
338       information about the problem. It may be a known problem for your given
339       architecture and operating system or database. You can check the README
340       files for each driver in advance online at:
341
342           http://dbi.perl.org/
343           http://www.symbolstone.org/technology/perl/DBI
344
345       If it's a known problem, you'll probably have to wait till it gets
346       fixed. If you're really needing it fixed, try the following:
347
348       Attempt to fix it yourself
349           This technique is generally not recommended to the faint-hearted.
350           If you do think you have managed to fix it, then, send a patch file
351           ( context diff ) to the author with an explanation of:
352
353           *   What the problem was, and test cases, if possible.
354
355           *   What you needed to do to fix it. Please make sure you mention
356               everything.
357
358           *   Platform information, database version, perl version, module
359               version and DBI version.
360
361       Email the author Do NOT whinge!
362           Please email the address listed in the WWW pages for whichever
363           driver you are having problems with. Do not directly email the
364           author at a known address unless it corresponds with the one
365           listed.
366
367           We tend to have real jobs to do, and we do read the mailing lists
368           for problems. Besides, we may not have access to <insert your
369           favourite brain-damaged platform here> and couldn't be of any
370           assistance anyway! Apologies for sounding harsh, but that's the way
371           of it!
372
373           However, you might catch one of these creative genii at 3am when
374           we're doing this sort of stuff anyway, and get a patch within 5
375           minutes. The atmosphere in the DBI circle is that we do appreciate
376           the users' problems, since we work in similar environments.
377
378           If you are planning to email the author, please furnish as much
379           information as possible, ie:
380
381           *   ALL the information asked for in the README file in the prob‐
382               lematic module. And we mean ALL of it. We don't put lines like
383               that in documentation for the good of our health, or to meet
384               obscure README file standards of length.
385
386           *   If you have a core dump, try the Devel::CoreStack module for
387               generating a stack trace from the core dump. Send us that too.
388               Devel::CoreStack can be found on CPAN at:
389
390                   http://www.perl.com/cgi-bin/cpan_mod?module=Devel::CoreStack
391
392           *   Module versions, perl version, test cases, operating system
393               versions and any other pertinent information.
394
395           Remember, the more information you send us, the quicker we can
396           track problems down. If you send us no useful information, expect
397           nothing back.
398
399           Finally, please be aware that some authors, including Tim Bunce,
400           specifically request that you do not mail them directly. Please
401           respect their wishes and use the email addresses listed in the
402           appropriate module "README" file.
403
404       Email the dbi-users Mailing List
405           It's usually a fairly intelligent idea to cc the mailing list any‐
406           way with problems. The authors all read the lists, so you lose
407           nothing by mailing there.
408

Platform and Driver Issues

410       3.1 What's the difference between ODBC and DBI?
411
412       In terms of architecture - not much: Both define programming inter‐
413       faces. Both allow multiple drivers to be loaded to do the actual work.
414
415       In terms of ease of use - much: The DBI is a 'high level' interface
416       that, like Perl itself, strives to make the simple things easy while
417       still making the hard things possible. The ODBC is a 'low level' inter‐
418       face. All nuts-bolts-knobs-and-dials.
419
420       Now there's an ODBC driver for the DBI (DBD::ODBC) the "What's the dif‐
421       ference" question is more usefully rephrased as:
422
423       Chapter 7 of "Programming the Perl DBI" covers this topic in far more
424       detail and should be consulted.
425
426       3.2 What's the difference between Win32::ODBC and DBD::ODBC?
427
428       The DBI, and thus DBD::ODBC, has a different philosophy from the
429       Win32::ODBC module:
430
431       The Win32::ODBC module is a 'thin' layer over the low-level ODBC API.
432       The DBI defines a simpler 'higher level' interface.
433
434       The Win32::ODBC module gives you access to more of the ODBC API.  The
435       DBI and DBD::ODBC give you access to only the essentials.  (But, unlike
436       Win32::ODBC, the DBI and DBD::ODBC do support parameter binding and
437       multiple prepared statements which reduces the load on the database
438       server and can dramatically increase performance.)
439
440       The Win32::ODBC module only works on Win32 systems.  The DBI and
441       DBD::ODBC are very portable and work on Win32 and Unix.
442
443       The DBI and DBD::ODBC modules are supplied as a standard part of the
444       Perl 5.004 binary distribution for Win32 (they don't work with the
445       older, non-standard, ActiveState port).
446
447       Scripts written with the DBI and DBD::ODBC are faster than Win32::ODBC
448       on Win32 and are trivially portable to other supported database types.
449
450       The DBI offers optional automatic printing or die()ing on errors which
451       makes applications simpler and more robust.
452
453       The current DBD::ODBC driver version 0.16 is new and not yet fully sta‐
454       ble.  A new release is due soon [relative to the date of the next TPJ
455       issue :-] and will be much improved and offer more ODBC functionality.
456
457       To summarise: The Win32::ODBC module is your best choice if you need
458       access to more of the ODBC API than the DBI gives you. Otherwise, the
459       DBI and DBD::ODBC combination may be your best bet.
460
461       Chapter 7 of "Programming the Perl DBI" covers this topic in far more
462       detail and should be consulted.
463
464       3.3 Is DBI supported under Windows 95 / NT platforms?
465
466       Finally, yes! Jeff Urlwin has been working diligently on building DBI
467       and DBD::ODBC under these platforms, and, with the advent of a stabler
468       perl and a port of MakeMaker, the project has come on by great leaps
469       and bounds.
470
471       The DBI and DBD::Oracle Win32 ports are now a standard part of DBI, so,
472       downloading DBI of version higher than 0.81 should work fine as should
473       using the most recent DBD::Oracle version.
474
475       3.4 Can I access Microsoft Access or SQL-Server databases with DBI?
476
477       Yes, use the DBD::ODBC driver.
478
479       3.5 Is the a DBD for <insert favourite database here>?
480
481       Is is listed on the DBI drivers page?
482
483           http://dbi.perl.org/
484           http://www.symbolstone.org/technology/perl/DBI
485
486       If not, no. A complete absence of a given database driver from that
487       page means that no-one has announced any intention to work on it, not
488       that such a driver is impossible to write.
489
490       A corollary of the above statement implies that if you see an announce‐
491       ment for a driver not on the above page, there's a good chance it's not
492       actually a DBI driver, and may not conform to the specifications.
493       Therefore, questions concerning problems with that code should not
494       really be addressed to the DBI Mailing Lists.
495
496       3.6 What's DBM? And why should I use DBI instead?
497
498       Extracted from ``DBI - The Database Interface for Perl 5'':
499
500           ``UNIX was originally blessed with simple file-based ``databases'', namely
501           the dbm system. dbm lets you store data in files, and retrieve
502           that data quickly. However, it also has serious drawbacks.
503
504               File Locking
505
506               The dbm systems did not allow particularly robust file locking
507               capabilities, nor any capability for correcting problems arising through
508               simultaneous writes [ to the database ].
509
510               Arbitrary Data Structures
511
512               The dbm systems only allows a single fixed data structure:
513               key-value pairs. That value could be a complex object, such as a
514               [ C ] struct, but the key had to be unique. This was a large
515               limitation on the usefulness of dbm systems.
516
517           However, dbm systems still provide a useful function for users with
518           simple datasets and limited resources, since they are fast, robust and
519           extremely well-tested. Perl modules to access dbm systems have now
520           been integrated into the core Perl distribution via the
521           AnyDBM_File module.''
522
523       To sum up, DBM is a perfectly satisfactory solution for essentially
524       read-only databases, or small and simple datasets. However, for more
525       scaleable dataset handling, not to mention robust transactional lock‐
526       ing, users are recommended to use a more powerful database engine via
527       DBI.
528
529       Chapter 2 of "Programming the Perl DBI" discusses DBM files in detail.
530
531       3.7 What database do you recommend me using?
532
533       This is a particularly thorny area in which an objective answer is dif‐
534       ficult to come by, since each dataset, proposed usage and system con‐
535       figuration differs from person to person.
536
537       From the current author's point of view, if the dataset is relatively
538       small, being tables of less than 1 million rows, and less than 1000
539       tables in a given database, then mSQL is a perfectly acceptable solu‐
540       tion to your problem. This database is extremely cheap, is wonderfully
541       robust and has excellent support. More information is available on the
542       Hughes Technology WWW site at:
543
544           http://www.hughes.com.au
545
546       You may also wish to look at MySQL which is a more powerful database
547       engine that has a similar feel to mSQL.
548
549           http://www.tcx.se
550
551       If the dataset is larger than 1 million row tables or 1000 tables, or
552       if you have either more money, or larger machines, I would recommend
553       Oracle RDBMS.  Oracle's WWW site is an excellent source of more infor‐
554       mation.
555
556           http://www.oracle.com
557
558       Informix is another high-end RDBMS that is worth considering. There are
559       several differences between Oracle and Informix which are too complex
560       for this document to detail. Information on Informix can be found on
561       their WWW site at:
562
563           http://www.informix.com
564
565       In the case of WWW fronted applications, mSQL may be a better option
566       due to slow connection times between a CGI script and the Oracle RDBMS
567       and also the amount of resource each Oracle connection will consume.
568       mSQL is lighter resource-wise and faster.
569
570       These views are not necessarily representative of anyone else's opin‐
571       ions, and do not reflect any corporate sponsorship or views. They are
572       provided as-is.
573
574       3.8 Is <insert feature here> supported in DBI?
575
576       Given that we're making the assumption that the feature you have
577       requested is a non-standard database-specific feature, then the answer
578       will be no.
579
580       DBI reflects a generic API that will work for most databases, and has
581       no database-specific functionality.
582
583       However, driver authors may, if they so desire, include hooks to data‐
584       base-specific functionality through the "func()" method defined in the
585       DBI API.  Script developers should note that use of functionality pro‐
586       vided via the "func()" methods is very unlikely to be portable across
587       databases.
588

Programming Questions

590       4.1 Is DBI any use for CGI programming?
591
592       In a word, yes! DBI is hugely useful for CGI programming! In fact, I
593       would tentatively say that CGI programming is one of two top uses for
594       DBI.
595
596       DBI confers the ability to CGI programmers to power WWW-fronted data‐
597       bases to their users, which provides users with vast quantities of
598       ordered data to play with. DBI also provides the possibility that, if a
599       site is receiving far too much traffic than their database server can
600       cope with, they can upgrade the database server behind the scenes with
601       no alterations to the CGI scripts.
602
603       4.2 How do I get faster connection times with DBD::Oracle and CGI?
604
605           Contributed by John D. Groenveld
606
607       The Apache "httpd" maintains a pool of "httpd" children to service
608       client requests.
609
610       Using the Apache mod_perl module by Doug MacEachern, the perl inter‐
611       preter is embedded with the "httpd" children. The CGI, DBI, and your
612       other favorite modules can be loaded at the startup of each child.
613       These modules will not be reloaded unless changed on disk.
614
615       For more information on Apache, see the Apache Project's WWW site:
616
617           http://www.apache.org
618
619       The mod_perl module can be downloaded from CPAN via:
620
621           http://www.perl.com/cgi-bin/cpan_mod?module=Apache
622
623       4.3 How do I get persistent connections with DBI and CGI?
624
625           Contributed by John D. Groenveld
626
627       Using Edmund Mergl's Apache::DBI module, database logins are stored in
628       a hash with each of these "httpd" child. If your application is based
629       on a single database user, this connection can be started with each
630       child.  Currently, database connections cannot be shared between
631       "httpd" children.
632
633       Apache::DBI can be downloaded from CPAN via:
634
635           http://www.perl.com/cgi-bin/cpan_mod?module=Apache::DBI
636
637       4.4 ``When I run a perl script from the command line, it works, but,
638       when I run it under the "httpd", it fails!'' Why?
639
640       Basically, a good chance this is occurring is due to the fact that the
641       user that you ran it from the command line as has a correctly config‐
642       ured set of environment variables, in the case of DBD::Oracle, vari‐
643       ables like "ORACLE_HOME", "ORACLE_SID" or "TWO_TASK".
644
645       The "httpd" process usually runs under the user id of "nobody", which
646       implies there is no configured environment. Any scripts attempting to
647       execute in this situation will correctly fail.
648
649       One way to solve this problem is to set the environment for your data‐
650       base in a "BEGIN { }" block at the top of your script. Another tech‐
651       nique is to configure your WWW server to pass-through certain environ‐
652       ment variables to your CGI scripts.
653
654       Similarly, you should check your "httpd" error logfile for any clues,
655       as well as the ``Idiot's Guide To Solving Perl / CGI Problems'' and
656       ``Perl CGI Programming FAQ'' for further information. It is unlikely
657       the problem is DBI-related.
658
659       The ``Idiot's Guide To Solving Perl / CGI Problems'' can be located at:
660
661           http://www.perl.com/perl/faq/index.html
662
663       as can the ``Perl CGI Programming FAQ''. Read BOTH these documents
664       carefully!
665
666       4.5 How do I get the number of rows returned from a "SELECT" statement?
667
668       Count them. Read the DBI docs for the "rows()" method.
669

Miscellaneous Questions

671       5.1 Can I do multi-threading with DBI?
672
673       Perl version 5.005 and later can be built to support multi-threading.
674       The DBI, as of version 1.02, does not yet support multi-threading so it
675       would be unsafe to let more than one thread enter the DBI at the same
676       time.
677
678       It is expected that some future version of the DBI will at least be
679       thread-safe (but not thread-hot) by automatically blocking threads
680       intering the DBI while it's already in use.
681
682       For some OCI example code for Oracle that has multi-threaded "SELECT"
683       statements, see:
684
685           http://www.symbolstone.org/technology/oracle/oci/orathreads.tar.gz
686
687       5.2 How do I handle BLOB data with DBI?
688
689       Handling BLOB data with the DBI is very straight-forward. BLOB columns
690       are specified in a SELECT statement as per normal columns. However, you
691       also need to specify a maximum BLOB size that the <I>database han‐
692       dle</I> can fetch using the "LongReadLen" attribute.
693
694       For example:
695
696           ### $dbh is a connected database handle
697           $sth = $dbh->prepare( "SELECT blob_column FROM blobby_table" );
698           $sth->execute;
699
700       would fail.
701
702           ### $dbh is a connected database handle
703           ### Set the maximum BLOB size...
704           $dbh->{LongReadLen} = 16384;        ### 16Kb...Not much of a BLOB!
705
706           $sth = $dbh->prepare( "..." );
707
708       would succeed <I>provided no column values were larger than the speci‐
709       fied value</I>.
710
711       If the BLOB data is longer than the value of "LongReadLen", then an
712       error will occur. However, the DBI provides an additional piece of
713       functionality that will automatically truncate the fetched BLOB to the
714       size of "LongReadLen" if it is longer. This does not cause an error to
715       occur, but may make your fetched BLOB data useless.
716
717       This behaviour is regulated by the "LongTruncOk" attribute which is
718       defaultly set to a false value ( thus making overlong BLOB fetches fail
719       ).
720
721           ### Set BLOB handling such that it's 16Kb and can be truncated
722           $dbh->{LongReadLen} = 16384;
723           $dbh->{LongTruncOk} = 1;
724
725       Truncation of BLOB data may not be a big deal in cases where the BLOB
726       contains run-length encoded data, but data containing checksums at the
727       end, for example, a ZIP file, would be rendered useless.
728
729       5.3 How can I invoke stored procedures with DBI?
730
731       The DBI does not define a database-independent way of calling stored
732       procedures.
733
734       However, most database that support them also provide a way to call
735       them from SQL statements - and the DBI certainly supports that.
736
737       So, assuming that you have created a stored procedure within the target
738       database, eg, an Oracle database, you can use $dbh->"do()" to immedi‐
739       ately execute the procedure. For example,
740
741           $dbh->do( "BEGIN someProcedure; END;" );   # Oracle-specific
742
743       You should also be able to "prepare" and "execute", which is the recom‐
744       mended way if you'll be calling the procedure often.
745
746       5.4 How can I get return values from stored procedures with DBI?
747
748           Contributed by Jeff Urlwin
749
750           $sth = $dbh->prepare( "BEGIN foo(:1, :2, :3); END;" );
751           $sth->bind_param(1, $a);
752           $sth->bind_param_inout(2, \$path, 2000);
753           $sth->bind_param_inout(3, \$success, 2000);
754           $sth->execute;
755
756       Remember to perform error checking, though! ( Or use the "RaiseError"
757       attribute ).
758
759       5.5 How can I create or drop a database with DBI?
760
761       Database creation and deletion are concepts that are entirely too
762       abstract to be adequately supported by DBI. For example, Oracle does
763       not support the concept of dropping a database at all! Also, in Oracle,
764       the database server essentially is the database, whereas in mSQL, the
765       server process runs happily without any databases created in it. The
766       problem is too disparate to attack in a worthwhile way.
767
768       Some drivers, therefore, support database creation and deletion through
769       the private "func()" methods. You should check the documentation for
770       the drivers you are using to see if they support this mechanism.
771
772       5.6 How can I "commit" or "rollback" a statement with DBI?
773
774       See the "commit()" and "rollback()" methods in the DBI Specification.
775
776       Chapter 6 of "Programming the Perl DBI" discusses transaction handling
777       within the context of DBI in more detail.
778
779       5.7 How are "NULL" values handled by DBI?
780
781       "NULL" values in DBI are specified to be treated as the value "undef".
782       "NULL"s can be inserted into databases as "NULL", for example:
783
784           $rv = $dbh->do( "INSERT INTO table VALUES( NULL )" );
785
786       but when queried back, the "NULL"s should be tested against "undef".
787       This is standard across all drivers.
788
789       5.8 What are these "func()" methods all about?
790
791       The "func()" method is defined within DBI as being an entry point for
792       database-specific functionality, eg, the ability to create or drop
793       databases. Invoking these driver-specific methods is simple, for exam‐
794       ple, to invoke a "createDatabase" method that has one argument, we
795       would write:
796
797           $rv =$dbh->func( 'argument', 'createDatabase' );
798
799       Software developers should note that the "func()" methods are non-por‐
800       table between databases.
801
802       5.9 Is DBI Year 2000 Compliant?
803
804       DBI has no knowledge of understanding of what dates are. Therefore, DBI
805       itself does not have a Year 2000 problem. Individual drivers may use
806       date handling code internally and therefore be potentially susceptible
807       to the Year 2000 problem, but this is unlikely.
808
809       You may also wish to read the ``Does Perl have a Year 2000 problem?''
810       section of the Perl FAQ at:
811
812           http://www.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html
813

Support and Training

815       The Perl5 Database Interface is FREE software. IT COMES WITHOUT WAR‐
816       RANTY OF ANY KIND. See the DBI README for more details.
817
818       However, some organizations are providing either technical support or
819       training programs on DBI. The present author has no knowledge as to the
820       quality of these services. The links are included for reference pur‐
821       poses only and should not be regarded as recommendations in any way.
822       Caveat emptor.
823
824       Commercial Support
825
826       The Perl Clinic
827           The Perl Clinic provides commercial support for Perl and Perl
828           related problems, including the DBI and its drivers.  Support is
829           provided by the company with whom Tim Bunce, author of DBI and
830           DBD::Oracle, works and ActiveState. For more information on their
831           services, please see:
832
833               http://www.perlclinic.com
834
835       Training
836
837       Westlake Solutions
838           A hands-on class for experienced Perl CGI developers that teaches
839           how to write database-connected CGI scripts using Perl and DBI.pm.
840           This course, along with four other courses on CGI scripting with
841           Perl, is taught in Washington, DC; Arlington, Virginia; and on-site
842           worldwide upon request.
843
844           See:
845
846               http://www.westlake.com/training
847
848           for more details.
849

Other References

851       In this section, we present some miscellaneous WWW links that may be of
852       some interest to DBI users. These are not verified and may result in
853       unknown sites or missing documents.
854
855           http://www-ccs.cs.umass.edu/db.html
856           http://www.odmg.org/odmg93/updates_dbarry.html
857           http://www.jcc.com/sql_stnd.html
858

AUTHOR

860       Alligator Descartes <http://www.symbolstone.org/descarte/contact.html>.
861       Portions are Copyright their original stated authors.
862
864       This document is Copyright (c)1994-2000 Alligator Descartes, with por‐
865       tions Copyright (c)1994-2000 their original authors. This module is
866       released under the 'Artistic' license which you can find in the perl
867       distribution.
868
869       This document is Copyright (c)1997-2000 Alligator Descartes. All rights
870       reserved.  Permission to distribute this document, in full or in part,
871       via email, Usenet, ftp archives or http is granted providing that no
872       charges are involved, reasonable attempt is made to use the most cur‐
873       rent version and all credits and copyright notices are retained ( the
874       AUTHOR and COPYRIGHT sections ).  Requests for other distribution
875       rights, including incorporation into commercial products, such as
876       books, magazine articles or CD-ROMs should be made to Alligator
877       Descartes <http://www.symbolstone.org/descarte/contact.html>.
878
879
880
881perl v5.8.8                       2006-02-07                       DBI::FAQ(3)
Impressum