Codebase list libdbi-perl / 5bfd952
Imported Upstream version 1.628 gregor herrmann 10 years ago
63 changed file(s) with 489 addition(s) and 365 deletion(s). Raw diff Collapse all Expand all
11
22 DBI::Changes - List of significant changes to the DBI
33
4 (As of $Date$ $Revision$)
5
64 =encoding ISO8859-1
75
86 =cut
7
8 =head2 Changes in DBI 1.628 - 22nd July 2013
9
10 Fixed missing fields on partial insert via DBI::DBD::SqlEngine
11 engines (DBD::CSV, DBD::DBM etc.) [H.Merijn Brand, Jens Rehsack]
12 Fixed stack corruption on callbacks RT#85562 RT#84974 [Aaron Schweiger]
13 Fixed DBI::SQL::Nano_::Statement handling of "0" [Jens Rehsack]
14 Fixed exit op precedence in test RT#87029 [Reni Urban]
15
16 Added support for finding tables in multiple directories
17 via new DBD::File f_dir_search attribute [H.Merijn Brand]
18 Enable compiling by C++ RT#84285 [Kurt Jaeger]
19
20 Typo fixes in pod and comment [David Steinbrunner]
21 Change DBI's docs to refer to git not svn [H.Merijn Brand]
22 Clarify bind_col TYPE attribute is sticky [Martin J. Evans]
23 Fixed reference to $sth in selectall_arrayref docs RT#84873
24 Spelling fixes [Ville Skyttä]
25 Changed $VERSIONs to hardcoded strings [H.Merijn Brand]
926
1027 =head2 Changes in DBI 1.627 - 16th May 2013
1128
380397 Fixed DBI::PurePerl neat() to behave more like XS neat().
381398
382399 Increased default $DBI::neat_maxlen from 400 to 1000.
383 Increased timeout on tests to accomodate very slow systems.
400 Increased timeout on tests to accommodate very slow systems.
384401 Changed behaviour of trace levels 1..4 to show less information
385402 at lower levels.
386403 Changed the format of the key used for $h->{CachedKids}
11891206
11901207 Documentation changes:
11911208 Documented $high_resolution_time = dbi_time() function.
1192 Documented that bind_col() can take an atribute hash.
1209 Documented that bind_col() can take an attribute hash.
11931210 Clarified documentation for ParamValues attribute hash keys.
11941211 Many good DBI documentation tweaks from Jonathan Leffler,
11951212 including a major update to the DBI::DBD driver author guide.
13281345 : If you are still using perl 5.005_03 you should be making plans to
13291346 : upgrade to at least perl 5.6.1, or 5.8.0. Perl 5.8.0 is due to be
13301347 : released in the next week or so. (Although it's a "point 0" release,
1331 : it is the most throughly tested release ever.)
1348 : it is the most thoroughly tested release ever.)
13321349
13331350 Added XS/C implementations of selectrow_array, selectrow_arrayref, and
13341351 selectall_arrayref to Driver.xst. See DBI 1.26 Changes for more info.
13721389
13731390 Added C implementations of selectrow_arrayref() and fetchall_arrayref()
13741391 in Driver.xst. All compiled drivers using Driver.xst will now be
1375 faster making those calls. Most noticable with fetchall_arrayref for
1392 faster making those calls. Most noticeable with fetchall_arrayref for
13761393 many rows or selectrow_arrayref with a fast query. For example, using
13771394 DBD::mysql a selectrow_arrayref for a single row using a primary key
13781395 is ~20% faster, and fetchall_arrayref for 20000 rows is twice as fast!
23242341 Added DBI->internal->{DebugLog} = $filename;
23252342 Reworked internal logging.
23262343 Added $VERSION.
2327 Made disconnect_all a compulsary method for drivers.
2344 Made disconnect_all a compulsory method for drivers.
23282345
23292346
23302347 =head1 ANCIENT HISTORY
1010 require 5.008_001;
1111
1212 BEGIN {
13 $VERSION = "1.627"; # ==> ALSO update the version in the pod text below!
13 $VERSION = "1.628"; # ==> ALSO update the version in the pod text below!
1414 }
1515
1616 =head1 NAME
136136
137137 =head2 NOTES
138138
139 This is the DBI specification that corresponds to DBI version 1.627
139 This is the DBI specification that corresponds to DBI version 1.628
140140 (see L<DBI::Changes> for details).
141141
142142 The DBI is evolving at a steady pace, so it's good to check that
157157
158158 Extensions to the DBI API often use the C<DBIx::*> namespace.
159159 See L</Naming Conventions and Name Space>. DBI extension modules
160 can be found at L<http://search.cpan.org/search?mode=module&query=DBIx>.
161 And all modules related to the DBI can be found at
162 L<http://search.cpan.org/search?query=DBI&mode=all>.
160 can be found at L<https://metacpan.org/search?q=DBIx>. And all modules
161 related to the DBI can be found at L<https://metacpan.org/search?q=DBI>.
163162
164163 =cut
165164
693692 my $rebless_class = $apply->{RootClass} || ($class ne 'DBI' ? $class : '');
694693 if ($rebless_class) {
695694 no strict 'refs';
696 if ($apply->{RootClass}) { # explicit attribute (ie not static methd call class)
695 if ($apply->{RootClass}) { # explicit attribute (ie not static method call class)
697696 delete $apply->{RootClass};
698697 DBI::_load_class($rebless_class, 0);
699698 }
726725 }
727726 }
728727
729 # confirm to driver (ie if subclassed) that we've connected sucessfully
728 # confirm to driver (ie if subclassed) that we've connected successfully
730729 # and finished the attribute setup. pass in the original arguments
731730 $dbh->connected(@orig_args); #if ref $dbh ne 'DBI::db' or $proxy;
732731
25272526 is null, and returns 1 if it is, or 0 if not.
25282527
25292528 Example 6, the least simple, is probably the most portable, i.e., it
2530 should work with with most, if not all, database engines.
2529 should work with most, if not all, database engines.
25312530
25322531 Here is a table that indicates which examples above are known to
25332532 work on various database engines:
25482547 DBI provides a sample perl script that will test the examples above
25492548 on your database engine and tell you which ones work. It is located
25502549 in the F<ex/> subdirectory of the DBI source distribution, or here:
2551 L<http://svn.perl.org/modules/dbi/trunk/ex/perl_dbi_nulls_test.pl>
2550 L<https://github.com/perl5-dbi/dbi/blob/master/ex/perl_dbi_nulls_test.pl>
25522551 Please use the script to help us fill-in and maintain this table.
25532552
25542553 B<Performance>
26822681 description of the syntax they require.
26832682
26842683 It is recommended that drivers support the ODBC style, shown in the
2685 last example above. It is also recommended that that they support the
2684 last example above. It is also recommended that they support the
26862685 three common names 'C<host>', 'C<port>', and 'C<database>' (plus 'C<db>'
26872686 as an alias for C<database>). This simplifies automatic construction
26882687 of basic DSNs: C<"dbi:$driver:database=$db;host=$host;port=$port">.
45494548 If L</RaiseError> is not set and any method except C<fetchall_arrayref>
45504549 fails then C<selectall_arrayref> will return C<undef>; if
45514550 C<fetchall_arrayref> fails then it will return with whatever data
4552 has been fetched thus far. You should check C<$sth-E<gt>err>
4551 has been fetched thus far. You should check C<$dbh-E<gt>err>
45534552 afterwards (or use the C<RaiseError> attribute) to discover if the data is
45544553 complete or was truncated due to an error.
45554554
66526651
66536652 Few drivers support specifying a data type via a C<bind_col> call
66546653 (most will simply ignore the data type). Fewer still allow the data
6655 type to be altered once set.
6654 type to be altered once set. If you do set a column type the type
6655 should remain sticky through further calls to bind_col for the same
6656 column if the type is not overridden (this is important for instance
6657 when you are using a slice in fetchall_arrayref).
66566658
66576659 The TYPE attribute for bind_col() was first specified in DBI 1.41.
66586660
80508052
80518053 Index of DBI related modules available from CPAN:
80528054
8053 http://search.cpan.org/search?mode=module&query=DBIx%3A%3A
8054 http://search.cpan.org/search?mode=doc&query=DBI
8055 https://metacpan.org/search?q=DBD%3A%3A
8056 https://metacpan.org/search?q=DBIx%3A%3A
8057 https://metacpan.org/search?q=DBI
80558058
80568059 For a good comparison of RDBMS-OO mappers and some OO-RDBMS mappers
80578060 (including Class::DBI, Alzabo, and DBIx::RecordSet in the former
81588161 Contact me for details.
81598162
81608163 =head2 Sponsor Enhancements
8161
8162 The DBI Roadmap is available at L<http://search.cpan.org/~timb/DBI/Roadmap.pod>
81638164
81648165 If your company would benefit from a specific new DBI feature,
81658166 please consider sponsoring its development. Work is performed
81918192 "Programming the Perl DBI" book and letting me jump on board.
81928193
81938194 The DBI and DBD::Oracle were originally developed while I was Technical
8194 Director (CTO) of Ingeneering in the UK (L<http://www.ig.co.uk>) (formerly known as the
8195 Paul Ingram Group). So I'd especially like to thank Paul for his generosity
8196 and vision in supporting this work for many years.
8195 Director (CTO) of the Paul Ingram Group in the UK. So I'd especially like
8196 to thank Paul for his generosity and vision in supporting this work for many years.
81978197
81988198 A couple of specific DBI features have been sponsored by enlightened companies:
81998199
82028202 The development of DBD::Gofer and related modules was sponsored by
82038203 Shopzilla.com (L<http://Shopzilla.com>), where I currently work.
82048204
8205
82068205 =head1 CONTRIBUTING
82078206
82088207 As you can see above, many people have contributed to the DBI and
82098208 drivers in many ways over many years.
82108209
8211 If you'd like to help then see L<http://dbi.perl.org/contributing>
8212 and L<http://search.cpan.org/~timb/DBI/Roadmap.pod>
8210 If you'd like to help then see L<http://dbi.perl.org/contributing>.
82138211
82148212 If you'd like the DBI to do something new or different then a good way
82158213 to make that happen is to do it yourself and send me a patch to the
82188216
82198217 =head2 Browsing the source code repository
82208218
8221 Use http://svn.perl.org/modules/dbi/trunk (basic)
8222 or http://svn.perl.org/viewcvs/modules/ (more useful)
8223
8224 =head2 How to create a patch using Subversion
8225
8226 The DBI source code is maintained using Subversion (a replacement
8227 for CVS, see L<http://subversion.tigris.org/>). To access the source
8228 you'll need to install a Subversion client. Then, to get the source
8229 code, do:
8230
8231 svn checkout http://svn.perl.org/modules/dbi/trunk
8232
8233 If it prompts for a username and password use your perl.org account
8234 if you have one, else just 'guest' and 'guest'. The source code will
8235 be in a new subdirectory called C<trunk>.
8236
8237 To keep informed about changes to the source you can send an empty email
8238 to svn-commit-modules-dbi-subscribe@perl.org after which you'll get an email
8239 with the change log message and diff of each change checked-in to the source.
8240
8241 After making your changes you can generate a patch file, but before
8242 you do, make sure your source is still up to date using:
8243
8244 svn update
8219 Use https://github.com/perl5-dbi/dbi
8220
8221 =head2 How to create a patch using Git
8222
8223 The DBI source code is maintained using Git. To access the source
8224 you'll need to install a Git client. Then, to get the source code, do:
8225
8226 git clone https://github.com/perl5-dbi/dbi.git DBI-git
8227
8228 The source code will now be available in the new subdirectory C<DBI-git>.
8229
8230 When you want to synchronize later, issue the command
8231
8232 git pull --all
8233
8234 Make your changes, test them, test them again until everything passes.
8235 If there are no tests for the new feature you added or a behaviour change,
8236 the change should include a new test. Then commit the changes. Either use
8237
8238 git gui
8239
8240 or
8241
8242 git commit -a -m 'Message to my changes'
82458243
82468244 If you get any conflicts reported you'll need to fix them first.
8247 Then generate the patch file from within the C<trunk> directory using:
8248
8249 svn diff > foo.patch
8250
8245
8246 Then generate the patch file to be mailed:
8247
8248 git format-patch -1 --attach
8249
8250 which will create a file 0001-*.patch (where * relates to the commit message).
82518251 Read the patch file, as a sanity check, and then email it to dbi-dev@perl.org.
82528252
8253 =head2 How to create a patch without Subversion
8253 If you have a L<github|https://github.com> account, you can also fork the
8254 repository, commit your changes to the forked repository and then do a
8255 pull request.
8256
8257 =head2 How to create a patch without Git
82548258
82558259 Unpack a fresh copy of the distribution:
82568260
8257 tar xfz DBI-1.40.tar.gz
8261 wget http://cpan.metacpan.org/authors/id/T/TI/TIMB/DBI-1.627.tar.gz
8262 tar xfz DBI-1.627.tar.gz
82588263
82598264 Rename the newly created top level directory:
82608265
8261 mv DBI-1.40 DBI-1.40.your_foo
8262
8263 Edit the contents of DBI-1.40.your_foo/* till it does what you want.
8266 mv DBI-1.627 DBI-1.627.your_foo
8267
8268 Edit the contents of DBI-1.627.your_foo/* till it does what you want.
82648269
82658270 Test your changes and then remove all temporary files:
82668271
82728277
82738278 Unpack I<another> copy of the original distribution you started with:
82748279
8275 tar xfz DBI-1.40.tar.gz
8280 tar xfz DBI-1.627.tar.gz
82768281
82778282 Then create a patch file by performing a recursive C<diff> on the two
82788283 top level directories:
82798284
8280 diff -r -u DBI-1.40 DBI-1.40.your_foo > DBI-1.40.your_foo.patch
8285 diff -purd DBI-1.627 DBI-1.627.your_foo > DBI-1.627.your_foo.patch
82818286
82828287 =head2 Speak before you patch
82838288
82878292 of them being rejected because they don't fit into some larger plans
82888293 you may not be aware of.
82898294
8295 You can also reach the developers on IRC (chat). If they are on-line,
8296 the most likely place to talk to them is the #dbi channel on irc.perl.org
8297
82908298 =head1 TRANSLATIONS
82918299
82928300 A German translation of this manual (possibly slightly out of date) is
82988306
82998307 http://cronopio.net/perl/ - Spanish
83008308 http://member.nifty.ne.jp/hippo2000/dbimemo.htm - Japanese
8301
83028309
83038310 =head1 TRAINING
83048311
35153515 */
35163516 /* we want to localize $_ for the callback but can't just do that alone
35173517 * because we're not using SAVETMPS & FREETMPS, so we have to get sneaky.
3518 * We still localize, so we're safe from the callback dieing,
3518 * We still localize, so we're safe from the callback die-ing,
35193519 * but after the callback we manually restore the original $_.
35203520 */
35213521 orig_defsv = DEFSV; /* remember the current $_ */
4040 #include "dbi_sql.h"
4141
4242
43 #define DBIXS_VERSION 93 /* superceeded by DBIXS_REVISION */
43 #define DBIXS_VERSION 93 /* superseded by DBIXS_REVISION */
4444
4545 #ifdef NEED_DBIXS_VERSION
4646 #if NEED_DBIXS_VERSION > DBIXS_VERSION
9292 D_imp_dbh(dbh);
9393 #if !defined(dbd_db_login6_sv)
9494 STRLEN lna;
95 char *u = (SvOK(username)) ? SvPV(username,lna) : "";
96 char *p = (SvOK(password)) ? SvPV(password,lna) : "";
95 char *u = (SvOK(username)) ? SvPV(username,lna) : (char*)"";
96 char *p = (SvOK(password)) ? SvPV(password,lna) : (char*)"";
9797 #endif
9898 #ifdef dbd_db_login6_sv
9999 ST(0) = dbd_db_login6_sv(dbh, imp_dbh, dbname, username, password, attribs) ? &PL_sv_yes : &PL_sv_no;
111111 SV *sth;
112112 SV **maxrows_svp;
113113 SV **tmp_svp;
114 SV *tmp_sv;
114115 SV *attr = &PL_sv_undef;
115116 imp_sth_t *imp_sth;
116117 CODE:
156157 }
157158 /* --- fetchall --- */
158159 maxrows_svp = DBD_ATTRIB_GET_SVP(attr, "MaxRows", 7);
159 ST(0) = dbdxst_fetchall_arrayref(sth, &PL_sv_undef, (maxrows_svp) ? *maxrows_svp : &PL_sv_undef);
160 tmp_sv = dbdxst_fetchall_arrayref(sth, &PL_sv_undef, (maxrows_svp) ? *maxrows_svp : &PL_sv_undef);
161 SPAGAIN;
162 ST(0) = tmp_sv;
160163
161164
162165 void
300303 /* still exists. This possibly needs some more thought. */
301304 if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !PL_dirty) {
302305 STRLEN lna;
303 char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? "" : "s";
306 char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? (char*)"" : (char*)"s";
304307 warn("%s->disconnect invalidates %d active statement handle%s %s",
305308 SvPV(dbh,lna), (int)DBIc_ACTIVE_KIDS(imp_dbh), plural,
306309 "(either destroy statement handles or call finish on them before disconnecting)");
659662 ST(0) = tmp;
660663 }
661664 else {
662 ST(0) = dbdxst_fetchall_arrayref(sth, slice, batch_row_count);
665 SV *tmp = dbdxst_fetchall_arrayref(sth, slice, batch_row_count);
666 SPAGAIN;
667 ST(0) = tmp;
663668 }
664669
665670
2323 Synaptic for Ubuntu, port for FreeBSD etc)
2424
2525 ---
26 If you get compiler errors refering to Perl's own header files
26 If you get compiler errors referring to Perl's own header files
2727 (.../CORE/...h) or the compiler complains about bad options etc then
2828 there is something wrong with your perl installation. If the compiler complains
2929 of missing files (.../perl.h: error: sys/types.h: No such file) then you may
33 "Tim Bunce (dbi-users@perl.org)"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921",
6 "generated_by" : "ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.131560",
77 "license" : [
88 "perl_5"
99 ],
6464 },
6565 "x_MailingList" : "mailto:dbi-dev@perl.org"
6666 },
67 "version" : "1.627"
67 "version" : "1.628"
6868 }
1515 DBD::RAM: 0.072
1616 SQL::Statement: 1.33
1717 dynamic_config: 1
18 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921'
18 generated_by: 'ExtUtils::MakeMaker version 6.68, CPAN::Meta::Converter version 2.131560'
1919 license: perl
2020 meta-spec:
2121 url: http://module-build.sourceforge.net/META-spec-v1.4.html
3535 requires:
3636 perl: 5.008
3737 resources:
38 MailingList: mailto:dbi-dev@perl.org
3839 homepage: http://dbi.perl.org/
3940 license: http://dev.perl.org/licenses/
4041 repository: https://github.com/perl5-dbi/dbi
41 x_MailingList: mailto:dbi-dev@perl.org
42 version: 1.627
42 version: 1.628
7575 while (my ($key, $val) = each %match) {
7676 if ($val =~ m!^/(.+)/$!) {
7777 $val = $case_sensitive ? qr/$1/ : qr/$1/i;
78 }
78 }
7979 $prof->match($key, $val, case_sensitive => $case_sensitive);
8080 }
8181 }
8484 while (my ($key, $val) = each %exclude) {
8585 if ($val =~ m!^/(.+)/$!) {
8686 $val = $case_sensitive ? qr/$1/ : qr/$1/i;
87 }
87 }
8888 $prof->exclude($key, $val, case_sensitive => $case_sensitive);
8989 }
9090 }
159159
160160 =item B<--version>
161161
162 Supresses startup of the server; instead the version string will
162 Suppresses startup of the server; instead the version string will
163163 be printed and the program exits immediately.
164164
165165 =back
11
22 package Bundle::DBI;
33
4 our $VERSION = sprintf("12.%06d", q$Revision: 8695 $ =~ /(\d+)/o);
4 our $VERSION = "12.008696";
55
66 1;
77
175175 eval {
176176 $dver = $meta->{dbm_type}->VERSION();
177177
178 # *) when we're still alive here, everthing went ok - no need to check for $@
178 # *) when we're still alive here, everything went ok - no need to check for $@
179179 $dtype .= " ($dver)";
180180 };
181181 if ( $meta->{dbm_mldbm} )
77 require File::Spec;
88
99 @EXPORT = qw(); # Do NOT @EXPORT anything.
10 $VERSION = sprintf("12.%06d", q$Revision: 14310 $ =~ /(\d+)/o);
11
10 $VERSION = "12.014311";
1211
1312 # $Id: ExampleP.pm 14310 2010-08-02 06:35:25Z Jens $
1413 #
3434 use Carp;
3535 use vars qw( @ISA $VERSION $drh );
3636
37 $VERSION = "0.41";
37 $VERSION = "0.42";
3838
3939 $drh = undef; # holds driver handle(s) once initialized
4040
4646 # We use a hash here to have one singleton per subclass.
4747 # (Otherwise DBD::CSV and DBD::DBM, for example, would
4848 # share the same driver object which would cause problems.)
49 # An alternative would be not not cache the $drh here at all
49 # An alternative would be to not cache the $drh here at all
5050 # and require that subclasses do that. Subclasses should do
5151 # their own caching, so caching here just provides extra safety.
5252 $drh->{$class} and return $drh->{$class};
129129 {
130130 my ($dbh, $attr, @other) = @_;
131131 ref ($attr) eq "HASH" or $attr = {};
132 exists $attr->{f_dir} or $attr->{f_dir} = $dbh->{f_dir};
132 exists $attr->{f_dir} or $attr->{f_dir} = $dbh->{f_dir};
133 exists $attr->{f_dir_search} or $attr->{f_dir_search} = $dbh->{f_dir_search};
133134 return $dbh->SUPER::data_sources ($attr, @other);
134135 } # data_source
135136
148149 $dbh->{f_valid_attrs} = {
149150 f_version => 1, # DBD::File version
150151 f_dir => 1, # base directory
152 f_dir_search => 1, # extended search directories
151153 f_ext => 1, # file extension
152154 f_schema => 1, # schema name
153155 f_lock => 1, # Table locking mode
183185 if (0 == $phase) {
184186 # f_ext should not be initialized
185187 # f_map is deprecated (but might return)
186 $dbh->{f_dir} = Cwd::abs_path (File::Spec->curdir ());
188 $dbh->{f_dir} = Cwd::abs_path (File::Spec->curdir ());
187189
188190 push @{$dbh->{sql_init_order}{90}}, "f_meta";
189191
193195 if (exists $dbh->{$drv_prefix . "meta"} and !$dbh->{sql_engine_in_gofer}) {
194196 my $attr = $dbh->{$drv_prefix . "meta"};
195197 defined $dbh->{f_valid_attrs}{f_meta}
196 and $dbh->{f_valid_attrs}{f_meta} = 1;
198 and $dbh->{f_valid_attrs}{f_meta} = 1;
197199
198200 $dbh->{f_meta} = $dbh->{$attr};
199201 }
243245 eval {
244246 $dver = IO::File->VERSION ();
245247
246 # when we're still alive here, everthing went ok - no need to check for $@
248 # when we're still alive here, everything went ok - no need to check for $@
247249 $dtype .= " ($dver)";
248250 };
249251
345347 delete $attrs{f_dir};
346348 my $dsn_quote = $drh->{ImplementorClass}->can ("dsn_quote");
347349 my $dsnextra = join ";", map { $_ . "=" . &{$dsn_quote} ($attrs{$_}) } keys %attrs;
348 my $dirh = IO::Dir->new ($dir);
349 unless (defined $dirh) {
350 $drh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
351 return;
352 }
353
354 my ($file, @dsns, %names, $driver);
355 $driver = $drh->{ImplementorClass} =~ m/^dbd\:\:([^\:]+)\:\:/i ? $1 : "File";
356
357 while (defined ($file = $dirh->read ())) {
358 my $d = File::Spec->catdir ($dir, $file);
359 # allow current dir ... it can be a data_source too
360 $file ne File::Spec->updir () && -d $d and
361 push @dsns, "DBI:$driver:f_dir=" . &{$dsn_quote} ($d) . ($dsnextra ? ";$dsnextra" : "");
350 my @dir = ($dir);
351 $attr->{f_dir_search} && ref $attr->{f_dir_search} eq "ARRAY" and
352 push @dir, grep { -d $_ } @{$attr->{f_dir_search}};
353 my @dsns;
354 foreach $dir (@dir) {
355 my $dirh = IO::Dir->new ($dir);
356 unless (defined $dirh) {
357 $drh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
358 return;
359 }
360
361 my ($file, %names, $driver);
362 $driver = $drh->{ImplementorClass} =~ m/^dbd\:\:([^\:]+)\:\:/i ? $1 : "File";
363
364 while (defined ($file = $dirh->read ())) {
365 my $d = File::Spec->catdir ($dir, $file);
366 # allow current dir ... it can be a data_source too
367 $file ne File::Spec->updir () && -d $d and
368 push @dsns, "DBI:$driver:f_dir=" . &{$dsn_quote} ($d) . ($dsnextra ? ";$dsnextra" : "");
369 }
362370 }
363371 return @dsns;
364372 } # data_sources
367375 {
368376 my ($self, $dbh) = @_;
369377
370 my $dir = $dbh->{f_dir};
378 my $dir = $dbh->{f_dir};
371379 defined $dir or return; # Stream based db's cannot be queried for tables
372 my $dirh = IO::Dir->new ($dir);
373
374 unless (defined $dirh) {
375 $dbh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
376 return;
377 }
378
379 my $class = $dbh->FETCH ("ImplementorClass");
380 $class =~ s/::db$/::Table/;
381 my ($file, %names);
382 my $schema = exists $dbh->{f_schema}
383 ? defined $dbh->{f_schema} && $dbh->{f_schema} ne ""
384 ? $dbh->{f_schema} : undef
385 : eval { getpwuid ((stat $dir)[4]) }; # XXX Win32::pwent
380
386381 my %seen;
387382 my @tables;
388 while (defined ($file = $dirh->read ())) {
389 my ($tbl, $meta) = $class->get_table_meta ($dbh, $file, 0, 0) or next; # XXX
390 # $tbl && $meta && -f $meta->{f_fqfn} or next;
391 $seen{defined $schema ? $schema : "\0"}{$tbl}++ or
392 push @tables, [ undef, $schema, $tbl, "TABLE", "FILE" ];
393 }
394 $dirh->close () or
395 $dbh->set_err ($DBI::stderr, "Cannot close directory $dir: $!");
383 my @dir = ($dir);
384 $dbh->{f_dir_search} && ref $dbh->{f_dir_search} eq "ARRAY" and
385 push @dir, grep { -d $_ } @{$dbh->{f_dir_search}};
386 foreach $dir (@dir) {
387 my $dirh = IO::Dir->new ($dir);
388
389 unless (defined $dirh) {
390 $dbh->set_err ($DBI::stderr, "Cannot open directory $dir: $!");
391 return;
392 }
393
394 my $class = $dbh->FETCH ("ImplementorClass");
395 $class =~ s/::db$/::Table/;
396 my ($file, %names);
397 my $schema = exists $dbh->{f_schema}
398 ? defined $dbh->{f_schema} && $dbh->{f_schema} ne ""
399 ? $dbh->{f_schema} : undef
400 : eval { getpwuid ((stat $dir)[4]) }; # XXX Win32::pwent
401 while (defined ($file = $dirh->read ())) {
402 my ($tbl, $meta) = $class->get_table_meta ($dbh, $file, 0, 0) or next; # XXX
403 # $tbl && $meta && -f $meta->{f_fqfn} or next;
404 $seen{defined $schema ? $schema : "\0"}{$dir}{$tbl}++ or
405 push @tables, [ undef, $schema, $tbl, "TABLE", "FILE" ];
406 }
407 $dirh->close () or
408 $dbh->set_err ($DBI::stderr, "Cannot close directory $dir: $!");
409 }
396410
397411 return @tables;
398412 } # avail_tables
517531 }
518532
519533 # (my $tbl = $file) =~ s/$ext$//i;
520 my ($tbl, $basename, $dir, $fn_ext, $user_spec_file);
534 my ($tbl, $basename, $dir, $fn_ext, $user_spec_file, $searchdir);
521535 if ($file_is_table and defined $meta->{f_file}) {
522536 $tbl = $file;
523537 ($basename, $dir, $fn_ext) = File::Basename::fileparse ($meta->{f_file}, $fn_any_ext_regex);
526540 }
527541 else {
528542 ($basename, $dir, undef) = File::Basename::fileparse ($file, $ext);
543 # $dir is returned with trailing (back)slash. We just need to check
544 # if it is ".", "./", or ".\" or "[]" (VMS)
545 if ($dir =~ m{^(?:[.][/\\]?|\[\])$} && ref $meta->{f_dir_search} eq "ARRAY") {
546 foreach my $d ($meta->{f_dir}, @{$meta->{f_dir_search}}) {
547 my $f = File::Spec->catdir ($d, $file);
548 -f $f or next;
549 $searchdir = Cwd::abs_path ($d);
550 $dir = "";
551 last;
552 }
553 }
529554 $file = $tbl = $basename;
530555 $user_spec_file = 0;
531556 }
539564 $tbl = lc $tbl;
540565 }
541566
542 my $searchdir = File::Spec->file_name_is_absolute ($dir)
543 ? ($dir =~ s{/$}{}, $dir)
544 : Cwd::abs_path (File::Spec->catdir ($meta->{f_dir}, $dir));
567 unless (defined $searchdir) {
568 $searchdir = File::Spec->file_name_is_absolute ($dir)
569 ? ($dir =~ s{/$}{}, $dir)
570 : Cwd::abs_path (File::Spec->catdir ($meta->{f_dir}, $dir));
571 }
545572 -d $searchdir or
546573 croak "-d $searchdir: $!";
547574
752779
753780 $self->SUPER::bootstrap_table_meta ($dbh, $meta, $table, @other);
754781
755 exists $meta->{f_dir} or $meta->{f_dir} = $dbh->{f_dir};
756 defined $meta->{f_ext} or $meta->{f_ext} = $dbh->{f_ext};
757 defined $meta->{f_encoding} or $meta->{f_encoding} = $dbh->{f_encoding};
758 exists $meta->{f_lock} or $meta->{f_lock} = $dbh->{f_lock};
759 exists $meta->{f_lockfile} or $meta->{f_lockfile} = $dbh->{f_lockfile};
760 defined $meta->{f_schema} or $meta->{f_schema} = $dbh->{f_schema};
782 exists $meta->{f_dir} or $meta->{f_dir} = $dbh->{f_dir};
783 exists $meta->{f_dir_search} or $meta->{f_dir_search} = $dbh->{f_dir_search};
784 defined $meta->{f_ext} or $meta->{f_ext} = $dbh->{f_ext};
785 defined $meta->{f_encoding} or $meta->{f_encoding} = $dbh->{f_encoding};
786 exists $meta->{f_lock} or $meta->{f_lock} = $dbh->{f_lock};
787 exists $meta->{f_lockfile} or $meta->{f_lockfile} = $dbh->{f_lockfile};
788 defined $meta->{f_schema} or $meta->{f_schema} = $dbh->{f_schema};
761789
762790 defined $meta->{f_open_file_needed} or
763791 $meta->{f_open_file_needed} = $self->can ("open_file") != DBD::File::Table->can ("open_file");
780808 } # get_table_meta
781809
782810 my %reset_on_modify = (
783 f_file => [ "f_fqfn", "sql_data_source" ],
784 f_dir => "f_fqfn",
785 f_ext => "f_fqfn",
786 f_lockfile => "f_fqfn", # forces new file2table call
811 f_file => [ "f_fqfn", "sql_data_source" ],
812 f_dir => "f_fqfn",
813 f_dir_search => [],
814 f_ext => "f_fqfn",
815 f_lockfile => "f_fqfn", # forces new file2table call
787816 );
788817
789818 __PACKAGE__->register_reset_on_modify (\%reset_on_modify);
962991 the appropriate absolute path name (based on the current working
963992 directory) when the dbh attribute is set.
964993
994 f_dir => "/data/foo/csv",
995
965996 See L<KNOWN BUGS AND LIMITATIONS>.
997
998 =head4 f_dir_search
999
1000 This optional attribute can be set to pass a list of folders to also
1001 find existing tables. It will B<not> be used to create new files.
1002
1003 f_dir_search => [ "/data/bar/csv", "/dump/blargh/data" ],
9661004
9671005 =head4 f_ext
9681006
9721010
9731011 where the /flag is optional and the extension is case-insensitive.
9741012 C<f_ext> allows you to specify an extension which:
1013
1014 f_ext => ".csv/r",
9751015
9761016 =over
9771017
12531293
12541294 =item f_dir
12551295
1296 =item f_dir_search
1297
12561298 =item f_lock
12571299
12581300 =item f_lockfile
1010 use warnings;
1111 use Carp;
1212
13 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
13 our $VERSION = "0.010088";
1414 our $AUTOLOAD;
1515
1616 my %policy_defaults = (
4949 sub create_policy_subs {
5050 my ($class, $policy_defaults) = @_;
5151
52 while ( my ($policy_name, $policy_default) = each %$policy_defaults) {
52 while ( my ($policy_name, $policy_default) = each %$policy_defaults) {
5353 my $policy_attr_name = "go_$policy_name";
5454 my $sub = sub {
5555 # $policy->foo($attr, ...)
105105 =head1 POLICY CLASSES
106106
107107 Three policy classes are supplied with DBD::Gofer:
108
108
109109 L<DBD::Gofer::Policy::pedantic> is most 'transparent' but slowest because it
110110 makes more round-trips to the Gofer server.
111111
112112 L<DBD::Gofer::Policy::classic> is a reasonable compromise - it's the default policy.
113
113
114114 L<DBD::Gofer::Policy::rush> is fastest, but may require code changes in your applications.
115115
116116 Generally the default C<classic> policy is fine. When first testing an existing
99 use strict;
1010 use warnings;
1111
12 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
12 our $VERSION = "0.010088";
1313
1414 use base qw(DBD::Gofer::Policy::Base);
1515
99 use strict;
1010 use warnings;
1111
12 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
12 our $VERSION = "0.010088";
1313
1414 use base qw(DBD::Gofer::Policy::Base);
1515
99 use strict;
1010 use warnings;
1111
12 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
12 our $VERSION = "0.010088";
1313
1414 use base qw(DBD::Gofer::Policy::Base);
1515
1111
1212 use base qw(DBI::Gofer::Transport::Base);
1313
14 our $VERSION = sprintf("0.%06d", q$Revision: 14120 $ =~ /(\d+)/o);
14 our $VERSION = "0.014121";
1515
1616 __PACKAGE__->mk_accessors(qw(
1717 trace
3737 $args->{keep_meta_frozen} ||= 1 if $args->{go_cache};
3838 #warn "args @{[ %$args ]}\n";
3939 return $class->SUPER::new($args);
40 }
40 }
4141
4242
4343 sub _init_trace { $ENV{DBD_GOFER_TRACE} || 0 }
183183 # This is the main decision point. We don't retry requests that got
184184 # as far as executing because the error is probably from the database
185185 # (not transport) so retrying is unlikely to help. But note that any
186 # severe transport error occuring after execute is likely to return
186 # severe transport error occurring after execute is likely to return
187187 # a new response object that doesn't have the execute flag set. Beware!
188188 return 0 if $response->executed_flag_set;
189189
1313
1414 use DBI::Gofer::Execute;
1515
16 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
16 our $VERSION = "0.010088";
1717
1818 __PACKAGE__->mk_accessors(qw(
1919 pending_response
2020 transmit_count
21 ));
21 ));
2222
2323 my $executor = DBI::Gofer::Execute->new();
2424
8585
8686 Also, by measuring the difference in performance between normal connections and
8787 connections via C<dbi:Gofer:transport=null> the basic cost of using DBD::Gofer
88 can be measured. Furthermore, the additional cost of more advanced transports can be
88 can be measured. Furthermore, the additional cost of more advanced transports can be
8989 isolated by comparing their performance with the null transport.
9090
9191 The C<t/85gofer.t> script in the DBI distribution includes a comparative benchmark.
1717
1818 use base qw(DBD::Gofer::Transport::Base);
1919
20 our $VERSION = sprintf("0.%06d", q$Revision: 10087 $ =~ /(\d+)/o);
20 our $VERSION = "0.010088";
2121
2222 __PACKAGE__->mk_accessors(qw(
2323 connection_info
2424 go_perl
25 ));
25 ));
2626
2727
2828 sub new {
4343
4444
4545 # nonblock($fh) puts filehandle into nonblocking mode
46 sub nonblock {
46 sub nonblock {
4747 my $fh = shift;
4848 my $flags = fcntl($fh, F_GETFL, 0)
4949 or croak "Can't get flags for filehandle $fh: $!";
1313
1414 use base qw(DBD::Gofer::Transport::pipeone);
1515
16 our $VERSION = sprintf("0.%06d", q$Revision: 14598 $ =~ /(\d+)/o);
16 our $VERSION = "0.014599";
1717
1818 __PACKAGE__->mk_accessors(qw(
1919 go_persist
20 ));
20 ));
2121
2222 my $persist_all = 5;
2323 my %persist;
196196 $response->add_err(0, $stderr_msg, undef, $trace)
197197 # but ignore warning from old version of blib
198198 unless $stderr_msg =~ /^Using .*blib/ && "@$cmd" =~ /-Mblib/;
199 }
199 }
200200
201201 return $response;
202202 }
77 require DBI::Gofer::Response;
88 require Carp;
99
10 our $VERSION = sprintf("0.%06d", q$Revision: 15326 $ =~ /(\d+)/o);
10 our $VERSION = "0.015327";
1111
1212 # $Id: Gofer.pm 15326 2012-06-06 16:32:38Z Tim $
1313 #
692692 or return undef; # no more result sets
693693 #warn "more_results: ".Data::Dumper::Dumper($meta);
694694
695 # pull out the special non-atributes first
695 # pull out the special non-attributes first
696696 my ($rowset, $err, $errstr, $state)
697697 = delete @{$meta}{qw(rowset err errstr state)};
698698
11581158 $transport = $h->{go_transport};
11591159 $retry = $transport->go_retry_hook->($request, $response, $transport);
11601160
1161 If it returns true then the request will be retried, upto the C<retry_limit>.
1161 If it returns true then the request will be retried, up to the C<retry_limit>.
11621162 If it returns a false but defined value then the request will not be retried.
11631163 If it returns undef then the default behaviour will be used, as if C<retry_hook>
11641164 had not been specified.
11651165
11661166 The default behaviour is to retry requests where $request->is_idempotent is true,
11671167 or the error message matches C</induced by DBI_GOFER_RANDOM/>.
1168
1168
11691169 =head3 cache
11701170
11711171 Specifies that client-side caching should be performed. The value is the name
44 require Carp;
55
66 @EXPORT = qw(); # Do NOT @EXPORT anything.
7 $VERSION = sprintf("12.%06d", q$Revision: 14714 $ =~ /(\d+)/o);
7 $VERSION = "12.014715";
88
99 # $Id: NullP.pm 14714 2011-02-22 17:27:07Z Tim $
1010 #
4040 sub connect { # normally overridden, but a handy default
4141 my $dbh = shift->SUPER::connect(@_)
4242 or return;
43 $dbh->STORE(Active => 1);
43 $dbh->STORE(Active => 1);
4444 $dbh;
4545 }
4646
104104 $sth->{ParamAttr}{$param} = $attr
105105 if defined $attr; # attr is sticky if not explicitly set
106106 return 1;
107 }
107 }
108108
109109 sub execute {
110110 my $sth = shift;
111111 $sth->bind_param($_, $_[$_-1]) for (1..@_);
112112 if ($sth->{Statement} =~ m/^ \s* SELECT \s+/xmsi) {
113 $sth->STORE(NUM_OF_FIELDS => 1);
113 $sth->STORE(NUM_OF_FIELDS => 1);
114114 $sth->{NAME} = [ "fieldname" ];
115115 # just for the sake of returning something, we return the params
116116 my $params = $sth->{ParamValues} || {};
117117 $sth->{dbd_nullp_data} = [ @{$params}{ sort keys %$params } ];
118 $sth->STORE(Active => 1);
118 $sth->STORE(Active => 1);
119119 }
120120 # force a sleep - handy for testing
121121 elsif ($sth->{Statement} =~ m/^ \s* SLEEP \s+ (\S+) /xmsi) {
131131 elsif ($sth->{Statement} =~ m/^ \s* ERROR \s+ (\d+) \s* (.*) /xmsi) {
132132 return $sth->set_err($1, $2);
133133 }
134 # anything else is silently ignored, sucessfully
134 # anything else is silently ignored, successfully
135135 1;
136136 }
137137
884884
885885 However, if you set the I<proxy_no_finish> attribute to a TRUE value,
886886 either in the database handle or in the statement handle, then finish()
887 calls will be supressed. This is what you want, for example, in small
887 calls will be suppressed. This is what you want, for example, in small
888888 and fast CGI applications.
889889
890890 =item proxy_quote
44 require Carp;
55
66 our @EXPORT = qw(); # Do NOT @EXPORT anything.
7 our $VERSION = sprintf("12.%06d", q$Revision: 10002 $ =~ /(\d+)/o);
8
7 our $VERSION = "12.010003";
98
109 # $Id: Sponge.pm 10002 2007-09-26 21:03:25Z Tim $
1110 #
213212
214213 1;
215214
216 __END__
215 __END__
217216
218217 =pod
219218
273272 =item *
274273
275274 C<$names> is a reference an array of column names for the C<$data> you are providing.
276 The number and order should match the number and ordering of the C<$data> columns.
275 The number and order should match the number and ordering of the C<$data> columns.
277276
278277 =item *
279278
3737 =cut
3838
3939 my
40 $VERSION = sprintf("2.%06d", q$Revision: 8696 $ =~ /(\d+)/o);
41
40 $VERSION = "2.008697";
4241
4342 %InfoTypes =
4443 (
2121
2222 Information requested by GetInfo().
2323
24 The API for this module is private and subject to change.
24 The API for this module is private and subject to change.
2525
2626 =head1 REFERENCES
2727
3434 =cut
3535
3636 my
37 $VERSION = sprintf("2.%06d", q$Revision: 11373 $ =~ /(\d+)/o);
38
37 $VERSION = "2.011374";
3938
4039 %InfoTypes =
4140 (
9998 , SQL_CURSOR_SENSITIVITY => 10001
10099 , SQL_DATA_SOURCE_NAME => 2
101100 , SQL_DATA_SOURCE_READ_ONLY => 25
102 , SQL_DATABASE_NAME => 16
101 , SQL_DATABASE_NAME => 16
103102 , SQL_DATETIME_LITERALS => 119
104103 , SQL_DBMS_NAME => 17
105104 , SQL_DBMS_VER => 18
328327 , SQL_CURSOR_SENSITIVITY => 'SQLUINTEGER' # 10001
329328 , SQL_DATA_SOURCE_NAME => 'SQLCHAR' # 2
330329 , SQL_DATA_SOURCE_READ_ONLY => 'SQLCHAR' # 25
331 , SQL_DATABASE_NAME => 'SQLCHAR' # 16
330 , SQL_DATABASE_NAME => 'SQLCHAR' # 16
332331 , SQL_DATETIME_LITERALS => 'SQLUINTEGER bitmask' # 119
333332 , SQL_DBMS_NAME => 'SQLCHAR' # 17
334333 , SQL_DBMS_VER => 'SQLCHAR' # 18
1818 @EXPORT = qw(%GetInfoReturnTypes %GetInfoReturnValues);
1919
2020 my
21 $VERSION = sprintf("2.%06d", q$Revision: 8696 $ =~ /(\d+)/o);
22
21 $VERSION = "2.008697";
2322
2423 =head1 NAME
2524
1818 @EXPORT = qw(%GetInfoType);
1919
2020 my
21 $VERSION = sprintf("2.%06d", q$Revision: 8696 $ =~ /(\d+)/o);
22
21 $VERSION = "2.008697";
2322
2423 =head1 NAME
2524
1717 @ISA = qw(Exporter);
1818 @EXPORT = qw(write_getinfo_pm write_typeinfo_pm);
1919
20 $VERSION = sprintf("2.%06d", q$Revision: 14213 $ =~ /(\d+)/o);
21
20 $VERSION = "2.014214";
2221
2322 use strict;
2423
5353 # We use a hash here to have one singleton per subclass.
5454 # (Otherwise DBD::CSV and DBD::DBM, for example, would
5555 # share the same driver object which would cause problems.)
56 # An alternative would be not not cache the $drh here at all
56 # An alternative would be to not cache the $drh here at all
5757 # and require that subclasses do that. Subclasses should do
5858 # their own caching, so caching here just provides extra safety.
5959 $drh->{$class} and return $drh->{$class};
12681268 {
12691269 $sth->set_err(
12701270 $DBI::stderr,
1271 "Attempt to fetch row without a preceeding execute () call or from a non-SELECT statement"
1271 "Attempt to fetch row without a preceding execute () call or from a non-SELECT statement"
12721272 );
12731273 return;
12741274 }
20232023
20242024 $dbh->func( "list_tables" );
20252025
2026 Everytime where an C<\%attr> argument can be specified, this C<\%attr>
2026 Every time where an C<\%attr> argument can be specified, this C<\%attr>
20272027 object's C<sql_table_source> attribute is preferred over the C<$dbh>
20282028 attribute or the driver default, eg.
20292029
44
55 # don't use Revision here because that's not in svn:keywords so that the
66 # examples that use it below won't be messed up
7 $VERSION = sprintf("12.%06d", q$Id: DBD.pm 15128 2012-02-04 20:51:39Z Tim $ =~ /(\d+)/o);
8
7 $VERSION = "12.015129";
98
109 # $Id: DBD.pm 15128 2012-02-04 20:51:39Z Tim $
1110 #
693692
694693 For Subversion you could use:
695694
696 $VERSION = sprintf("12.%06d", q$Revision: 12345 $ =~ /(\d+)/o);
695 $VERSION = "12.012346";
697696
698697 (use lots of leading zeros on the second portion so if you move the code to a
699698 shared repository like svn.perl.org the much larger revision numbers won't
700699 cause a problem, at least not for a few years). For RCS or CVS you can use:
701700
702 $VERSION = sprintf "%d.%02d", '$Revision: 11.21 $ ' =~ /(\d+)\.(\d+)/;
701 $VERSION = "11.22";
703702
704703 which pads out the fractional part with leading zeros so all is well
705704 (so long as you don't go past x.99)
796795
797796 Methods installed using install_method default to the standard error
798797 handling behaviour for DBI methods: clearing err and errstr before
799 calling the method, and checking for errors to trigger RaiseError
800 etc. on return. This differs from the default behaviour of func().
798 calling the method, and checking for errors to trigger RaiseError
799 etc. on return. This differs from the default behaviour of func().
801800
802801 Note for driver authors: The DBD::Foo::xx->install_method call won't
803802 work until the class-hierarchy has been setup. Normally the DBI
34533452 my $dbi_driver_xst= File::Spec->catfile($dbi_instarch_dir, 'Driver.xst');
34543453 my $xstf_h = File::Spec->catfile($dbi_instarch_dir, 'Driver_xst.h');
34553454
3456 # we must be careful of quotes, expecially for Win32 here.
3455 # we must be careful of quotes, especially for Win32 here.
34573456 return '
34583457 # --- This section was generated by DBI::DBD::dbd_postamble()
34593458 DBI_INSTARCH_DIR='.$dbi_instarch_dir.'
34603459 DBI_DRIVER_XST='.$dbi_driver_xst.'
34613460
3462 # The main dependancy (technically correct but probably not used)
3461 # The main dependency (technically correct but probably not used)
34633462 $(BASEEXT).c: $(BASEEXT).xsi
34643463
3465 # This dependancy is needed since MakeMaker uses the .xs.o rule
3464 # This dependency is needed since MakeMaker uses the .xs.o rule
34663465 $(BASEEXT)$(OBJ_EXT): $(BASEEXT).xsi
34673466
34683467 $(BASEEXT).xsi: $(DBI_DRIVER_XST) '.$xstf_h.'
77 ### This document is Copyright (c)1994-2000 Alligator Descartes, with portions
88 ### Copyright (c)1994-2000 their original authors. This module is released under
99 ### the 'Artistic' license which you can find in the perl distribution.
10 ###
10 ###
1111 ### This document is Copyright (c)1997-2000 Alligator Descartes. All rights reserved.
1212 ### Permission to distribute this document, in full or in part, via email,
1313 ### Usenet, ftp archives or http is granted providing that no charges are involved,
1414 ### reasonable attempt is made to use the most current version and all credits
1515 ### and copyright notices are retained ( the I<AUTHOR> and I<COPYRIGHT> sections ).
16 ### Requests for other distribution rights, including incorporation into
16 ### Requests for other distribution rights, including incorporation into
1717 ### commercial products, such as books, magazine articles or CD-ROMs should be
1818 ### made to Alligator Descartes.
19 ###
19 ###
2020
2121 package DBI::FAQ;
2222
23 our $VERSION = sprintf("1.%06d", q$Revision: 14934 $ =~ /(\d+)/o);
24
23 our $VERSION = "1.014935";
2524
2625 =head1 NAME
2726
139138 DBD::Informix Isqlperl Under development
140139 DBD::Ingres Ingperl Complete?
141140 DBD::Sybase Sybperl Working? ( Needs verification )
142 DBD::mSQL Msqlperl Experimentally released with
141 DBD::mSQL Msqlperl Experimentally released with
143142 DBD::mSQL-0.61
144143
145144 The I<Msqlperl> emulation is a special case. I<Msqlperl> is a perl5 driver
153152
154153 The Comprehensive Perl Archive Network
155154 resources should be used for retrieving up-to-date versions of the DBI
156 and drivers. CPAN may be accessed I<via> Tom Christiansen's splendid
155 and drivers. CPAN may be accessed I<via> Tom Christiansen's splendid
157156 I<CPAN multiplexer> program located at:
158157
159158 http://www.perl.com/CPAN/
168167
169168 =head2 1.3. Where can I get more information?
170169
171 There are a few information sources on DBI.
170 There are a few information sources on DBI.
172171
173172 =over 4
174173
250249
251250 I<POD>s are chunks of documentation usually embedded within perl programs
252251 that document the code ``I<in place>'', providing a useful resource for
253 programmers and users of modules. POD for DBI and drivers is beginning to
252 programmers and users of modules. POD for DBI and drivers is beginning to
254253 become more commonplace, and documentation for these modules can be read
255254 with the C<perldoc> program included with Perl.
256255
257 =over 4
256 =over 4
258257
259258 =item The DBI Specification
260259
282281
283282 perldoc <driver>
284283
285 For example, the I<DBD::mSQL> driver is bundled with driver-specific
284 For example, the I<DBD::mSQL> driver is bundled with driver-specific
286285 documentation that can be accessed by typing
287286
288287 perldoc DBD::mSQL
310309
311310 Users with the Tk module installed may be interested to learn there is a
312311 Tk-based POD reader available called C<tkpod>, which formats POD in a convenient
313 and readable way. This is available I<via> CPAN as the module called
312 and readable way. This is available I<via> CPAN as the module called
314313 I<Tk::POD> and is highly recommended.
315314
316315 =back
348347
349348 =item I<README files>
350349
351 The I<README> files included with each driver occasionally contains
350 The I<README> files included with each driver occasionally contains
352351 some useful information ( no, really! ) that may be pertinent to the user.
353352 Please read them. It makes our worthless existences more bearable. These
354353 can all be read from the main DBI WWW page at:
395394
396395 =head2 2.1. Compilation problems or "It fails the test!"
397396
398 First off, consult the README for that driver in case there is useful
399 information about the problem. It may be a known problem for your given
397 First off, consult the README for that driver in case there is useful
398 information about the problem. It may be a known problem for your given
400399 architecture and operating system or database. You can check the README
401400 files for each driver in advance online at:
402401
403402 http://dbi.perl.org/
404403
405 If it's a known problem, you'll probably have to wait till it gets fixed. If
404 If it's a known problem, you'll probably have to wait till it gets fixed. If
406405 you're I<really> needing it fixed, try the following:
407406
408407 =over 4
425424
426425 =item *
427426
428 Platform information, database version, perl version, module version and
427 Platform information, database version, perl version, module version and
429428 DBI version.
430429
431430 =back
473472
474473 =back
475474
476 Remember, the more information you send us, the quicker we can track
475 Remember, the more information you send us, the quicker we can track
477476 problems down. If you send us no useful information, expect nothing back.
478477
479478 Finally, please be aware that some authors, including Tim Bunce, specifically
553552 come on by great leaps and bounds.
554553
555554 The I<DBI> and I<DBD::Oracle> Win32 ports are now a standard part of DBI,
556 so, downloading I<DBI> of version higher than I<0.81> should work fine as
555 so, downloading I<DBI> of version higher than I<0.81> should work fine as
557556 should using the most recent I<DBD::Oracle> version.
558557
559558 =head2 3.4 Can I access Microsoft Access or SQL-Server databases with DBI?
598597 limitation on the usefulness of dbm systems.
599598
600599 However, dbm systems still provide a useful function for users with
601 simple datasets and limited resources, since they are fast, robust and
600 simple datasets and limited resources, since they are fast, robust and
602601 extremely well-tested. Perl modules to access dbm systems have now
603602 been integrated into the core Perl distribution via the
604603 AnyDBM_File module.''
605604
606605 To sum up, DBM is a perfectly satisfactory solution for essentially read-only
607 databases, or small and simple datasets. However, for more
608 scaleable dataset handling, not to mention robust transactional locking,
606 databases, or small and simple datasets. However, for more
607 scalable dataset handling, not to mention robust transactional locking,
609608 users are recommended to use a more powerful database engine I<via> I<DBI>.
610609
611610 Chapter 2 of "Programming the Perl DBI" discusses DBM files in detail.
683682
684683 Contributed by John D. Groenveld
685684
686 The Apache C<httpd> maintains a pool of C<httpd> children to service client
685 The Apache C<httpd> maintains a pool of C<httpd> children to service client
687686 requests.
688687
689 Using the Apache I<mod_perl> module by I<Doug MacEachern>, the perl
690 interpreter is embedded with the C<httpd> children. The CGI, DBI, and your
691 other favorite modules can be loaded at the startup of each child. These
688 Using the Apache I<mod_perl> module by I<Doug MacEachern>, the perl
689 interpreter is embedded with the C<httpd> children. The CGI, DBI, and your
690 other favorite modules can be loaded at the startup of each child. These
692691 modules will not be reloaded unless changed on disk.
693692
694693 For more information on Apache, see the Apache Project's WWW site:
703702
704703 Contributed by John D. Groenveld
705704
706 Using Edmund Mergl's I<Apache::DBI> module, database logins are stored in a
707 hash with each of these C<httpd> child. If your application is based on a
708 single database user, this connection can be started with each child.
705 Using Edmund Mergl's I<Apache::DBI> module, database logins are stored in a
706 hash with each of these C<httpd> child. If your application is based on a
707 single database user, this connection can be started with each child.
709708 Currently, database connections cannot be shared between C<httpd> children.
710709
711710 I<Apache::DBI> can be downloaded from CPAN I<via>:
725724
726725 One way to solve this problem is to set the environment for your database in a
727726 C<BEGIN { }> block at the top of your script. Another technique is to configure
728 your WWW server to pass-through certain environment variables to your CGI
727 your WWW server to pass-through certain environment variables to your CGI
729728 scripts.
730729
731730 Similarly, you should check your C<httpd> error logfile for any clues,
737736
738737 http://www.perl.com/perl/faq/index.html
739738
740 as can the ``Perl CGI Programming FAQ''. Read I<BOTH> these documents
739 as can the ``Perl CGI Programming FAQ''. Read I<BOTH> these documents
741740 carefully!
742741
743742 =head2 4.5 How do I get the number of rows returned from a C<SELECT> statement?
755754
756755 It is expected that some future version of the DBI will at least be
757756 thread-safe (but not thread-hot) by automatically blocking threads
758 intering the DBI while it's already in use.
757 entering the DBI while it's already in use.
759758
760759 =head2 5.2 How do I handle BLOB data with DBI?
761760
787786 size of C<LongReadLen> if it is longer. This does not cause an error to
788787 occur, but may make your fetched BLOB data useless.
789788
790 This behaviour is regulated by the C<LongTruncOk> attribute which is
791 defaultly set to a false value ( thus making overlong BLOB fetches fail ).
789 This behaviour is regulated by the C<LongTruncOk> attribute which is
790 set to a false value by default ( thus making overlong BLOB fetches fail ).
792791
793792 ### Set BLOB handling such that it's 16Kb and can be truncated
794793 $dbh->{LongReadLen} = 16384;
955954 Usenet, ftp archives or http is granted providing that no charges are involved,
956955 reasonable attempt is made to use the most current version and all credits
957956 and copyright notices are retained ( the I<AUTHOR> and I<COPYRIGHT> sections ).
958 Requests for other distribution rights, including incorporation into
957 Requests for other distribution rights, including incorporation into
959958 commercial products, such as books, magazine articles or CD-ROMs should be
960959 made to Alligator Descartes.
961960
1717
1818 use base qw(DBI::Util::_accessor);
1919
20 our $VERSION = sprintf("0.%06d", q$Revision: 14282 $ =~ /(\d+)/o);
20 our $VERSION = "0.014283";
2121
2222 our @all_dbh_methods = sort map { keys %$_ } $DBI::DBI_methods{db}, $DBI::DBI_methods{common};
2323 our %all_dbh_methods = map { $_ => (DBD::_::db->can($_)||undef) } @all_dbh_methods;
212212 $dbh->{ShowErrorStatement} = 1 if $local_log;
213213
214214 # XXX should probably just be a Callbacks => arg to connect_cached
215 # with a cache of pre-built callback hooks (memoized, without $self)
215 # with a cache of pre-built callback hooks (memoized, without $self)
216216 if (my $random = $self->{forced_gofer_random} || $ENV{DBI_GOFER_RANDOM}) {
217217 $self->_install_rand_callbacks($dbh, $random);
218218 }
372372
373373 # XXX piggyback installed_methods onto dbh_attributes for now
374374 $dbh_attr_values{dbi_installed_methods} = { DBI->installed_methods };
375
375
376376 # XXX piggyback default_methods onto dbh_attributes for now
377377 $dbh_attr_values{dbi_default_methods} = _get_default_methods($dbh);
378
378
379379 return \%dbh_attr_values;
380380 }
381381
498498 my $sth_attr = {};
499499 $sth_attr->{$_} = 1 for @$attr_names;
500500
501 # let the client add/remove sth atributes
501 # let the client add/remove sth attributes
502502 if (my $sth_result_attr = $request->sth_result_attr) {
503503 $sth_attr->{$_} = $sth_result_attr->{$_}
504504 for keys %$sth_result_attr;
612612 next;
613613 }
614614 unless (defined $fail_percent or defined $delay_percent) {
615 warn "Ignored DBI_GOFER_RANDOM item '$spec' because not preceeded by 'fail=N' and/or 'delayN=N'";
615 warn "Ignored DBI_GOFER_RANDOM item '$spec' because not preceded by 'fail=N' and/or 'delayN=N'";
616616 next;
617617 }
618618
1212
1313 use base qw(DBI::Util::_accessor);
1414
15 our $VERSION = sprintf("0.%06d", q$Revision: 12536 $ =~ /(\d+)/o);
15 our $VERSION = "0.012537";
1616
1717 use constant GOf_REQUEST_IDEMPOTENT => 0x0001;
1818 use constant GOf_REQUEST_READONLY => 0x0002;
111111 $method ||= 'connect_cached';
112112 $pass = '***' if defined $pass;
113113 my $tmp = '';
114 if ($attr) {
114 if ($attr) {
115115 $tmp = { %{$attr||{}} }; # copy so we can edit
116116 $tmp->{Password} = '***' if exists $tmp->{Password};
117117 $tmp = "{ ".neat_list([ %$tmp ])." }";
1313
1414 use base qw(DBI::Util::_accessor Exporter);
1515
16 our $VERSION = sprintf("0.%06d", q$Revision: 11565 $ =~ /(\d+)/o);
16 our $VERSION = "0.011566";
1717
1818 use constant GOf_RESPONSE_EXECUTED => 0x0001;
1919
4242 $args->{version} ||= $VERSION;
4343 chomp $args->{errstr} if $args->{errstr};
4444 return $self->SUPER::new($args);
45 }
45 }
4646
4747
4848 sub err_errstr_state {
7676 $r_errstr .= sprintf " [state was %s now %s]", $r_state, $state
7777 if $r_state and $r_state ne "S1000" && $state && $r_state ne $state;
7878 $r_errstr .= "\n$errstr" if $r_errstr ne $errstr;
79 }
80 else {
79 }
80 else {
8181 $r_errstr = $errstr;
8282 }
8383
120120 my @keys = sort keys %$dbh_attr;
121121 push @s, sprintf "dbh= { %s }", join(", ", map { "$_=>".neat($dbh_attr->{$_},100) } @keys)
122122 if @keys;
123 }
123 }
124124
125125 for my $rs (@{$self->sth_resultsets || []}) {
126126 my ($rowset, $err, $errstr, $state)
134134 $summary .= sprintf ", err=%s, errstr=%s", $err, neat($errstr) if defined $err;
135135 if ($rows) {
136136 my $NAME = $rs->{NAME};
137 # generate
137 # generate
138138 my @colinfo = map { "$NAME->[$_]=".neat($rowset->[0][$_], 30) } 0..@{$NAME}-1;
139139 $summary .= sprintf " [%s]", join ", ", @colinfo;
140140 $summary .= ",..." if $rows > 1;
148148 chomp $w;
149149 push @s, "warning: $w";
150150 }
151 if ($context && %$context) {
151 if ($context && %$context) {
152152 my @keys = sort keys %$context;
153153 push @s, join(", ", map { "$_=>".$context->{$_} } @keys);
154 }
154 }
155155 return join("\n\t", @s). "\n";
156156 }
157157
3434
3535 use Carp qw(croak);
3636
37 our $VERSION = sprintf("0.%06d", q$Revision: 9949 $ =~ /(\d+)/o);
37 our $VERSION = "0.009950";
3838
3939
4040 sub new {
22 use strict;
33 use warnings;
44
5 our $VERSION = sprintf("0.%06d", q$Revision: 9949 $ =~ /(\d+)/o);
5 our $VERSION = "0.009950";
66
77 # $Id: DataDumper.pm 9949 2007-09-18 09:38:15Z Tim $
88 #
3737
3838 use Storable qw(nfreeze thaw);
3939
40 our $VERSION = sprintf("0.%06d", q$Revision: 15585 $ =~ /(\d+)/o);
40 our $VERSION = "0.015586";
4141
4242 use base qw(DBI::Gofer::Serializer::Base);
4343
1616 use DBI::Gofer::Serializer::Storable;
1717 use DBI::Gofer::Serializer::DataDumper;
1818
19
20 our $VERSION = sprintf("0.%06d", q$Revision: 12536 $ =~ /(\d+)/o);
21
19 our $VERSION = "0.012537";
2220
2321 __PACKAGE__->mk_accessors(qw(
2422 trace
1313
1414 use base qw(DBI::Gofer::Transport::Base Exporter);
1515
16 our $VERSION = sprintf("0.%06d", q$Revision: 12536 $ =~ /(\d+)/o);
16 our $VERSION = "0.012537";
1717
1818 our @EXPORT = qw(run_one_stdio);
1919
1414
1515 use base qw(DBI::Gofer::Transport::pipeone Exporter);
1616
17 our $VERSION = sprintf("0.%06d", q$Revision: 12536 $ =~ /(\d+)/o);
17 our $VERSION = "0.012537";
1818
1919 our @EXPORT = qw(run_stdio_hex);
2020
475475 If not specified it defaults to $dbh->{Profile}{Data}.
476476
477477 The $path argument can be used to specify a list of path elements that will be
478 added to each element of the returned list. If not specified it defaults to a a
478 added to each element of the returned list. If not specified it defaults to a
479479 ref to an empty array.
480480
481481 =head2 as_text
546546 my $totals=[],
547547 [ 10, 0.51, 0.11, 0.01, 0.22, 1023110000, 1023110010 ],
548548 [ 15, 0.42, 0.12, 0.02, 0.23, 1023110005, 1023110009 ],
549 );
549 );
550550
551551 $totals will then contain
552552
555555 and $time_in_dbi will be 0.93;
556556
557557 The second argument need not be just leaf nodes. If given a reference to a hash
558 then the hash is recursively searched for for leaf nodes and all those found
558 then the hash is recursively searched for leaf nodes and all those found
559559 are merged.
560560
561561 For example, to get the time spent 'inside' the DBI during an http request,
662662 much better than integer resolution. This limited resolution means
663663 that fast method calls will often register as taking 0 time. And
664664 timings in general will have much more 'jitter' depending on where
665 within the 'current millisecond' the start and and timing was taken.
665 within the 'current millisecond' the start and end timing was taken.
666666
667667 This documentation could be more clear. Probably needs to be reordered
668668 to start with several examples and build from there. Trying to
680680
681681 use DBI qw(dbi_time dbi_profile dbi_profile_merge_nodes dbi_profile_merge);
682682
683 $VERSION = sprintf("2.%06d", q$Revision: 15064 $ =~ /(\d+)/o);
684
683 $VERSION = "2.015065";
685684
686685 @ISA = qw(Exporter);
687686 @EXPORT = qw(
719718 # assigned to the Profile attribute. For example
720719 # dbi:mysql(RaiseError=>1,Profile=>!Statement:!MethodName/DBIx::MyProfile/arg1:arg2):dbname
721720 # This sub works out what to do and returns a suitable hash ref.
722
721
723722 $arg =~ s/^DBI::/2\/DBI::/
724723 and carp "Automatically changed old-style DBI::Profile specification to $arg";
725724
757756 }
758757 }
759758
760 eval "require $package" if $package; # sliently ignores errors
759 eval "require $package" if $package; # silently ignores errors
761760 $package ||= $class;
762761
763762 return $package->new(Path => \@Path, @args);
768767 my $self = shift;
769768 DBI->trace_msg("profile data discarded\n",0) if $self->{Trace};
770769 $self->{Data} = undef;
771 }
770 }
772771
773772 sub filename { # baseclass method, see DBI::ProfileDumper
774773 return undef;
786785 sub as_node_path_list {
787786 my ($self, $node, $path) = @_;
788787 # convert the tree into an array of arrays
789 # from
788 # from
790789 # {key1a}{key2a}[node1]
791790 # {key1a}{key2b}[node2]
792791 # {key1b}{key2a}{key3a}[node3]
815814 || "%s"; # or e.g., " key%2$d='%s'"
816815 my $format = $args_ref->{format}
817816 || '%1$s: %11$fs / %10$d = %2$fs avg (first %12$fs, min %13$fs, max %14$fs)'."\n";
818
817
819818 my @node_path_list = $self->as_node_path_list(undef, $args_ref->{path});
820819
821820 $args_ref->{sortsub}->(\@node_path_list) if $args_ref->{sortsub};
838837 ($node->[0] ? $node->[1]/$node->[0] : 0), # 2=avg
839838 @spare_slots,
840839 @$node; # 10=count, 11=dur, 12=first_dur, 13=min, 14=max, 15=first_called, 16=last_called
841 }
840 }
842841 return @text if wantarray;
843842 return join "", @text;
844 }
843 }
845844
846845
847846 sub format {
848847 my $self = shift;
849848 my $class = ref($self) || $self;
850
849
851850 my $prologue = "$class: ";
852851 my $detail = $self->format_profile_thingy(
853852 $self->{Data}, 0, " ",
3535 $prof->match(key1 => qr/^SELECT/i);
3636
3737 # produce a formatted report with the given number of items
38 $report = $prof->report(number => 10);
38 $report = $prof->report(number => 10);
3939
4040 # clone the profile data set
4141 $clone = $prof->clone();
5555 =head1 DESCRIPTION
5656
5757 This module offers the ability to read, manipulate and format
58 DBI::ProfileDumper profile data.
58 DBI::ProfileDumper profile data.
5959
6060 Conceptually, a profile consists of a series of records, or nodes,
6161 each of each has a set of statistics and set of keys. Each record
6868
6969 =cut
7070
71
72 our $VERSION = sprintf("2.%06d", q$Revision: 10007 $ =~ /(\d+)/o);
71 our $VERSION = "2.010008";
7372
7473 use Carp qw(croak);
7574 use Symbol;
9998
10099 =head2 $prof = DBI::ProfileData->new(Files => [ "dbi.prof.1", "dbi.prof.2" ])
101100
102 Creates a a new DBI::ProfileData object. Takes either a single file
101 Creates a new DBI::ProfileData object. Takes either a single file
103102 through the File option or a list of Files in an array ref. If
104103 multiple files are specified then the header data from the first file
105104 is used.
162161
163162 sub new {
164163 my $pkg = shift;
165 my $self = {
164 my $self = {
166165 Files => [ "dbi.prof" ],
167166 Filter => undef,
168167 DeleteFiles => 0,
174173 @_
175174 };
176175 bless $self, $pkg;
177
176
178177 # File (singular) overrides Files (plural)
179178 $self->{Files} = [ $self->{File} ] if exists $self->{File};
180179
188187 my $files = $self->{Files};
189188 my $read_header = 0;
190189 my @files_to_delete;
191
190
192191 my $fh = gensym;
193192 foreach (@$files) {
194193 my $filename = $_;
211210 or croak("Unable to read profile file '$filename': $!");
212211
213212 # lock the file in case it's still being written to
214 # (we'll be foced to wait till the write is complete)
213 # (we'll be forced to wait till the write is complete)
215214 flock($fh, LOCK_SH) if $self->{LockFile};
216215
217216 if (-s $fh) { # not empty
220219 $self->_read_body($fh, $filename);
221220 }
222221 close($fh); # and release lock
223
222
224223 push @files_to_delete, $filename
225224 if $self->{DeleteFiles};
226225 }
231230 warn "Can't delete '$_': $!";
232231 }
233232 }
234
233
235234 # discard node_lookup now that all files are read
236235 delete $self->{_node_lookup};
237236 }
254253 /^(\S+)\s*=\s*(.*)/
255254 or croak("Syntax error in header in $filename line $.: $_");
256255 # XXX should compare new with existing (from previous file)
257 # and warn if they differ (diferent program or path)
256 # and warn if they differ (different program or path)
258257 $self->{_header}{$1} = unescape_key($2) if $keep;
259258 }
260259 }
449448 my $self = shift;
450449 my $nodes = $self->{_nodes};
451450 my %opt = @_;
452
451
453452 croak("Missing required field option.") unless $opt{field};
454453
455454 my $index = $FIELDS{$opt{field}};
456
455
457456 croak("Unrecognized sort field '$opt{field}'.")
458457 unless defined $index;
459458
460459 # sort over index
461460 if ($opt{reverse}) {
462 @$nodes = sort {
463 $a->[$index] <=> $b->[$index]
461 @$nodes = sort {
462 $a->[$index] <=> $b->[$index]
464463 } @$nodes;
465464 } else {
466 @$nodes = sort {
467 $b->[$index] <=> $a->[$index]
465 @$nodes = sort {
466 $b->[$index] <=> $a->[$index]
468467 } @$nodes;
469468 }
470469
508507 if (UNIVERSAL::isa($val,"Regexp")) {
509508 # regex match
510509 @$nodes = grep {
511 $#$_ < $index or $_->[$index] !~ /$val/
510 $#$_ < $index or $_->[$index] !~ /$val/
512511 } @$nodes;
513512 } else {
514513 if ($opt{case_sensitive}) {
515 @$nodes = grep {
514 @$nodes = grep {
516515 $#$_ < $index or $_->[$index] ne $val;
517516 } @$nodes;
518517 } else {
519518 $val = lc $val;
520 @$nodes = grep {
519 @$nodes = grep {
521520 $#$_ < $index or lc($_->[$index]) ne $val;
522521 } @$nodes;
523522 }
559558 if (UNIVERSAL::isa($val,"Regexp")) {
560559 # regex match
561560 @$nodes = grep {
562 $#$_ >= $index and $_->[$index] =~ /$val/
561 $#$_ >= $index and $_->[$index] =~ /$val/
563562 } @$nodes;
564563 } else {
565564 if ($opt{case_sensitive}) {
566 @$nodes = grep {
565 @$nodes = grep {
567566 $#$_ >= $index and $_->[$index] eq $val;
568567 } @$nodes;
569568 } else {
570569 $val = lc $val;
571 @$nodes = grep {
570 @$nodes = grep {
572571 $#$_ >= $index and lc($_->[$index]) eq $val;
573572 } @$nodes;
574573 }
615614 sub format {
616615 my ($self, $node) = @_;
617616 my $format;
618
617
619618 # setup keys
620619 my $keys = "";
621620 for (my $i = PATH; $i <= $#$node; $i++) {
622621 my $key = $node->[$i];
623
622
624623 # remove leading and trailing space
625624 $key =~ s/^\s+//;
626625 $key =~ s/\s+$//;
643642 Shortest Time : %3.6f seconds
644643 Average Time : %3.6f seconds
645644 END
646 return sprintf($format, @{$node}[COUNT,TOTAL,LONGEST,SHORTEST],
645 return sprintf($format, @{$node}[COUNT,TOTAL,LONGEST,SHORTEST],
647646 $node->[TOTAL] / $node->[COUNT]) . $keys;
648647 } else {
649648 $format = <<END;
674673
675674 my $report = $self->_report_header($opt{number});
676675 for (0 .. $opt{number} - 1) {
677 $report .= sprintf("#" x 5 . "[ %d ]". "#" x 59 . "\n",
676 $report .= sprintf("#" x 5 . "[ %d ]". "#" x 59 . "\n",
678677 $_ + 1);
679678 $report .= $self->format($nodes->[$_]);
680679 $report .= "\n";
710709 $header .= sprintf(<<END, $node_count, $number, $self->{_sort}, $count, $time);
711710 Total Records : %d (showing %d, sorted by %s)
712711 Total Count : %d
713 Total Runtime : %3.6f seconds
712 Total Runtime : %3.6f seconds
714713
715714 END
716715
158158
159159 =cut
160160
161 our $VERSION = sprintf("2.%06d", q$Revision: 14120 $ =~ /(\d+)/o);
161 our $VERSION = "2.014121";
162162
163163 our @ISA = qw(DBI::ProfileDumper);
164164
9191 $profile->flush_to_disk()
9292
9393 Flushes all collected profile data to disk and empties the Data hash. Returns
94 the filename writen to. If no profile data has been collected then the file is
94 the filename written to. If no profile data has been collected then the file is
9595 not written and flush_to_disk() returns undef.
9696
9797 The file is locked while it's being written. A process 'consuming' the files
176176
177177 our @ISA = ("DBI::Profile");
178178
179 our $VERSION = sprintf("2.%06d", q$Revision: 15324 $ =~ /(\d+)/o);
179 our $VERSION = "2.015325";
180180
181181 use Carp qw(croak);
182182 use Fcntl qw(:flock);
235235 if (($self->{_wrote_header}||'') eq $filename) {
236236 # append more data to the file
237237 # XXX assumes that Path hasn't changed
238 open($fh, ">>", $filename)
238 open($fh, ">>", $filename)
239239 or croak("Unable to open '$filename' for $class output: $!");
240240 } else {
241241 # create new file (or overwrite existing)
245245 rename($filename, $bak)
246246 or warn "Error renaming $filename to $bak: $!\n";
247247 }
248 open($fh, ">", $filename)
248 open($fh, ">", $filename)
249249 or croak("Unable to open '$filename' for $class output: $!");
250250 }
251251 # lock the file (before checking size and writing the header)
309309 # XXX it's valid for $data to be an ARRAY ref, i.e., Path is empty.
310310 # produce an empty profile for invalid $data
311311 return 0 unless $data and UNIVERSAL::isa($data,'HASH');
312
312
313313 # isolate us against globals which affect print
314314 local ($\, $,);
315315
00 package DBI::ProfileSubs;
11
2 our $VERSION = sprintf("0.%06d", q$Revision: 9395 $ =~ /(\d+)/o);
2 our $VERSION = "0.009396";
33
44 =head1 NAME
55
2525 # way to compose them in various combinations into multiple subs.
2626 # Perhaps via AUTOLOAD where \&auto_X_Y_Z creates a sub that does X, Y, and Z.
2727 # The final subs always need to be very fast.
28 #
28 #
2929
3030 sub norm_std_n3 {
3131 # my ($h, $method_name) = @_;
623623 # hint to organize:
624624 # the most specialized rules for single machines/users are 1st
625625 # then the denying rules
626 # the the rules about whole networks
626 # then the rules about whole networks
627627
628628 # rule: internal_webserver
629629 # desc: to get statistical information
650650 },
651651
652652 # rule: employee_workplace
653 # desc: get detailled information
653 # desc: get detailed information
654654 {
655655 # any IP-address is meant here
656656 mask => '^10\.95\.81\.(\d+)$',
808808
809809 =item * "mask" is a perl regular expression against the plain ip-address of the machine which wishes to connect _or_ the reverse-lookup from a nameserver.
810810
811 =item * "accept" tells the dbiproxy-server wether ip-adresse like in "mask" are allowed to connect or not (0/1)
811 =item * "accept" tells the dbiproxy-server whether ip-adresse like in "mask" are allowed to connect or not (0/1)
812812
813813 =item * "users" is a reference to a list of usernames which must be matched, this is NOT a regular expression.
814814
816816
817817 Controlling which SQL-statements are allowed
818818
819 You can put every SQL-statement you like in simply ommiting "sql => ...", but the more important thing is to restrict the connection so that only allowed queries are possible.
819 You can put every SQL-statement you like in simply omitting "sql => ...", but the more important thing is to restrict the connection so that only allowed queries are possible.
820820
821821 If you include an sql-section in your config-file like this:
822822
2727 } unless defined &utf8::is_utf8;
2828
2929 $DBI::PurePerl = $ENV{DBI_PUREPERL} || 1;
30 $DBI::PurePerl::VERSION = sprintf("2.%06d", q$Revision: 14285 $ =~ /(\d+)/o);
30 $DBI::PurePerl::VERSION = "2.014286";
3131
3232 $DBI::neat_maxlen ||= 400;
3333
119119 use constant IMA_NO_TAINT_OUT => 0x0020; #/* don't taint results */
120120 use constant IMA_COPY_UP_STMT => 0x0040; #/* copy sth Statement to dbh */
121121 use constant IMA_END_WORK => 0x0080; #/* set on commit & rollback */
122 use constant IMA_STUB => 0x0100; #/* donothing eg $dbh->connected */
122 use constant IMA_STUB => 0x0100; #/* do nothing eg $dbh->connected */
123123 use constant IMA_CLEAR_STMT => 0x0200; #/* clear Statement before call */
124124 use constant IMA_UNRELATED_TO_STMT=> 0x0400; #/* profile as empty Statement */
125125 use constant IMA_NOT_FOUND_OKAY => 0x0800; #/* not error if not found */
756756 for keys %$hash_ref;
757757 $num_sort = $sort_guess;
758758 }
759
759
760760 my @keys = keys %$hash_ref;
761761 no warnings 'numeric';
762762 my @sorted = ($num_sort)
950950 my $dbh = shift;
951951 # A reasonable default implementation based on the one in DBI.xs.
952952 # Typically a pure-perl driver would have their own take_imp_data method
953 # that would delete all but the essential items in the hash before einding with:
953 # that would delete all but the essential items in the hash before ending with:
954954 # return $dbh->SUPER::take_imp_data();
955955 # Of course it's useless if the driver doesn't also implement support for
956956 # the dbi_imp_data attribute to the connect() method.
11311131
11321132 DBI_PUREPERL == 2 Always use PurePerl
11331133
1134 You may set the enviornment variable in your shell (e.g. with
1134 You may set the environment variable in your shell (e.g. with
11351135 set or setenv or export, etc) or else set it in your script like
11361136 this:
11371137
2727
2828 BEGIN
2929 {
30 $VERSION = sprintf( "1.%06d", q$Revision: 15543 $ =~ /(\d+)/o );
30 $VERSION = "1.015544";
3131
3232 $versions->{nano_version} = $VERSION;
3333 if ( $ENV{DBI_SQL_NANO} || !eval { require SQL::Statement; $SQL::Statement::VERSION ge '1.400' } )
8282 {
8383 $self->{command} = 'CREATE';
8484 $self->{table_name} = $1;
85 $self->{column_names} = parse_coldef_list($2) if $2;
85 defined $2 and $2 ne "" and
86 $self->{column_names} = parse_coldef_list($2);
8687 $self->{column_names} or croak "Can't find columns";
8788 };
8889 /^\s*DROP\s+TABLE\s+(IF\s+EXISTS\s+)?(.*?)\s*$/is
9091 {
9192 $self->{command} = 'DROP';
9293 $self->{table_name} = $2;
93 $self->{ignore_missing_table} = 1 if $1;
94 defined $1 and $1 ne "" and
95 $self->{ignore_missing_table} = 1;
9496 };
9597 /^\s*SELECT\s+(.*?)\s+FROM\s+(\S+)((.*))?/is
9698 && do
9799 {
98100 $self->{command} = 'SELECT';
99 $self->{column_names} = parse_comma_list($1) if $1;
101 defined $1 and $1 ne "" and
102 $self->{column_names} = parse_comma_list($1);
100103 $self->{column_names} or croak "Can't find columns";
101104 $self->{table_name} = $2;
102105 if ( my $clauses = $4 )
114117 {
115118 $self->{command} = 'INSERT';
116119 $self->{table_name} = $1;
117 $self->{column_names} = parse_comma_list($2) if $2;
118 $self->{values} = $self->parse_values_list($4) if $4;
120 defined $2 and $2 ne "" and
121 $self->{column_names} = parse_comma_list($2);
122 defined $4 and $4 ne "" and
123 $self->{values} = $self->parse_values_list($4);
119124 $self->{values} or croak "Can't parse values";
120125 };
121126 /^\s*DELETE\s+FROM\s+(\S+)((.*))?/is
123128 {
124129 $self->{command} = 'DELETE';
125130 $self->{table_name} = $1;
126 $self->{where_clause} = $self->parse_where_clause($3) if $3;
131 defined $3 and $3 ne "" and
132 $self->{where_clause} = $self->parse_where_clause($3);
127133 };
128134 /^\s*UPDATE\s+(\S+)\s+SET\s+(.+)(\s+WHERE\s+.+)/is
129135 && do
130136 {
131137 $self->{command} = 'UPDATE';
132138 $self->{table_name} = $1;
133 $self->parse_set_clause($2) if $2;
134 $self->{where_clause} = $self->parse_where_clause($3) if $3;
139 defined $2 and $2 ne "" and
140 $self->parse_set_clause($2);
141 defined $3 and $3 ne "" and
142 $self->{where_clause} = $self->parse_where_clause($3);
135143 };
136144 }
137145 croak "Couldn't parse" unless ( $self->{command} and $self->{table_name} );
328336 my ( $self, $data, $params ) = @_;
329337 my $table = $self->open_tables( $data, 0, 1 );
330338 $self->verify_columns($table);
339 my $all_columns = $table->{col_names};
331340 $table->seek( $data, 0, 2 ) unless ( $table->can('insert_one_row') );
332341 my ($array) = [];
333342 my ( $val, $col, $i );
335344 my $cNum = scalar( @{ $self->{column_names} } ) if ( $self->{column_names} );
336345 my $param_num = 0;
337346
338 if ($cNum)
339 {
340 for ( $i = 0; $i < $cNum; $i++ )
341 {
342 $col = $self->{column_names}->[$i];
343 $array->[ $self->column_nums( $table, $col ) ] = $self->row_values($i);
344 }
345 }
346 else
347 {
347 $cNum or
348348 croak "Bad col names in INSERT";
349 }
349
350 my $maxCol = $#$all_columns;
351
352 for ( $i = 0; $i < $cNum; $i++ )
353 {
354 $col = $self->{column_names}->[$i];
355 $array->[ $self->column_nums( $table, $col ) ] = $self->row_values($i);
356 }
357
358 # Extend row to put values in ALL fields
359 $#$array < $maxCol and $array->[$maxCol] = undef;
350360
351361 $table->can('insert_new_row') ? $table->insert_new_row( $data, $array ) : $table->push_row( $data, $array );
352362
5959
6060 =cut
6161
62 our $VERSION = sprintf("0.%06d", q$Revision: 10314 $ =~ /(\d+)/o);
62 our $VERSION = "0.010315";
6363
6464 my %cache;
6565
00 package DBI::Util::_accessor;
11 use strict;
22 use Carp;
3 our $VERSION = sprintf("0.%06d", q$Revision: 9478 $ =~ /(\d+)/);
3 our $VERSION = "0.009479";
44
55 # inspired by Class::Accessor::Fast
66
8686 my($h, $statement, $attribs, @params) = @_;
8787 Carp::carp "\$h->do() attribs unused" if $attribs;
8888 my $new_h = $h->prepare($statement) or return undef; ##
89 pop @{ $h->{'___sths'} }; ## certian death assured
89 pop @{ $h->{'___sths'} }; ## certain death assured
9090 $new_h->execute(@params) or return undef; ##
9191 my $rows = $new_h->rows; ##
9292 $new_h->finish; ## bang bang
9595 $self->{'DBI_NAME'} = $sth->{NAME};
9696 }
9797
98 # [R] provide compatibility with Win32::ODBC's way of identifying erraneous SQL statements
98 # [R] provide compatibility with Win32::ODBC's way of identifying erroneous SQL statements
9999 return ($self->{'DBI_ERR'})?1:undef;
100100 # -[R]-
101101 }
115115 if (scalar(@row)>0)
116116 {
117117 #-- the row of result is not nul
118 #-- return somthing nothing will be return else
118 #-- return something nothing will be return else
119119 return 1;
120120 }
121121 }
140140
141141 ## testing neat_list
142142
143 is(neat_list([ 1 + 1, "2", undef, "foobarbaz"], 8, "|"), "2|'2'|undef|'foo...'", '... test array argument w/seperator and maxlen');
144 is(neat_list([ 1 + 1, "2", undef, "foobarbaz"]), "2, '2', undef, 'foobarbaz'", '... test array argument w/out seperator or maxlen');
143 is(neat_list([ 1 + 1, "2", undef, "foobarbaz"], 8, "|"), "2|'2'|undef|'foo...'", '... test array argument w/separator and maxlen');
144 is(neat_list([ 1 + 1, "2", undef, "foobarbaz"]), "2, '2', undef, 'foobarbaz'", '... test array argument w/out separator or maxlen');
145145
146146
147147 ## ----------------------------------------------------------------------------
7272 [ values %{$ck} ],
7373 [ $sth1 ]
7474 ),
75 '... our statment handle should be in the CachedKids');
76
77 ok($sth1->{Active}, '... our first statment is Active');
75 '... our statement handle should be in the CachedKids');
76
77 ok($sth1->{Active}, '... our first statement is Active');
7878
7979 {
8080 my $warn = 0; # use this to check that we are warned
8686 is($sth1, $sth2, '... prepare_cached returned the same statement handle');
8787 cmp_ok($warn,'==', 1, '... we got warned about our first statement handle being still active');
8888
89 ok(!$sth1->{Active}, '... our first statment is no longer Active since we re-prepared it');
89 ok(!$sth1->{Active}, '... our first statement is no longer Active since we re-prepared it');
9090
9191 my $sth3 = $dbh->prepare_cached($sql, { foo => 1 });
9292 isa_ok($sth3, 'DBI::st');
9797 [ values %{$ck} ],
9898 [ $sth1, $sth3 ]
9999 ),
100 '... both statment handles should be in the CachedKids');
100 '... both statement handles should be in the CachedKids');
101101
102102 ok($sth1->execute("."), '... executing first statement handle again');
103103 ok($sth1->{Active}, '... first statement handle is now active again');
113113 [ values %{$ck} ],
114114 [ $sth2, $sth4 ]
115115 ),
116 '... second and fourth statment handles should be in the CachedKids');
116 '... second and fourth statement handles should be in the CachedKids');
117117
118118 $sth1->finish;
119119 ok(!$sth1->{Active}, '... first statement handle is no longer active');
135135 [ values %{$ck} ],
136136 [ $sth2, $sth5 ]
137137 ),
138 '... second and fourth/fifth statment handles should be in the CachedKids');
138 '... second and fourth/fifth statement handles should be in the CachedKids');
139139 }
140140
141141 SKIP: {
218218 # this test checks for reference leaks by testing the Kids attribute
219219 # which is not supported by DBI::PurePerl, so we just do not run this
220220 # for DBI::PurePerl all together. Even though some of the tests would
221 # pass, it does not make sense becuase in the end, what is actually
221 # pass, it does not make sense because in the end, what is actually
222222 # being tested for will give a false positive
223223
224224 sub work {
3737 ok( $dbh->{Active}, '... checking Active attribute for dbh');
3838 ok( $dbh->{AutoCommit}, '... checking AutoCommit attribute for dbh');
3939 ok(!$dbh->{CompatMode}, '... checking CompatMode attribute for dbh');
40 ok(!$dbh->{InactiveDestroy}, '... checking InactiveDestory attribute for dbh');
41 ok(!$dbh->{AutoInactiveDestroy}, '... checking AutoInactiveDestory attribute for dbh');
40 ok(!$dbh->{InactiveDestroy}, '... checking InactiveDestroy attribute for dbh');
41 ok(!$dbh->{AutoInactiveDestroy}, '... checking AutoInactiveDestroy attribute for dbh');
4242 ok(!$dbh->{PrintError}, '... checking PrintError attribute for dbh');
4343 ok( $dbh->{PrintWarn}, '... checking PrintWarn attribute for dbh'); # true because of perl -w above
4444 ok( $dbh->{RaiseError}, '... checking RaiseError attribute for dbh');
110110 ok( $drh->{Active}, '... checking Active attribute for drh');
111111 ok( $drh->{AutoCommit}, '... checking AutoCommit attribute for drh');
112112 ok(!$drh->{CompatMode}, '... checking CompatMode attribute for drh');
113 ok(!$drh->{InactiveDestroy}, '... checking InactiveDestory attribute for drh');
114 ok(!$drh->{AutoInactiveDestroy}, '... checking AutoInactiveDestory attribute for drh');
113 ok(!$drh->{InactiveDestroy}, '... checking InactiveDestroy attribute for drh');
114 ok(!$drh->{AutoInactiveDestroy}, '... checking AutoInactiveDestroy attribute for drh');
115115 ok(!$drh->{PrintError}, '... checking PrintError attribute for drh');
116116 ok( $drh->{PrintWarn}, '... checking PrintWarn attribute for drh'); # true because of perl -w above
117117 ok(!$drh->{RaiseError}, '... checking RaiseError attribute for drh');
7777 sub DESTROY {
7878 if ($expect_active < 0) { # inside child
7979 my $self = shift;
80 exit $self->FETCH('Active') || 0 unless $^O eq 'MSWin32';
80 exit ($self->FETCH('Active') || 0) unless $^O eq 'MSWin32';
8181
8282 # On Win32, the forked child is actually a thread. So don't exit,
8383 # and report failure directly.
5555 if $row->[0] < 0;
5656 # ... and providing alternate results
5757 # (although typically would trap and hide and error from SUPER::fetch)
58 return $sth->set_err(2,"Don't exagerate",undef, undef, [ 42,"zz",0 ])
58 return $sth->set_err(2,"Don't exaggerate",undef, undef, [ 42,"zz",0 ])
5959 if $row->[0] > 42;
6060 }
6161 return $row;
129129 isa_ok($row, 'ARRAY');
130130 is($row->[0], 42);
131131 is($DBI::err, 2);
132 like($DBI::errstr, qr/Don't exagerate/);
132 like($DBI::errstr, qr/Don't exaggerate/);
133133 is($@ =~ /Don't be so negative/, $@);
134134
135135
118118 }
119119 );
120120
121 my @tbl;
122 @tbl = $dbh->tables (undef, undef, undef, undef);
123 is( scalar @tbl, 1, "Found 1 tables");
124
121125 $r = $dbh->selectall_arrayref(q/select * from Fred/);
122126 ok( @$r == 2, 'rows found after reconnect using "dbm_tables"' );
123127
124 ok( $dbh->do(q/drop table if exists FRED/), 'drop table' );
128 my $deep_dir = File::Spec->catdir( $dir, 'deep' );
129 mkpath $deep_dir;
130
131 $dbh = DBI->connect( 'dbi:DBM:', undef, undef, {
132 f_dir => $deep_dir,
133 sql_identifier_case => 2, # SQL_IC_LOWER
134 }
135 );
136 ok( $dbh->do( q{create table wilma (a integer, b char (10))} ), "Create wilma" );
137 ok( $dbh->do( q{insert into wilma values (1, 'Barney')} ), "insert Barney" );
138 ok( $dbh->disconnect(), "disconnect" );
139
140 $dbh = DBI->connect( 'dbi:DBM:', undef, undef, {
141 f_dir => $dir,
142 sql_identifier_case => 2, # SQL_IC_LOWER
143 }
144 );
145
146 # Make sure wilma is not found without f_dir_search
147 @tbl = $dbh->tables (undef, undef, undef, undef);
148 is( scalar @tbl, 1, "Found 1 table");
149 ok( $dbh->disconnect(), "disconnect" );
150
151 $dbh = DBI->connect( 'dbi:DBM:', undef, undef, {
152 f_dir => $dir,
153 f_dir_search => [ $deep_dir ],
154 sql_identifier_case => 2, # SQL_IC_LOWER
155 }
156 );
157
158 @tbl = $dbh->tables (undef, undef, undef, undef);
159 is( scalar @tbl, 2, "Found 2 tables");
160 # f_dir should always appear before f_dir_search
161 like( $tbl[0], qr{(?:^|\.)fred$}i, "Fred first" );
162 like( $tbl[1], qr{(?:^|\.)wilma$}i, "Fred second" );
163
164 my( $n, $sth );
165 ok( $sth = $dbh->prepare( 'select * from fred' ), "select from fred" );
166 ok( $sth->execute, "execute fred" );
167 $n = 0;
168 $n++ while $sth->fetch;
169 is( $n, 2, "2 entry in fred" );
170 ok( $sth = $dbh->prepare( 'select * from wilma' ), "select from wilma" );
171 ok( $sth->execute, "execute wilma" );
172 $n = 0;
173 $n++ while $sth->fetch;
174 is( $n, 1, "1 entry in wilma" );
175
176 ok( $dbh->do(q/drop table if exists FRED/), 'drop table fred' );
125177 ok( !-f File::Spec->catfile( $dir, "fred$dirfext" ), "fred$dirfext removed" );
126178 ok( !-f File::Spec->catfile( $dir, "fred$tblfext" ), "fred$tblfext removed" );
179
180 ok( $dbh->do(q/drop table if exists wilma/), 'drop table wilma' );
181 ok( !-f File::Spec->catfile( $deep_dir, "wilma$dirfext" ), "wilma$dirfext removed" );
182 ok( !-f File::Spec->catfile( $deep_dir, "wilma$tblfext" ), "wilma$tblfext removed" );
127183 }
128184
129185 done_testing();
8585 #http => { url => "http://localhost:8001/gofer" },
8686 );
8787
88 # too dependant on local config to make a standard test
88 # too dependent on local config to make a standard test
8989 delete $trials{http} unless $username eq 'timbo' && -d '.svn';
9090
9191 my @transports = ($opt_transport) ? ($opt_transport) : (sort keys %trials);
00 #!/usr/bin/perl
11
22 # lib.pl is the file where database specific things should live,
3 # whereever possible. For example, you define certain constants
3 # wherever possible. For example, you define certain constants
44 # here and the like.
55
66 use strict;