blib/lib/JDBIx.pm

filter: Statementstmt 7.1% 58 / 814 Branchbran 2.9% 15 / 516 Conditioncond 3.0% 5 / 165 MC/DCmcdc 0.0% 0 / 104 Subroutinesub 17.6% 6 / 34 Podpod 100% 20 / 20 totaltotal 6.2% 104 / 1653 CC 321 SCAR 64.5
CC
321
Cov
5%
do
1482.0
new
1383.9
do1
870.0
CRAP 633.1
↑ Summary
1 =head1 NAME
2  
3 JDBIx - Object-oriented higher-level DBI interface for select into arrays, placeholders, sequences, etc.
4  
5 =head1 AUTHOR
6  
7 This module is Copyright (C) 2000-2016 by
8  
9 Jim Turner
10
11 Email: turnerjw784@yahoo.com
12  
13 All rights reserved.
14  
15 You may distribute this module under the terms of either the GNU General
16 Public License or the Artistic License, as specified in the Perl README
17 file.
18  
19 =head1 SYNOPSIS
20  
21 #!/usr/bin/perl
22  
23 use strict;
24 use JDBIx;
25  
26 &jdbix_setlog('/tmp/dbixlogt.txt'); #OPTIONALLY, SET UP A LOG FILE.
27  
28 #CONNECT TO A DATABASE:
29  
30 my $dbh = new JDBIx('dbtype:dbname,dbuser,dbpswd',{})
31 or die ("-no login: err=" . &jdbix_err() . ':' . &jdbix_errstr . "=\n");
32  
33 $dbh->package(__PACKAGE__); #UNLESS PACKAGE IS "main::".
34  
35 #DO A SIMPLE SELECT, STORING THE RESULTS INTO @f1 AND @f2.
36  
37 our (@f1, @f2); #MUST BE PACKAGE, NOT "MY" VARIABLES:
38 my $res = $dbh->select('select field1, field2 into :f1, :f2 from test')
39 or warn ('Could not do select (' . $dbh->err() . '.' . $dbh->errstr() . ')!');
40  
41 for (my $i=0;$i<=$res;$i++) {
42 print "-For record# $i: field1=$f1[$i], field2=$f2[$i]\n";
43 }
44  
45 #ANOTHER SIMPLE SELECT, RETURNING THE RESULTS INTO @res:
46  
47 my @res = $dbh->select('select field1, field2 from test');
48 for (my $i=0;$i<=$#res;$i++) {
49 print "\n-For record# $i: ";
50 for (my $j=0;$j<=$#{$res[$i]};$j++) {
51 print "value =$res[$i]->[$j],\t";
52 }
53 }
54  
55 #DO A VECTORIZED SELECT, SELECTING A RECORD FOR EACH KEY VALUE IN @f1:
56  
57 our (@f3, @f4); #MUST BE PACKAGE, NOT "MY" VARIABLES:
58 my $sqlstr = 'select field3, field4 into :f3, :f4 from test2 where field1 = :f1';
59 $res = $dbh->do($sqlstr, 1) or die $dbh->errstr();
60  
61 #INSERT A NEW RECORD:
62  
63 $res = $dbh->do1('insert into test values (?, ?, ?, ?)',
64 'value1', 'value2', 'value3', 'value4')
65 or die ('Could not insert record (' . $dbh->err() . '.' . $dbh->errstr() . ')!');
66  
67 #COMMIT THE TRANSACTION:
68  
69 $dbh->commit();
70  
71 #FETCH THE AUTONUMBER / SEQUENCE KEY VALUE OF THE LAST INSERT:
72  
73 my $newestkey = $dbh->fetchseq('keyfieldname');
74 print "..Just inserted new record with key: $newestkey.\n";
75  
76 #CURSORS:
77  
78 $sqlstr = 'update test set field1 = ? where field2 = ?';
79 my $csr = $dbh->opencsr($sqlstr) or die ("Could not open ($sqlstr) (".$dbh->errstr().")!");
80  
81 #AN OPTIONAL 2ND ARGUMENT TO opencsr CAUSES $dbh->execute() TO BE CALLED
82 #IN ADDITION TO $dbh->prepare(). IF THE RETURN VARIABLE IS A LIST, A
83 #SECOND VALUE IS RETURNED REPRESENTING THE RESULT RETURNED BY $dbh->execute.
84 #ALSO, IF USED FOR A SELECT STATEMENT, VARIABLES CAN BE BOUND JUST AS
85 #FOR select (see ":f1" and ":f2" in prev. examples).
86  
87 for (my $i=0;$i<=$#f1;$i++) {
88 $csr->bind($i, $f1[$i]);
89 }
90 $csr->closecsr();
91  
92 #AN EXAMPLE OF SELECT USING CURSORS:
93  
94 $sqlstr = 'select field3, field4 from test2 where field1 = ?';
95 $csr = $dbh->opencsr($sqlstr) or die "Could not open ($sqlstr) (".$dbh->errstr().")!";
96 for (my $i=0;$i<=$#f1;$i++) {
97 $csr->bind($f1[$i]);
98 while (my ($f3, $f4) = $csr->fetch()) {
99 print "-For record# $i (key $f1[$i]): field3=$f3, field4=$f4\n";
100 }
101 }
102 $csr->closecsr();
103  
104 #ANOTHER EXAMPLE OF VECTOR SELECT USING CURSORS (WITH INTO CLAUSE):
105 #NOTE: $csr->fetch() and $csr->fetchall() WILL NOT RETURN RESULTS HERE BECAUSE
106 #THE DATA HAS ALREADY BEEN FETCHED BY THE $csr->bind() CALL INTO THE VECTORS: @f1 and @f3!
107  
108 $sqlstr = 'select field3, field4 into :f3, :f4 from test2 where field1 = ?';
109 $csr = $dbh->opencsr($sqlstr) or die "Could not open ($sqlstr) (".$dbh->errstr().")!";
110 for (my $i=0;$i<=$#f1;$i++) {
111 $res = $csr->bind($f1[$i]);
112 for (my $j=0;$j<$res;$j++) {
113 print "-For record# $i (key $f1[$i]): field3=$f3[$j], field4=$f4[$j]\n";
114 }
115 }
116 $csr->closecsr();
117  
118 #DISCONNECT FROM THE DATABASE:
119  
120 $dbh->disconnect();
121  
122 exit(0);
123  
124 =head1 DESCRIPTION
125  
126 JDBIx provides a higher-level interface to L<DBI> by combining I<prepare>() and I<execute>()
127 methods, but more than that, it also provides placeholders for databases that do not support
128 them, provides instant loading of I<select>() results into arrays by column via a single command.
129 Another feature is abstraction of sequence / autonumbering fields in a database-independent manner.
130  
131 =head1 METHODS
132  
133 =over 4
134  
135 =item B<Class Methods>
136  
137 =over 4
138  
139 =item $dbh = B<new JDBIx>(I<connect-string>, [ I<attrs> ]);
140  
141 Creates and returns a new database connection object. I<connect-string> normally contains the
142 DBD::I<modulename>, the I<database-name>, the I<user-name>, and the I<password> in the format:
143 'I<modulename>:I<database-name>,I<user-name>,I<password>'. The I<user-name>, and I<password>
144 are sometimes optional depending on the database and connection requirements. I<attrs> is
145 an optional hash-reference and DBD::I<modulename> -dependent. Returns I<undef> on failure.
146  
147 I<connect-string>: Examples:
148  
149 1) Simple 1: 'mysql:mydatabase,userid,password'
150  
151 2) Simple 2: 'SQLite:mydatabase'
152  
153 3) Proxy 1: 'dbi:host:port:mysql:mydatabase,userid,password'
154  
155 3) Proxy 2: 'mysql:mydatabase,userid,password', { -proxy => 'host:port' }
156  
157 4) Literal1: '=dbi:Proxy:hostname=host;port=9090;dsn=DBI:dbi:host:port:mysql:userid,password'
158  
159 5) Literal2: 'connect=dbi:Proxy:hostname=host;port=9090;dsn=DBI:dbi:host:port:mysql:userid,password'
160  
161 6) Hash1: (-type => 'mysql', -name = >'mydatabase', -user=> 'userid' -pswd => 'password', -proxy => 'host:port')
162  
163 7) Hash2: (-connect => 'mysql:mydatabase,userid,password', -proxy => 'host:port')
164  
165 8) Hash3: (-connect => '=dbi:Proxy:hostname=host;port=9090;dsn=DBI:dbi:host:port:mysql:userid,password', -proxy => 'IGNORESME!:port')
166  
167 NOTE: If using the Hash format, any additional arguments ("I<attrs>") should be included in the hash,
168 rather than as a separate hash-reference.
169  
170 NOTE2: If a literal DBI connect string ("=dbi...") is used, any conflicting attributes, namely "-name",
171 "-user", "-pswd", and "-proxy" are IGNORED and the literal string is passed directly to DBI->connect()!
172  
173 =item I<$scalar> = B<&jdbix_autocommit>([ I<1 | 0> ]);
174  
175 I<attrs> - include any additional attributes in hash-reference format. This includes any parameters to
176 be passed to DBI, any database-specific parameters, any jdbix parameters (prefix with "-jdbix_I<parameter>"),
177 and any environment variables that need to be set (prefix with "-jdbix_env_I<variable-name>").
178  
179 If an argument is passed, then sets the default I<autocommit> status for any future database objects
180 created within the program to on or off based on that argument, if no argument is passed, it returns
181 the current default I<autocommit> status, which is zero (0) if this function has not been previously
182 called with an argument. NOTE: It does not alter the I<autocommit> flag for any currently opened
183 database objects, see $dbh->B<autocommit>() for changing the I<autocommit> flag for a currently opened
184 database.
185  
186 =item I<$scalar> = B<&jdbix_err>([ I<$database_object> ]);
187  
188 Returns the last error code number encountered. If I<$database_object> is specified, then it returns
189 the last error code recorded for that database object, otherwise $DBI::err is returned. NOTE: this
190 method can be used after an I<attempted> creation of a new database object to get the error code
191 when the object fails to be created (and there's thus no database object). After a database object
192 is successfully created, it's preferred to use $dbh->B<err>().
193  
194 =item I<$scalar> = B<&jdbix_errstr>([ I<$database_object> ]);
195  
196 Returns the last error message text for the last error encountered. If I<$database_object> is
197 specified, then it returns the last error message recorded for that database object, otherwise
198 $DBI::errstr is returned. NOTE: this method can be used after an I<attempted> creation of a new
199 database object to get the error code when the object fails to be created (and there's thus no
200 database object). After a database object is successfully created, it's preferred to use
201 $dbh->B<errstr>().
202  
203 =item $dbh->B<setlog>(I<log-file>); -or- B<jdbix_setlog>(I<log-file>);
204  
205 Sets up a log file to log queries to. The first sets up a log file for a specific connection,
206 the latter, a general log file for all connections. The I<log-file> should be a string
207 containing the full path of the log file. Both functions may be called and set up two
208 separate log files. Return 1 if successfully opened the log file for writing, 0 if not.
209  
210 =item I<$scalar> = B<&jdbix_package>([ I<package_name> ]);
211  
212 Set or retrieve the current DEFAULT package name used for placeholder variables in "INTO" clauses in
213 queries. NOTE: This function does NOT change the current package name used by currently opened
214 database objects, but only the default package name used when subsequent database objects are created!
215 See $dbh->B<package>() for changing the current package name used by an open database object.
216 IF I<package_name> is specified, the default package name is set in the program in subsequently opened
217 database objects (until B<&jdbix_package>() is called with a different package name).
218 If not specified, it returns the current package name. The default package name is "main".
219 NOTE: The current I<package_name> can also be set for a database when opened by
220 passing the 'I<jdbix_package>' => 'I<package_name>' attribute when creating the database object.
221  
222 =back
223  
224 =item B<Object Methods>
225  
226 =over 4
227  
228 =item I<$scalar> = $dbh->B<autocommit>([ I<1 | 0> ]);
229  
230 If an argument is passed, then sets the database's I<autocommit> status to on or off based on that
231 argument, if no argument is passed, it returns the current state of the database's I<autocommit> status.
232  
233 =item I<$scalar> = $dbh->B<commit>();
234  
235 Causes any pending queries that changed the database to be committed (unless I<autocommit> is on for
236 the database connection). If I<autocommit> is on, it returns 1 (true). Otherwise, it returns the
237 result of the DBI->I<commit>() call.
238  
239 =item $dbh->B<disconnect>();
240  
241 Disconnect from the database;
242  
243 =item I<$scalar> = $dbh->B<do>('I<query-string>' [, I<attrs> ]);
244  
245 Provides vectorized selects and inserts, updates, etc. I<query-string> can be any valid SQL
246 query string. Returns the number of records affected / selected. I<attrs> is an optional
247 hash-reference that can contain one or more of the following options:
248  
249 =over 4
250  
251 =item B<-interpolate> => 0..3 (default 0) - special attribute for handling the relationship between the
252 key vector(s) and the vector array(s) containing the returned results.
253  
254 If B<0>, then the query is just executed as-is and the
255 number of rows affected / selected is returned. For selects based on key vectors (arrays), the
256 results are like as if 2 was specified.
257  
258 If B<1>, and the query is a select, then it is
259 assumed that a 1:1 relationship exists between the vector array-references given in the WHERE clause
260 and the results returned - the query is done once in a loop for each element in the set of "keys"
261 specified by these array-references and only the first matching record for each keyset will be
262 returned. All the arrays given by the array-references in both the WHERE clause AND the INTO
263 clause will be sorted WITHIN the sort order of the elements in the keys arrays.
264  
265 If B<2> or B<3>, a 1:MANY relationship is assumed between the key arrays and the results returned in the
266 INTO arrays, and all records that match the combination of the queries performed on each element
267 in the set of "keys" specified by the array-references in the WHERE clause will be returned sorted,
268 but the "key" arrays referenced will not be sorted, but remain in the order given. The difference
269 between 2 and 3 is that with 2, at least one record (with empty fields, if none match) is
270 guarenteed to be returned for EACH element in the longest key array (all key arrays should be the
271 same length). With 3, if no records match a given element in the key arrays, then no records will
272 be returned for that set of keys.
273  
274 =item B<-commit> => true | false (default false) - If I<autocommit> is off for the database connection,
275 a I<commit> will be done automatically after the query completes (if any records affected) (if TRUE),
276 no commit is done if FALSE.
277  
278 =back
279  
280 =item [ I<$scalar> | I<@array> = ] $dbh->B<do1>('I<query-string>' [, I<bind-parameter-list> ]);
281  
282 Performs a single query as-is.
283  
284 Similar to $dbh->B<do1>(), but simpler and a I<bind-parameter-list> is allowed. This method is the
285 preferred method of doing non-select queries, but can handle selects too. The optional returned
286 results are the same as $dbh->B<select>() for select queries, and $dbh->B<do>() for other queries.
287 The primary difference versus $dbh->B<do>() is that the query is not looped against vectors given
288 in a WHERE clause, the WHERE clause must be a simple scalar set of key values, which can be bound
289 with placeholders by the I<bind-parameter-list>. Results are not committed unless I<autocommit> is
290 turned on for the database connection. Think of it as "do ONE query".
291  
292 =item I<$scalar> = $dbh->B<err>();
293  
294 Returns the last error code number encountered.
295  
296 =item I<$scalar> = $dbh->B<errstr>();
297  
298 Returns the last error message text for the last error encountered.
299  
300 =item I<$scalar> = $dbh->B<fetchnextseq>([ I<sequencename> ]);
301  
302 This can be called anytime and returns the next value of sequence I<sequencename>. For Sprite and Oracle,
303 this is accomplished by doing a "SELECT <sequencename>.NEXTVAL from DUAL". For mysql, it returns the
304 I<mysql_insert_id>(). Currently only Oracle, Sprite, mysql, and SQLite are properly supported, but one can
305 add code for their own database or send me a patch! Or, one can rely on the failsafe option
306 (which works if either your database isn't supported, in which case,
307 the first time this function is called, a file named "$ENV{HOME}/.dbixseq" is created with a sequence
308 value of 1, which is returned. Subsequent calls return the next integer and save it to this file,
309 emulating a "sequence". For mysql and SQLite, the I<sequencename> can be omitted as mysql always returns
310 I<mysql_insert_id>() which is the value of the most recent autonumber field updated. SQLite always
311 returns I<sqlite_last_insert_rowid>().
312  
313 =item I<$scalar> = $dbh->B<fetchseq>('I<keyfieldname>', [ 'I<sequencename>', [ I<tablename>' ] ]);
314  
315 This is called after an insert and should return the value of the last sequence specified in that
316 insert (used to get the key of the last record inserted) when using sequences or the autonumbering
317 feature of a database. Only the 1st argument is required. The other arguments are useful if one
318 is not sure their database is supported or to act as a "catch-all" option if a value is not obtainable.
319 This is done by doing a fetch from the table: "Table_Name" for a descending list of values for the
320 field specified by "SEQ_FIELD_NAME" and returns the 1st value returned. I<sequencename> defaults
321 to the last sequence used in Oracle databases, but can be overridden here. This returns the
322 sequence or auto-number assigned to the last key field inserted into a table in a database-independent
323 way. You usually will call this function immediately after inserting a record with a sequence /
324 autonumber field to get the generated key value, for example to create an index record referencing
325 that key value. This currently supports Oracle, Sprite, and MySQL. There is also a default method
326 of fetching a descending list of values and returning the 1st one. This should work with most other
327 databases, but is less efficient. You can add code for your particular database, if it has a more
328 efficient way of supporting it, grep the comments for "ADD CODE".
329  
330 The I<keyfieldname> is the sequence or autonumber field name. The optional I<sequencename> is useful
331 only for Oracle and Sprite databases and specifies the actual "sequence" name to fetch. For others,
332 the default is used, which is the last sequence or autonumber field used in the most recent
333 insert or update query that involved a sequence or autonumber field. The I<tablename> field is
334 useful for other "non-supported" databases (those other than Oracle, Sprite, or mysql) to tell
335 B<fetchseq>() which table to grab the most recent autonumber / sequence field specified by
336 I<keyfieldname> from. It is ignored for supported databases and defaults to the last table to which
337 an insert or update involving a sequence or autonumber field was done.
338  
339 =item I<$scalar> = $dbh->B<package>([ I<package_name> ]);
340  
341 Set or retrieve the current package name used for placeholder variables in "INTO" clauses in queries.
342 IF I<package_name> is specified, the default package for all such variables from that point on in
343 the program (until B<&jdbix_package>() is called with a different package name) are assumed to be of
344 that package. If not specified, it returns the current package name. The default package name
345 is "main". NOTE: The current I<package_name> can also be set for a database when opened by
346 passing the 'I<-jdbix_package>' => 'I<package_name>' attribute when creating the database object.
347  
348 =item I<$scalar> = $dbh->B<rollback>();
349  
350 Causes any pending queries that changed the database to be rolled back (unless I<autocommit> is on for
351 the database connection). If I<autocommit> is on, it returns 1 (true). Otherwise, it returns the
352 result of the DBI->I<rollback>() call.
353  
354 =item $dbh->B<select>('I<query-string>' [, I<bind-parameter-list>]);
355  
356 Perform a selection query on the database. The I<query-string> can be a standard SQL query
357 string, but may contain traditional SQL placeholders ("?") or special JDBIx placeholders
358 in an "INTO" clause representing corresponding Perl variables to receive the respective field data.
359 For example:
360  
361 [ I<$scalar> | I<@array> = ] $dbh->B<select>('select field1, field2, field3 into :f1, :f2, :f3 where keyfield = ?', 'foo');
362  
363 This would do a B<prepare>(), an B<execute>(), and B<fetch>() functions, and create / reset three
364 scalars ($f1, $f2, and $f3) set to the first values returned for the respective fields, and
365 three arrays (@f1, @f2, and @f3), each containing a list of all the values returned for their
366 respective columns. NOTE: These are I<package> variables, NOT "my" variables. The I<package> is
367 the current package (or main) or the one specified by the B<dbix_package> attribute when the
368 database object was created.
369  
370 If <@array> is given, an array of references to arrays of field data is returned. This is not
371 necessary (and memory can be saved) if using the "INTO" clause and package variable placeholders
372 as described above. Each element of the array represents a single "row" or "record" of data as
373 a reference to an array containing the field values returned for that record. If no records are
374 returned, then it is (). If I<$scalar> is given, then it is the number of records (rows) fetched.
375  
376 =back
377  
378 =item B<Cursor Methods>
379  
380 =over 4
381  
382 =item I<$scalar> = $dbh->B<opencsr>(I<query-string> [, I<execute_flag> ]);
383  
384 Opens a "cursor" (does a I<prepare>()) on the query specified by I<query-string> and returns a "cursor"
385 object which can be used ...
386  
387 If the optional I<execute_flag> is set to true, then an I<execute>() is also performed immediately after
388 the I<prepare>(). One can then call B<opencsr>() in I<array> context, if so, the first element is the
389 I<cursor> object returned and the second element is the result returned by the I<execute>() call.
390  
391 Returns I<undef> if anything fails.
392  
393 =item $csr->B<bind>(I<bind-parameter-list>);
394  
395 Causes the values in the I<bind-parameter-list> to be bound to the placeholders and the query to be
396 executed. This is needed unless the I<execute_flag> is set to true when the cursor was opened.
397 Returns the number of rows affected or fetched, I<undef> on failure. "0E0", the Perl "true" value
398 for zero is returned if successful, but no rows are affected. NOTE: If a SELECT query with an INTO
399 clause is used, the data is fetched into the vector arrays by bind() and the number of rows fetched
400 will be returned. In this case, calling fetch() or fetchall() will return empty since the data has
401 already been fetched here. If a SELECT query with no INTO clause is performed, then bind() returns
402 "0E0" (success, but no rows affected or fetched) and then the data can then be fetched with either
403 fetch() or fetchall().
404  
405 =item I<@array> = $csr->B<fetch>();
406  
407 Fetches and returns the next row of data by a call to I<fetchrow_array>(). If no records remained
408 to be fetched, it returns an empty array () (false).
409  
410 =item I<$scalar> | I<@array> = $csr->B<fetchall>();
411  
412 Fetches and returns any and all remaining records by repeated calls to I<fetchrow_array>(). In
413 scalar context, returns only the number of records fetched. In array context, returns an array
414 of array references, one for each record returned. These each reference an array of field values
415 returned. If using array variable placeholders (an INTO clause), then one need not call B<fetchall>()
416 in array context to get back the data.
417  
418 =item $csr->B<closecsr>();
419  
420 Closes the cursor.
421  
422 =back
423  
424 =back
425  
426 =head1 KNOWN BUGS
427  
428 -none (yet)-
429  
430 =head1 SEE ALSO
431  
432 L<DBI>, L<perl(1)>
433  
434 =cut
435  
436 package JDBIx;
437  
438 #NOTE: do commits due to multiple records, do1 does NOT!
439  
440 2 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
441 2 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
442 2 ▶use vars qw(@ISA @EXPORT $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
443 2 $VERSION = '1.02';
444  
445 2 require Exporter;
446  
447 2 @ISA = qw(Exporter);
448 2 @EXPORT = qw(jdbix_autocommit jdbix_setlog jdbix_package jdbix_err jdbix_errstr);
449  
450 2 my $calling_package = 'main';
451 2 my $autocommit = 0;
452 2 my $lastdb;
453 2 my $logfid = 0;
454 2 my $logfh = 0;
455  
456 sub new
457 1 ▶{
Subroutine new: called CC=52 SCAR=72.3
Pod documented
458 1 my $class = shift;
459 1 my $connectstr = shift;
460 1 my $attrs;
461  
462 1 my $self = {};
463 1 ▶ if ($connectstr =~ /^\s*\-/)
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr =~ /^\s*\-/) { } 0 1 1
464 {
465 0 $attrs = {$connectstr, @_};
466 0 foreach my $atb (qw(type name user pswd connect))
467 {
468 0 ▶ $self->{"db$atb"} = delete $attrs->{"-$atb"} || '';
Condition0%0/2
delete $$attrs{"-$atb"} || ''
l!l
00
MC/DC0%0/1
delete $$attrs{"-$atb"} || ''
delete $$attrs{"-$atb"}
Truth table0%0/2
A
A= delete $$attrs{"-$atb"}
Aresult
11
00
469 }
470 $connectstr = (defined($self->{"dbconnect"}))
471 0 ▶ ? $self->{"dbconnect"}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'dbconnect'} ? : 0 0 0
472 : "$self->{dbname},$self->{dbuser},$self->{dbpswd}";
473 }
474 else
475 {
476 1 $attrs = shift;
477 }
478 1 ▶ $self->{proxy} = delete $attrs->{"-proxy"} || '';
Condition50%1/2
delete $attrs->{'-proxy'} || ''
l!l
01
MC/DC0%0/1
delete $attrs->{'-proxy'} || ''
delete $attrs->{'-proxy'}
Truth table50%1/2
A
A= delete $attrs->{'-proxy'}
Aresult
11
00
479  
480 1 my ($dbi_proxy, $j);
481 1 foreach my $i (keys (%$attrs))
482 {
483 3 ▶ if ($i =~ /^\-jdbix_/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^\-jdbix_/o) 0 3 3
484 {
485 0 $j = $i;
486 0 $j =~ s/^\-jdbix_//o;
487 0 $self->{$j} = $attrs->{$i};
488 0 ▶ $ENV{"\U$j\E"} = $attrs->{$i} if ($j =~ s/^env_//o);
Branch: 1 branch
BranchTrueFalseTotal
if $j =~ s/^env_//o 0 0 0
489 0 delete $attrs->{$i};
490 }
491 }
492 1 ▶ if ($self->{proxy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'proxy'}) { } 0 1 1
493 {
494 0 $dbi_proxy = $self->{proxy};
495 0 $dbi_proxy =~ s/\:/\;port\=/;
496 0 $dbi_proxy = 'Proxy:hostname='.$dbi_proxy.';dsn=DBI:';
497 }
498 else
499 {
500 1 $dbi_proxy = '';
501 }
502 1 ▶ $self->{dbtype} = $1 if ($connectstr =~ s/^(\w+)\://);
Branch: 1 branch
BranchTrueFalseTotal
if $connectstr =~ s/^(\w+)\:// 1 0 1
503 1 ▶ $self->{dbtype} = 'ODBC' if ($self->{dbtype} =~ /odbc/i);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbtype"} =~ /odbc/i 0 1 1
504  
505 1 ▶ if ($self->{dbtype} =~ /^Sybase/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dbtype"} =~ /^Sybase/) 0 1 1
506 {
507 #SET IF DB DOES NOT ALLOW "?" PLACEHOLDERS IN SQL-COMMANDS!
508 0 ▶ $self->{noplaceholders} = 1 unless(defined $self->{noplaceholders});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"noplaceholders"} 0 0 0
509 }
510 1 ▶ if ($connectstr =~ s/^\s*(?:connect\=|\=)//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr =~ s/^\s*(?:connect\=|\=)//i) { } 0 1 1
511 {
512 # $self->{dbtype} = $1 if ($connectstr =~ /dbi\:${dbi_proxy}(\w+):/);
513 #x if ($connectstr =~ /dbi\:${dbi_proxy}([^\:]+)\:(\w*)/)
514 0 ▶ if ($connectstr =~ /dbi\:proxy\:([^\:]+)\:/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr =~ /dbi\:proxy\:([^\:]+)\:/i) { } 0 0 0
515 {
516 0 $dbi_proxy = $1;
517 0 ($self->{proxy} = $dbi_proxy) =~ s/\;dsn=DBI$//i;
518 0 ▶ if ($connectstr =~ /dbi\:proxy\:${dbi_proxy}\:([^\:]+)\:(\w*)/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr =~ /dbi\:proxy\:$dbi_proxy\:([^\:]+)\:(\w*)/i) 0 0 0
519 {
520 0 ▶ $self->{dbtype} = $1 if ($1);
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
521 0 ▶ $self->{dbname} = $2 if ($2);
Branch: 1 branch
BranchTrueFalseTotal
if $2 0 0 0
522 }
523 }
524 else #PROXY IS NOT IN THE LITERAL CONNECT STRING, SO REMOVE IT, IF SPECIFIED IN ATTRIBUTES!
525 {
526 0 $dbi_proxy = '';
527 0 ▶ delete $self->{proxy} if (defined $self->{proxy});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"proxy"} 0 0 0
528 # ($self->{dbtype}, $self->{dbname}) = ($1, $2) if ($connectstr =~ /dbi\:([^\:]+)\:(\w*)/);
529 0 ▶ if ($connectstr =~ /dbi\:([^\:]+)\:(\w*)/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr =~ /dbi\:([^\:]+)\:(\w*)/i) 0 0 0
530 {
531 0 ▶ $self->{dbtype} = $1 if ($1);
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
532 0 ▶ $self->{dbname} = $2 if ($2);
Branch: 1 branch
BranchTrueFalseTotal
if $2 0 0 0
533 }
534 }
535 0 $dbi_err = \$DBI::err;
536 0 $dbi_errstr = \$DBI::errstr;
537 0 ▶ ($self->{dbuser}, $self->{dbpswd}) = ($1, $2) if ($connectstr =~ /\,([^\,]*)\,(.*)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $connectstr =~ /\,([^\,]*)\,(.*)$/ 0 0 0
538 0 ▶ unless ($connectstr =~ /dbi\:proxy\:/i || $dbi_proxy)
Branch: 1 branch
BranchTrueFalseTotal
unless ($connectstr =~ /dbi\:proxy\:/i or $dbi_proxy) 0 0 0
Condition0%0/3
$connectstr =~ /dbi\:proxy\:/i or $dbi_proxy
l!l&&r!l&&!r
000
MC/DC0%0/2
$connectstr =~ /dbi\:proxy\:/i or $dbi_proxy
$connectstr =~ /dbi\:proxy\:/i $dbi_proxy
Truth table0%0/3
A or B
A= $connectstr =~ /dbi\:proxy\:/iB= $dbi_proxy
ABresult
1X1
011
000
539 {
540 0 ▶ $ENV{TWO_TASK} ||= $1 if ($connectstr =~ s/\:Oracle\:(\w+)/\:Oracle\:/);
Branch: 1 branch
BranchTrueFalseTotal
if $connectstr =~ s/\:Oracle\:(\w+)/:Oracle:/ 0 0 0
Condition0%0/3
$ENV{"TWO_TASK"} ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"TWO_TASK"} ||= $1
$ENV{"TWO_TASK"} $1
Truth table0%0/3
A ||= B
A= $ENV{"TWO_TASK"}B= $1
ABresult
1X1
011
000
541 }
542 0 my $dB = DBI->connect($connectstr,$self->{dbuser},$self->{dbpswd},$attrs);
543 #print "*** connect1($connectstr,".$self->{dbuser}.',',$self->{dbpswd},",<attrs>);\n";
544 0 ▶ return undef unless ($dB);
Branch: 1 branch
BranchTrueFalseTotal
unless $dB 0 0 0
545 0 ▶ return undef if ($DBI::err);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::err 0 0 0
546 0 $self->{DBI} = $dB;
547 0 ▶ $dB->{AutoCommit} = $attrs->{-AutoCommit} || $autocommit;
Condition0%0/3
$attrs->{'-AutoCommit'} || $autocommit
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrs->{'-AutoCommit'} || $autocommit
$attrs->{'-AutoCommit'} $autocommit
Truth table0%0/3
A || B
A= $attrs->{'-AutoCommit'}B= $autocommit
ABresult
1X1
011
000
548 0 ▶ $dB->{AutoCommit} = 1 if ($self->{dbtype} =~ /^mysql/
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbtype"} =~ /^mysql/ or $connectstr =~ /dbi\:proxy\:/i and $DBI::VERSION < "1.21" 0 0 0
Condition0%0/6
$self->{"dbtype"} =~ /^mysql/ or $connectstr =~ /dbi\:proxy\:/i and $DBI::VERSION < "1.21"
l!l&&r!l&&!r
000
$connectstr =~ /dbi\:proxy\:/i and $DBI::VERSION < "1.21"
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"dbtype"} =~ /^mysql/ or $connectstr =~ /dbi\:proxy\:/i and $DBI::VERSION < "1.21"
$self->{"dbtype"} =~ /^mysql/ $connectstr =~ /dbi\:proxy\:/i $DBI::VERSION < "1.21"
Truth table0%0/4
A or B and C
A= $self->{"dbtype"} =~ /^mysql/B= $connectstr =~ /dbi\:proxy\:/iC= $DBI::VERSION < "1.21"
ABCresult
1XX1
0111
00X0
0100
549 || ($connectstr =~ /dbi\:proxy\:/i && $DBI::VERSION < 1.21));
550 0 $self->{connect} = $connectstr;
551 }
552 else
553 {
554 1 ▶ if ($connectstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($connectstr) 1 0 1
555 1 my @nup = split(/\,/,$connectstr);
556 1 ▶ $self->{dbname} ||= $nup[0] if ($nup[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $nup[0] 1 0 1
Condition33%1/3
$self->{"dbname"} ||= $nup[0]
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"dbname"} ||= $nup[0]
$self->{"dbname"} $nup[0]
Truth table33%1/3
A ||= B
A= $self->{"dbname"}B= $nup[0]
ABresult
1X1
011
000
557 1 ▶ $self->{dbuser} ||= $nup[1] if ($nup[1]);
Branch: 1 branch
BranchTrueFalseTotal
if $nup[1] 0 1 1
Condition0%0/3
$self->{"dbuser"} ||= $nup[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dbuser"} ||= $nup[1]
$self->{"dbuser"} $nup[1]
Truth table0%0/3
A ||= B
A= $self->{"dbuser"}B= $nup[1]
ABresult
1X1
011
000
558 1 ▶ $self->{dbpswd} ||= $nup[2] if ($nup[2]);
Branch: 1 branch
BranchTrueFalseTotal
if $nup[2] 0 1 1
Condition0%0/3
$self->{"dbpswd"} ||= $nup[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dbpswd"} ||= $nup[2]
$self->{"dbpswd"} $nup[2]
Truth table0%0/3
A ||= B
A= $self->{"dbpswd"}B= $nup[2]
ABresult
1X1
011
000
559 }
560
561 1 $dbi_err = \$DBI::err;
562 1 $dbi_errstr = \$DBI::errstr;
563 1 my $dbid;
564 1 ▶ if ($self->{dbtype} =~ /oracle/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /oracle/i) { } 0 1 1
565 {
566 0 @dbname = split(/:/,$self->{dbname});
567 0 ▶ $self->{dbname} = 'T:' . $self->{dbname} if ($#dbname == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $#dbname == 1 0 0 0
568 0 ▶ $ENV{TWO_TASK} = $self->{dbname} unless ($dbi_proxy);
Branch: 1 branch
BranchTrueFalseTotal
unless $dbi_proxy 0 0 0
569 0 $dbid = "dbi:${dbi_proxy}Oracle:";
570 0 ▶ $dbid .= $self->{dbname} if ($dbi_proxy);
Branch: 1 branch
BranchTrueFalseTotal
if $dbi_proxy 0 0 0
571 }
572 else
573 {
574 1 $dbid = "dbi:${dbi_proxy}$self->{dbtype}:$self->{dbname}";
575 }
576 1 my $dB = DBI->connect($dbid,$self->{dbuser},$self->{dbpswd},$attrs);
577 #print "*** connect($dbid,".$self->{dbuser}.',',$self->{dbpswd},",<attrs>);\n";
578 0 ▶ return undef unless ($dB);
Branch: 1 branch
BranchTrueFalseTotal
unless $dB 0 0 0
579 0 ▶ return undef if ($DBI::err);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::err 0 0 0
580 0 $self->{DBI} = $dB;
581 0 ▶ if ($self->{dbtype} =~ /^mysql/ || ($dbi_proxy && $DBI::VERSION < 1.21))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /^mysql/ or $dbi_proxy and $DBI::VERSION < 1.21) { } 0 0 0
Condition0%0/6
$self->{"dbtype"} =~ /^mysql/ or $dbi_proxy and $DBI::VERSION < "1.21"
l!l&&r!l&&!r
000
$dbi_proxy and $DBI::VERSION < "1.21"
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"dbtype"} =~ /^mysql/ or $dbi_proxy and $DBI::VERSION < "1.21"
$self->{"dbtype"} =~ /^mysql/ $dbi_proxy $DBI::VERSION < "1.21"
Truth table0%0/4
A or B and C
A= $self->{"dbtype"} =~ /^mysql/B= $dbi_proxyC= $DBI::VERSION < "1.21"
ABCresult
1XX1
0111
00X0
0100
582 {
583 0 $dB->{AutoCommit} = 1;
584 }
585 else
586 {
587 0 ▶ $dB->{AutoCommit} = $attrs->{-AutoCommit} || $autocommit;
Condition0%0/3
$attrs->{'-AutoCommit'} || $autocommit
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrs->{'-AutoCommit'} || $autocommit
$attrs->{'-AutoCommit'} $autocommit
Truth table0%0/3
A || B
A= $attrs->{'-AutoCommit'}B= $autocommit
ABresult
1X1
011
000
588 }
589 0 $self->{connect} = $dbid;
590 }
591 0 ▶ $self->{calling_package} = $self->{'package'} || $calling_package;
Condition0%0/3
$self->{'package'} || $calling_package
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'package'} || $calling_package
$self->{'package'} $calling_package
Truth table0%0/3
A || B
A= $self->{'package'}B= $calling_package
ABresult
1X1
011
000
592 0 ($self->{dbi_proxy} = $dbi_proxy) =~ s/\;dsn\=DBI\:$/i/;
593 0 $self->{autocommit} = $dB->{AutoCommit};
594 0 $self->{lasterr} = undef;
595 0 $self->{err} = \$DBI::err;
596 0 $self->{errstr} = \$DBI::errstr;
597 0 $self->{logfid} = 0;
598  
599 0 bless $self, $class;
600  
601 0 $lastdb = $self;
602 0 return $self;
603 }
604  
605 sub setlog
606 0 ▶{
Subroutine setlog: not called CC=7 SCAR=40.3
Pod documented
607 0 my $self = shift;
608 0 my ($mylogfid) = shift;
609  
610 0 ▶ $self->{addsemicolon} = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
611  
612 # 0=no change to logfile; 1=append ';'; 2=convert ampresands for SQL-PLUS and append ';'
613
614 0 ▶ $self->{logfh}->close if ($self->{logfid});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"logfid"} 0 0 0
615 0 $self->{logfid} = 0;
616 0 ▶ if ($mylogfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($mylogfid) 0 0 0
617 {
618 0 ▶ $self->{logfh} ||= new FileHandle;
Condition0%0/3
$self->{"logfh"} ||= "FileHandle"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfh"} ||= "FileHandle"->new
$self->{"logfh"} "FileHandle"->new
Truth table0%0/3
A ||= B
A= $self->{"logfh"}B= "FileHandle"->new
ABresult
1X1
011
000
619 0 ▶ if ($self->{logfh} && $self->{logfh}->open(">>$mylogfid"))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'logfh'} and $self->{'logfh'}->open(">>$mylogfid")) { } 0 0 0
Condition0%0/3
$self->{"logfh"} and $self->{"logfh"}->open(">>$mylogfid")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"logfh"} and $self->{"logfh"}->open(">>$mylogfid")
$self->{"logfh"} $self->{"logfh"}->open(">>$mylogfid")
Truth table0%0/3
A and B
A= $self->{"logfh"}B= $self->{"logfh"}->open(">>$mylogfid")
ABresult
0X0
100
111
620 {
621 0 $self->{logfid} = $mylogfid;
622 0 return (1);
623 }
624 else
625 {
626 0 return (0);
627 }
628 }
629 0 return (1);
630 }
631  
632 sub jdbix_setlog
633 1 ▶{
Subroutine jdbix_setlog: called CC=7 SCAR=23.2
Pod documented
634 1 my ($mylogfid) = shift;
635  
636 1 ▶ $addsemicolon = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
637 # 0=no change to logfile; 1=append ';'; 2=convert ampresands for SQL-PLUS and append ';'
638
639 1 ▶ $logfh->close if ($logfid);
Branch: 1 branch
BranchTrueFalseTotal
if $logfid 0 1 1
640 1 $logfid = 0;
641 1 ▶ if ($mylogfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($mylogfid) 1 0 1
642 {
643 1 ▶ $logfh ||= new FileHandle;
Condition33%1/3
$logfh ||= "FileHandle"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$logfh ||= "FileHandle"->new
$logfh "FileHandle"->new
Truth table33%1/3
A ||= B
A= $logfhB= "FileHandle"->new
ABresult
1X1
011
000
644 1 ▶ if ($logfh && $logfh->open(">>$mylogfid"))
Branch: 1 branch
BranchTrueFalseTotal
if ($logfh and $logfh->open(">>$mylogfid")) { } 1 0 1
Condition33%1/3
$logfh and $logfh->open(">>$mylogfid")
!ll&&!rl&&r
001
MC/DC0%0/2
$logfh and $logfh->open(">>$mylogfid")
$logfh $logfh->open(">>$mylogfid")
Truth table33%1/3
A and B
A= $logfhB= $logfh->open(">>$mylogfid")
ABresult
0X0
100
111
645 {
646 1 $logfid = $mylogfid;
647 1 return (1);
648 }
649 else
650 {
651 0 return (0);
652 }
653 }
654 0 return (1);
655 }
656  
657 sub package
658 0 ▶{
Subroutine package: not called CC=3 SCAR=24.8
Pod documented
659 0 my $self = shift;
660 0 my $pkg = shift;
661  
662 0 ▶ return $self->{calling_package} unless (defined($pkg) && $pkg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and $pkg 0 0 0
Condition0%0/3
defined $pkg and $pkg
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg and $pkg
defined $pkg $pkg
Truth table0%0/3
A and B
A= defined $pkgB= $pkg
ABresult
0X0
100
111
663 0 $self->{calling_package} = $pkg;
664 0 return 1;
665 }
666  
667 sub jdbix_package
668 0 ▶{
Subroutine jdbix_package: not called CC=3 SCAR=24.8
Pod documented
669 0 my $pkg = shift;
670  
671 0 ▶ return $calling_package unless (defined($pkg) && $pkg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and $pkg 0 0 0
Condition0%0/3
defined $pkg and $pkg
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pkg and $pkg
defined $pkg $pkg
Truth table0%0/3
A and B
A= defined $pkgB= $pkg
ABresult
0X0
100
111
672  
673 0 $calling_package = $pkg;
674 0 return 1;
675 }
676  
677 sub disconnect
678 0 ▶{
Subroutine disconnect: not called CC=3 SCAR=24.8
Pod documented
679 0 ▶ return undef unless ($_[0]->{DBI});
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"DBI"} 0 0 0
680 0 my $res = $_[0]->{DBI}->disconnect;
681 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
682 {
683 0 $self->{logfh}->close;
684 0 $self->{logfid} = 0;
685 0 undef $self->{logfh};
686 }
687 0 $_[0]->{DBI} = undef;
688 0 undef $_[0];
689 0 return $res;
690 }
691  
692 sub select
693 0 ▶{
Subroutine select: not called CC=28 SCAR=67.0
Pod documented
694 0 my ($self, $sqlstr, @bindvals) = @_; #bindvals ADDED 20000217!
695 0 local ($_);
696 0 my ($i, @res, $mycsr, $myexe, @reflistv, @refsclrv);
697 0 my ($fetchcnt) = 0;
698 0 my (@myline) = ();
699 0 my ($cleansql) = $sqlstr;
700
701 0 $lastdb = $self;
702 #$nores = 1 if ($cleansql =~ s/\binto\b//i);
703 0 $cleansql =~ s/\binto\b//io;
704 #$nores = 1 unless (wantarray); #20000425: CHANGED 2 NEXT LINE (FIX BUG)!
705 0 ▶ $nores = (wantarray ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
706 0 $cleansql =~ s/\:[^\s\,\:]+\,?//go;
707 0 ▶ if ($self->{noplaceholders})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"noplaceholders"}) 0 0 0
708 {
709 0 $cleansql =~ s/([\'\"])([^\1]*?)\1/
710 0 my ($quote) = $1;
711 0 my ($str) = $2;
712 0 $str =~ s|\?|\x02\^2jSpR1tE\x02|go; #PROTECT ?'S IN QUOTES.
713 0 "$quote$str$quote"
714 /egs;
715 0 my $t;
716 0 ▶ while (@bindvals)
Branch: 1 branch
BranchTrueFalseTotal
if (@bindvals) 0 0 0
717 {
718 0 $t = shift(@bindvals);
719 0 $t =~ s/\'/\'\'/gso;
720 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
721 0 $cleansql =~ s/\?/\'$t\'/s;
722 }
723 0 $cleansql =~ s/\x02\^2jSpR1tE\x02/\?/gso;
724 }
725 #print "<BR>-???- clean sql=$cleansql= DB=".$self->{dbtype}."=\n";
726 0 ▶ if ($mycsr = $self->{DBI}->prepare($cleansql))
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr = $self->{"DBI"}->prepare($cleansql)) 0 0 0
727 {
728 0 my (@types, @scales);
729 0 ▶ if ($myexe = $mycsr->execute(@bindvals))
Branch: 1 branch
BranchTrueFalseTotal
if ($myexe = $mycsr->execute(@bindvals)) { } 0 0 0
730 {
731 0 ▶ if ($self->{dbtype} eq 'SQLite') #HACK TO MAKE SQLite SCALED "DECIMALS" ROUND TO PROPER #DECIMALS AND VALUES!
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dbtype"} eq "SQLite") 0 0 0
732 { #SINCE SQLite STORES DECIMALS AS FLOATING POINT (REAL)!
733 0 @types = @{$mycsr->{TYPE}};
734 0 ▶ for (my $i=0;$i<=$#types;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#types) 0 0 0
735 {
736 0 ▶ $scales[$i] = $1 if ($types[$i] =~ /(?:DECIMAL|REAL)\(\d+[\,\.](\d+)\)/io);
Branch: 1 branch
BranchTrueFalseTotal
if $types[$i] =~ /(?:DECIMAL|REAL)\(\d+[\,\.](\d+)\)/io 0 0 0
737 }
738 }
739 0 ▶ if ($sqlstr =~ /\binto\b/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /\binto\b/io) { } 0 0 0
740 {
741 0 my (@varlistv) = ($sqlstr =~ /:\D\w*/go);
742 0 foreach $i (@varlistv)
743 {
744 0 $i =~s/\:/$self->{calling_package}\:\:/;
745 0 $i =~s/\,//o;
746 0 @{$i} = (); #INITIALIZE TO CLEAR ANY OLD VALUES!
747 0 ${$i} = '';
748 0 push (@reflistv,\@{$i});
749 0 push (@refsclrv,\${$i});
750 }
751 0 ▶ while ((@myline) = $mycsr->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->fetchrow_array) 0 0 0
752 {
753 0 ▶ last if (defined($self->{DBI}->err) && $self->{DBI}->err > 0);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"DBI"}->err and $self->{"DBI"}->err > 0 0 0 0
Condition0%0/3
defined $self->{"DBI"}->err and $self->{"DBI"}->err > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"DBI"}->err and $self->{"DBI"}->err > 0
defined $self->{"DBI"}->err $self->{"DBI"}->err > 0
Truth table0%0/3
A and B
A= defined $self->{"DBI"}->errB= $self->{"DBI"}->err > 0
ABresult
0X0
100
111
754 0 ▶ for ($i=0;$i<=$#varlistv;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#varlistv) 0 0 0
755 {
756 0 ▶ $myline[$i] = sprintf("%.$scales[$i]f", $myline[$i]) if (defined $scales[$i]); #FIX SQLite FLOAT->DECIMAL ROUNDING ERRORS
Branch: 1 branch
BranchTrueFalseTotal
if defined $scales[$i] 0 0 0
757 0 ▶ ${$refsclrv[$i]} = $myline[$i] unless ($fetchcnt);
Branch: 1 branch
BranchTrueFalseTotal
unless $fetchcnt 0 0 0
758 0 push(@{$reflistv[$i]},$myline[$i]);
759  
760 }
761 0 ▶ push (@res,[@myline]) unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
762 0 ++$fetchcnt;
763 };
764 }
765 else
766 {
767 0 ▶ if ($self->{dbtype} eq 'SQLite') #HACK TO MAKE SQLite SCALED "DECIMALS" ROUND TO PROPER #DECIMALS AND VALUES!
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dbtype'} eq 'SQLite') { } 0 0 0
768 {
769 0 ▶ while (@myline = $mycsr->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->fetchrow_array) 0 0 0
770 {
771 0 ▶ last if ($self->{DBI}->err > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err > 0 0 0 0
772 0 ▶ for ($i=0;$i<=$#myline;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#myline) 0 0 0
773 {
774 0 ▶ $myline[$i] = sprintf("%.$scales[$i]f", $myline[$i]) if (defined $scales[$i]); #FIX SQLite FLOAT->DECIMAL ROUNDING ERRORS
Branch: 1 branch
BranchTrueFalseTotal
if defined $scales[$i] 0 0 0
775 }
776 0 ▶ push (@res,[@myline]) unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
777 0 ++$fetchcnt;
778 }
779 }
780 else
781 {
782 0 ▶ while (@myline = $mycsr->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->fetchrow_array) 0 0 0
783 {
784 0 ▶ last if ($self->{DBI}->err > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err > 0 0 0 0
785 0 ▶ push (@res,[@myline]) unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
786 0 ++$fetchcnt;
787 }
788 }
789 }
790 }
791 else
792 {
793 0 return ();
794 }
795 0 $mycsr->finish();
796 #$mycsr = undef;
797 #return ( wantarray ? ('a','b','c') : $#res );
798 0 ▶ return (@res) unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
799 0 return $fetchcnt;
800 }
801 0 return ();
802 }
803  
804 sub do
805 0 ▶{
Subroutine do: not called CC=38 SCAR=73.0
Pod documented
806 0 my ($self, $sqlstr, $ophref) = @_;
807  
808 #### WARNING: DO *NOT* USE SINGLE-QUOTES AROUND ANY :PARAMETERS !!!!!!!!!
809 #### (IT DON'T WORK!)
810  
811 0 ▶ my ($interpolate) = $ophref->{-interpolate} || $ophref;
Condition0%0/3
$ophref->{'-interpolate'} || $ophref
l!l&&r!l&&!r
000
MC/DC0%0/2
$ophref->{'-interpolate'} || $ophref
$ophref->{'-interpolate'} $ophref
Truth table0%0/3
A || B
A= $ophref->{'-interpolate'}B= $ophref
ABresult
1X1
011
000
812 0 local ($_);
813 0 my ($i, $j, $mycsr, $myexe, $rowcnt, @myvals,
814 @varlistv, $logsql, $isaselect, $myline);
815 0 my ($maxlistsize) = -1;
816 0 my ($parmcnt) = 0;
817
818 0 $lastdb = $self;
819 0 $rowcnt = 0;
820 0 ▶ unless ($interpolate) #20001117: 3RD OPTION (=3): RETURN 0 OR MORE RECORDS FOR EACH KEY
Branch: 1 branch
BranchTrueFalseTotal
unless ($interpolate) 0 0 0
821 { #20001117: (=2) ALWAYS RETURNS 1 OR MORE RECORDS!
822 0 $rowcnt = $self->{DBI}->do($sqlstr);
823 0 ▶ if ($self->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$self->{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfid"} or $logfid
$self->{"logfid"} $logfid
Truth table0%0/3
A or B
A= $self->{"logfid"}B= $logfid
ABresult
1X1
011
000
824 {
825 0 $sqlstr =~ s/\s+$//o;
826 0 $sqlstr =~ s/^\s+//o;
827 0 ▶ $sqlstr .= ';' if ($self->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} 0 0 0
828 $sqlstr =~ s/\&/\'\|\|\'\&\'\|\|\'/go
829 0 ▶ if ($self->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} == 1 0 0 0
830 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
831 {
832 0 my $logfh = $self->{logfh}; #NEEDED FOR PERL TO COMPILE.
833 0 flock $logfh, 2; #EXCLUSIVE LOCK.
834 0 print $logfh "$sqlstr\n";
835 0 flock $logfh, 8; #UNLOCK.
836 }
837 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
838 {
839 0 flock $logfh, 2; #EXCLUSIVE LOCK.
840 0 print $logfh "$sqlstr\n";
841 0 flock $logfh, 8; #UNLOCK.
842 }
843 }
844 0 ▶ $self->commit() if ($ophref->{-commit});
Branch: 1 branch
BranchTrueFalseTotal
if $ophref->{"-commit"} 0 0 0
845 0 ▶ return (undef) if ($self->{DBI}->err < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err < 0 0 0 0
846 0 return ($rowcnt);
847 }
848 0 my $varliststart = 0; #NEXT 15 ADDED 20011207 TO FIX INCORRECT MAXLISTSIZE ON SELECTS.
849 0 ▶ if ($sqlstr =~ /^\s*select\s/io) #("INTO" VBLES NEEDED BLANKING *BEFORE* MAXLISTSIZE CALCULATED!)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /^\s*select\s/io) 0 0 0
850 {
851 0 $isaselect = 1;
852 #CHGD. TO NEXT 20160122 TO ALLOW :vbles W/O LEADING "/": while ($sqlstr =~ s#(into[\s\?\,]+)(\/\:[a-zA-Z_][^,\)\s\"]*)#$1\?#i)
853 0 ▶ while ($sqlstr =~ s#(into[\s\?\,]+)(\/?\:[a-zA-Z_][\w\d\_]*)#$1\?#i)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ s[(into[\s\?\,]+)(\/?\:[a-zA-Z_][\w\d\_]*)][$1?]i) 0 0 0
854 {
855 0 push (@varlistv,$2);
856 0 ++$parmcnt;
857 }
858 0 ▶ for ($i=0;$i<=$#varlistv;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#varlistv) 0 0 0
859 {
860 #CHGD. TO NEXT 20160122 TO ALLOW :vbles W/O LEADING "/": $varlistv[$i] =~ s#/\:#$self->{calling_package}\:\:#;
861 0 $varlistv[$i] =~ s#\/?\:#$self->{calling_package}\:\:#;
862 }
863 0 $varliststart = scalar(@varlistv);
864 }
865 #CHGD. TO NEXT 20160122 TO ALLOW :vbles W/O LEADING "/": while ($sqlstr =~ s#\'?(\/\:[a-zA-Z_][^,\)\s\"]*)#\?#o)
866 0 ▶ while ($sqlstr =~ s#\'?(\/?\:[a-zA-Z_][\w\d\_]*)#\?#o)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ s[\'?(\/?\:[a-zA-Z_][\w\d\_]*)][?]o) 0 0 0
867 {
868 0 push (@varlistv,$1);
869 0 ++$parmcnt;
870 }
871 0 ▶ for ($i=$varliststart;$i<=$#varlistv;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#varlistv) 0 0 0
872 {
873 #CHGD. TO NEXT 20160122 TO ALLOW :vbles W/O LEADING "/": $varlistv[$i] =~ s#/\:#$self->{calling_package}\:\:#;
874 0 $varlistv[$i] =~ s#\/?\:#$self->{calling_package}\:\:#;
875 0 ▶ if ($#{$varlistv[$i]} >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$varlistv[$i];} >= 0) 0 0 0
876 {
877 0 ▶ $maxlistsize = $#{$varlistv[$i]} if ($#{$varlistv[$i]} > $maxlistsize);
Branch: 1 branch
BranchTrueFalseTotal
if $#{$varlistv[$i];} > $maxlistsize 0 0 0
878 }
879 }
880 0 $sqlstr =~ s/'(\:\d+)'/$1/g;
881 #$sqlstr =~ s/'\?'/\?/g; #REMOVED 20010125 TO FIX ERROR WHEN USER ENTRY WAS JUST A SINGLE QUESTION-MARK!
882 0 my ($cleansql) = $sqlstr;
883 0 $selectargcnt = 0;
884 0 ▶ if ($isaselect)
Branch: 1 branch
BranchTrueFalseTotal
if ($isaselect) { } 0 0 0
885 {
886 0 $cleansql =~ s/\binto\b([\s\?\,]*)//io;
887 0 my ($t) = $1;
888 0 ▶ ++$selectargcnt while ($t =~ /\?/go);
Branch: 1 branch
BranchTrueFalseTotal
$t =~ /\?/go and do { ++$selectargcnt } 0 0 0
889 }
890 else
891 {
892 ###########$sqlstr =~ s/\n/ /gs;
893 0 ▶ if ($self->{dbtype} =~ /^odbc/io && $sqlstr =~ /insert.*\w+\.NEXTVAL/so)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so) { } 0 0 0
elsif ($self->{'dbtype'} =~ /^mysql/o) { } 0 0 0
Condition0%0/3
$self->{"dbtype"} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dbtype"} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so
$self->{"dbtype"} =~ /^odbc/io $sqlstr =~ /insert.*\w+\.NEXTVAL/so
Truth table0%0/3
A and B
A= $self->{"dbtype"} =~ /^odbc/ioB= $sqlstr =~ /insert.*\w+\.NEXTVAL/so
ABresult
0X0
100
111
894 {
895 0 $sqlstr = &_fixNEXTVAL($self, $sqlstr);
896 }
897 elsif ($self->{dbtype} =~ /^mysql/o)
898 {
899 0 $sqlstr =~ s/([\,\(]\s*)\w+\.NEXTVAL(\s*[\,\)])/$1NULL$2/g;
900 #MYSQL DOES SEQUENCES DIFFERENTLY (see AUTO_INCREMENT)!
901 }
902 #ADDED 20030904 TO MAKE SEQUENCE-RETRIEVAL DATABASE-INDEPENDENT.
903 0 ▶ if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/sio)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/iso) 0 0 0
904 {
905 0 $self->{lastsequencetable} = $1;
906 0 $self->{lastsequencename} = $2;
907 }
908 }
909 0 ▶ for ($i=0;$i<$selectargcnt;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $selectargcnt) 0 0 0
910 {
911 0 @{$varlistv[$i]} = (); #INITIALIZE TO CLEAR ANY OLD VALUES
912 0 ${$varlistv[$i]} = ''; #FROM VBLES TO RECEIVE SELECT INPUTS.
913 }
914 0 my $cleantemplate;
915 0 ▶ if ($self->{noplaceholders})
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'noplaceholders'}) { } 0 0 0
elsif ($isaselect) { } 0 0 0
916 {
917 0 $cleansql =~ s/([\'\"])([^\1]*?)\1/
918 0 my ($quote) = $1;
919 0 my ($str) = $2;
920 0 $str =~ s|\?|\x02\^2jSpR1tE\x02|go; #PROTECT ?'S IN QUOTES.
921 0 "$quote$str$quote"
922 /egs;
923 0 $cleansql =~ s/\?/\x02\^3jSpR1tE\x02/gso; #PROTECT BINDING ?S.
924 0 $cleansql =~ s/\x02\^2jSpR1tE\x02/\?/gso; #UNPROTECT ?'S IN QUOTES.
925 0 $cleantemplate = $cleansql;
926 }
927 elsif ($isaselect)
928 {
929 0 ▶ $mycsr = $self->{DBI}->prepare($cleansql) or return ();
Branch: 1 branch
BranchTrueFalseTotal
$mycsr = $self->{"DBI"}->prepare($cleansql) or return () 0 0 0
930 }
931  
932 0 ▶ $maxlistsize = 0 if ($maxlistsize < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $maxlistsize < 0 0 0 0
933 0 my ($ii) = 0;
934 0 my $bindok;
935  
936 #-------------------------------------------------------------
937  
938 local *select_noplaceholders = sub
939 0 ▶ {
Subroutine __ANON__: not called CC=17 SCAR=57.2
940 0 my $t;
941 0 ▶ for ($i=0;$i<=$maxlistsize;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $maxlistsize) 0 0 0
942 {
943 0 $cleansql = $cleantemplate;
944 0 ▶ for ($j=$selectargcnt;$j<=$parmcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $parmcnt - 1) 0 0 0
945 {
946 0 $t = defined($#{$varlistv[$j]}) ? ${$varlistv[$j]}[$i]
947 0 ▶ : ${$varlistv[$j]};
Branch: 1 branch
BranchTrueFalseTotal
defined $#{$varlistv[$j];} ? : 0 0 0
948 0 $t =~ s/\'/\'\'/gso;
949 0 $t =~ s/\?/\x02\^3jSpR1tE\x02/gso;
950 0 $cleansql =~ s/\x02\^3jSpR1tE\x02/\'$t\'/s;
951 }
952 0 @myline = ();
953 0 $mycsr = $self->{DBI}->prepare($cleansql);
954 0 ▶ return 0 if ($self->{DBI}->err); #ADDED 20010517 TO CATCH ERRORS!
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err 0 0 0
955 0 $res = $mycsr->execute();
956 0 ▶ return 0 if ($self->{DBI}->err); #ADDED 20010517 TO CATCH ERRORS!
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err 0 0 0
957 #return 0 unless ($res > 0 || $mycsr);
958 0 @myline = $mycsr->fetchrow_array();
959 0 ▶ if ($#myline >= 0 || $interpolate < 3) #IF ADDED 20001117
Branch: 1 branch
BranchTrueFalseTotal
if ($#myline >= 0 or $interpolate < 3) 0 0 0
Condition0%0/3
$#myline >= 0 or $interpolate < 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$#myline >= 0 or $interpolate < 3
$#myline >= 0 $interpolate < 3
Truth table0%0/3
A or B
A= $#myline >= 0B= $interpolate < 3
ABresult
1X1
011
000
960 {
961 0 ▶ for ($j=0;$j<=$selectargcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $selectargcnt - 1) 0 0 0
962 {
963 0 ▶ $myline[$j] = '' if ($res eq 'OK'); #ADDED 19991011 JWT.
Branch: 1 branch
BranchTrueFalseTotal
if $res eq "OK" 0 0 0
964 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
965 {
966 0 ${$varlistv[$j]}[$ii] = $myline[$j];
967 }
968 else
969 {
970 0 ${$varlistv[$j]} = $myline[$j];
971 }
972 }
973 0 ++$ii;
974 0 ++$rowcnt;
975 }
976 0 ▶ if ($interpolate >= 2) #20001117
Branch: 1 branch
BranchTrueFalseTotal
if ($interpolate >= 2) 0 0 0
977 {
978 II:
979 0 ▶ while (@myline = $mycsr->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->fetchrow_array) 0 0 0
980 {
981 0 ▶ for ($j=0;$j<=$selectargcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $selectargcnt - 1) 0 0 0
982 {
983 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
984 {
985 0 ${$varlistv[$j]}[$ii] = $myline[$j];
986 }
987 else
988 {
989 0 ${$varlistv[$j]} = $myline[$j];
990 }
991 }
992 0 ++$ii;
993 0 ++$rowcnt;
994 }
995 }
996 0 $mycsr->finish();
997 0 ▶ if ($ophref->{-commit})
Branch: 1 branch
BranchTrueFalseTotal
if ($ophref->{"-commit"}) 0 0 0
998 {
999 0 ▶ $self->commit() unless ($rowcnt % 20);
Branch: 1 branch
BranchTrueFalseTotal
unless $rowcnt % 20 0 0 0
1000 }
1001 }
1002 0 return 1;
1003 0 };
1004  
1005 local *select_placeholders = sub
1006 0 ▶ {
Subroutine __ANON__: not called CC=17 SCAR=57.2
1007 0 ▶ for ($i=0;$i<=$maxlistsize;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $maxlistsize) 0 0 0
1008 {
1009 0 @myvals = ();
1010 0 ▶ for ($j=$selectargcnt;$j<=$parmcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $parmcnt - 1) 0 0 0
1011 {
1012 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
1013 {
1014 0 push(@myvals,${$varlistv[$j]}[$i]);
1015 ###$mycsr->bind_param($j1, ${$varlistv[$j]}[$i]) if ($mycsr);
1016 }
1017 else
1018 {
1019 0 push(@myvals,${$varlistv[$j]});
1020 }
1021 }
1022 0 $res = $mycsr->execute(@myvals);
1023 0 ▶ return 0 if ($self->{DBI}->err); #ADDED 20010517 TO CATCH ERRORS!
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"}->err 0 0 0
1024 0 @myline = $mycsr->fetchrow_array();
1025 0 ▶ if ($#myline >= 0 || $interpolate < 3) #IF ADDED 20001117
Branch: 1 branch
BranchTrueFalseTotal
if ($#myline >= 0 or $interpolate < 3) 0 0 0
Condition0%0/3
$#myline >= 0 or $interpolate < 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$#myline >= 0 or $interpolate < 3
$#myline >= 0 $interpolate < 3
Truth table0%0/3
A or B
A= $#myline >= 0B= $interpolate < 3
ABresult
1X1
011
000
1026 {
1027 0 ▶ for ($j=0;$j<=$selectargcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $selectargcnt - 1) 0 0 0
1028 {
1029 0 ▶ $myline[$j] = '' if ($res eq 'OK'); #ADDED 19991011 JWT.
Branch: 1 branch
BranchTrueFalseTotal
if $res eq "OK" 0 0 0
1030 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
1031 {
1032 0 ${$varlistv[$j]}[$ii] = $myline[$j];
1033 }
1034 else
1035 {
1036 0 ${$varlistv[$j]} = $myline[$j];
1037 }
1038 }
1039 0 ++$ii;
1040 0 ++$rowcnt;
1041 }
1042 0 ▶ if ($interpolate >= 2) #20001117
Branch: 1 branch
BranchTrueFalseTotal
if ($interpolate >= 2) 0 0 0
1043 {
1044 II:
1045 0 ▶ if (scalar(@myline)) #TEST ADDED 20040211 TO PREVENT RAISE-ERROR ERROR.
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @myline) 0 0 0
1046 {
1047 0 ▶ while (@myline = $mycsr->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->fetchrow_array) 0 0 0
1048 {
1049 0 ▶ for ($j=0;$j<=$selectargcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $selectargcnt - 1) 0 0 0
1050 {
1051 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
1052 {
1053 0 ${$varlistv[$j]}[$ii] = $myline[$j];
1054 }
1055 else
1056 {
1057 0 ${$varlistv[$j]} = $myline[$j];
1058 }
1059 }
1060 0 ++$ii;
1061 0 ++$rowcnt;
1062 }
1063 }
1064 }
1065 0 $mycsr->finish();
1066 0 ▶ if ($ophref->{-commit})
Branch: 1 branch
BranchTrueFalseTotal
if ($ophref->{"-commit"}) 0 0 0
1067 {
1068 0 ▶ $self->commit() unless ($rowcnt % 20);
Branch: 1 branch
BranchTrueFalseTotal
unless $rowcnt % 20 0 0 0
1069 }
1070 }
1071 0 return 1;
1072 0 };
1073  
1074 local *nonselect_noplaceholders = sub
1075 0 ▶ {
Subroutine __ANON__: not called CC=14 SCAR=53.5
1076 0 my $t;
1077 0 ▶ for ($i=0;$i<=$maxlistsize;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $maxlistsize) 0 0 0
1078 {
1079 0 @myvals = ();
1080 0 $cleansql = $cleantemplate;
1081 0 ▶ for ($j=$selectargcnt;$j<=$parmcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $parmcnt - 1) 0 0 0
1082 {
1083 0 $t = defined($#{$varlistv[$j]}) ? ${$varlistv[$j]}[$i]
1084 0 ▶ : ${$varlistv[$j]};
Branch: 1 branch
BranchTrueFalseTotal
defined $#{$varlistv[$j];} ? : 0 0 0
1085 0 $t =~ s/\'/\'\'/gso;
1086 0 $t =~ s/\?/\x02\^3jSpR1tE\x02/gso;
1087 0 $cleansql =~ s/\x02\^3jSpR1tE\x02/\'$t\'/s;
1088 }
1089 0 @myline = ();
1090 0 $res = $self->{DBI}->do($cleansql);
1091 0 ▶ return 0 unless ($res eq '0E0' || $res > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $res eq "0E0" or $res > 0 0 0 0
Condition0%0/3
$res eq "0E0" or $res > 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$res eq "0E0" or $res > 0
$res eq "0E0" $res > 0
Truth table0%0/3
A or B
A= $res eq "0E0"B= $res > 0
ABresult
1X1
011
000
1092 0 ++$rowcnt;
1093 0 ▶ if ($self->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$self->{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfid"} or $logfid
$self->{"logfid"} $logfid
Truth table0%0/3
A or B
A= $self->{"logfid"}B= $logfid
ABresult
1X1
011
000
1094 {
1095 0 $logsql = $cleansql;
1096 0 $logsql =~ s/\s+$//o;
1097 0 $logsql =~ s/^\s+//o;
1098 0 ▶ $logsql .= ';' if ($self->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} 0 0 0
1099 $sqlstr =~ s/\&/\'\|\|\'\&\'\|\|\'/go
1100 0 ▶ if ($self->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} == 1 0 0 0
1101 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
1102 {
1103 0 my $logfh = $self->{logfh}; #NEEDED FOR PERL TO COMPILE.
1104 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1105 0 print $logfh "$logsql\n";
1106 0 flock $logfh, 8; #UNLOCK.
1107 }
1108 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
1109 {
1110 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1111 0 print $logfh "$logsql\n";
1112 0 flock $logfh, 8; #UNLOCK.
1113 }
1114 }
1115 0 ▶ if ($ophref->{-commit})
Branch: 1 branch
BranchTrueFalseTotal
if ($ophref->{"-commit"}) 0 0 0
1116 {
1117 0 ▶ $self->commit() unless ($rowcnt % 20);
Branch: 1 branch
BranchTrueFalseTotal
unless $rowcnt % 20 0 0 0
1118 }
1119 }
1120 0 return 1;
1121 0 };
1122  
1123 local *nonselect_placeholders = sub
1124 0 ▶ {
Subroutine __ANON__: not called CC=15 SCAR=54.8
1125 0 ▶ for ($i=0;$i<=$maxlistsize;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $maxlistsize) 0 0 0
1126 {
1127 0 @myvals = ();
1128 0 ▶ for ($j=$selectargcnt;$j<=$parmcnt-1;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $parmcnt - 1) 0 0 0
1129 {
1130 0 ▶ if (defined($#{$varlistv[$j]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $#{$varlistv[$j];}) { } 0 0 0
1131 {
1132 0 push(@myvals,${$varlistv[$j]}[$i]);
1133 ###$mycsr->bind_param($j1, ${$varlistv[$j]}[$i]) if ($mycsr);
1134 }
1135 else
1136 {
1137 0 push(@myvals,${$varlistv[$j]});
1138 }
1139 }
1140 0 @myline = ();
1141 0 $res = $self->{DBI}->do($cleansql,{},@myvals);
1142 0 ▶ return 0 unless ($res eq '0E0' || $res > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $res eq "0E0" or $res > 0 0 0 0
Condition0%0/3
$res eq "0E0" or $res > 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$res eq "0E0" or $res > 0
$res eq "0E0" $res > 0
Truth table0%0/3
A or B
A= $res eq "0E0"B= $res > 0
ABresult
1X1
011
000
1143 0 ++$rowcnt;
1144 0 ▶ if ($self->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$self->{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfid"} or $logfid
$self->{"logfid"} $logfid
Truth table0%0/3
A or B
A= $self->{"logfid"}B= $logfid
ABresult
1X1
011
000
1145 {
1146 0 $logsql = $cleansql;
1147 0 ▶ for ($j=0;$j<=$#myvals;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#myvals) 0 0 0
1148 {
1149 #$j1 = $j + 1;
1150 #$logsql =~ s/\:$j1/\'$myvals[$j]\'/g;
1151 0 $logsql =~ s/\?/\'$myvals[$j]\'/;
1152 }
1153 0 $logsql =~ s/\s+$//o;
1154 0 $logsql =~ s/^\s+//o;
1155 0 ▶ $logsql .= ';' if ($self->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} 0 0 0
1156 $sqlstr =~ s/\&/\'\|\|\'\&\'\|\|\'/go
1157 0 ▶ if ($self->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} == 1 0 0 0
1158 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
1159 {
1160 0 my $logfh = $self->{logfh}; #NEEDED FOR PERL TO COMPILE.
1161 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1162 0 print $logfh "$logsql\n";
1163 0 flock $logfh, 8; #UNLOCK.
1164 }
1165 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
1166 {
1167 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1168 0 print $logfh "$logsql\n";
1169 0 flock $logfh, 8; #UNLOCK.
1170 }
1171 }
1172 0 ▶ if ($ophref->{-commit})
Branch: 1 branch
BranchTrueFalseTotal
if ($ophref->{"-commit"}) 0 0 0
1173 {
1174 0 ▶ $self->commit() unless ($rowcnt % 20);
Branch: 1 branch
BranchTrueFalseTotal
unless $rowcnt % 20 0 0 0
1175 }
1176 }
1177 0 return 1;
1178 0 };
1179  
1180 #-------------------------------------------------------------
1181  
1182 0 ▶ if ($isaselect)
Branch: 1 branch
BranchTrueFalseTotal
if ($isaselect) { } 0 0 0
1183 {
1184 0 ▶ $bindok = $self->{noplaceholders} ? &select_noplaceholders() : &select_placeholders();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'noplaceholders'} ? : 0 0 0
1185 }
1186 else
1187 {
1188 0 ▶ $bindok = $self->{noplaceholders} ? &nonselect_noplaceholders() : &nonselect_placeholders();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'noplaceholders'} ? : 0 0 0
1189 }
1190 0 ▶ if ($bindok)
Branch: 1 branch
BranchTrueFalseTotal
if ($bindok) { } 0 0 0
1191 {
1192 0 ▶ $self->commit() if ($ophref->{-commit});
Branch: 1 branch
BranchTrueFalseTotal
if $ophref->{"-commit"} 0 0 0
1193 #NEXT IF ADDED 20040120 TO SORT VECTORIZED SELECTS (WHICH DON'T SORT
1194 #OTHERWISE) WHEN "ORDER-BY" CLAUSE PRESENT. NOTE: ONLY SELECT VECTORS
1195 #ARE SORTED (NOT KEY VECTORS) UNLESS INTERPOLATE = 1 (INTERPOLATE = 1
1196 #IMPLIES A PROMISE THAT *ALL* VECTORS WILL BE *SAME* LENGTH!!!!!!!!
1197 0 ▶ if ($isaselect && $selectargcnt > 0 && $rowcnt > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($isaselect and $selectargcnt > 0 and $rowcnt > 1) 0 0 0
Condition0%0/6
$isaselect and $selectargcnt > 0 and $rowcnt > 1
!ll&&!rl&&r
000
$isaselect and $selectargcnt > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$isaselect and $selectargcnt > 0 and $rowcnt > 1
$isaselect $selectargcnt > 0 $rowcnt > 1
Truth table0%0/4
A and B and C
A= $isaselectB= $selectargcnt > 0C= $rowcnt > 1
ABCresult
0XX0
10X0
1100
1111
1198 {
1199 0 ▶ if ($sqlstr =~ /\s*order\s+by\s+([\w\.\, ]+)$/iso)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /\s*order\s+by\s+([\w\.\, ]+)$/iso) 0 0 0
1200 {
1201 0 my $ordbyclause = $1;
1202 0 my $sortavailable;
1203 #s eval {require 'sort_elements.pl' and $sortavailable = 1;};
1204 #s if ($sortavailable)
1205 0 unless (1)
1206 {
1207 my @sortfields = split(/\,/o, $ordbyclause);
1208 my @sortorders = ();
1209 for (my $i=0;$i<=$#sortfields;$i++) #ASCENDING VS. DESCENDING.
1210 {
1211 $sortorders[$i] = ($sortfields[$i] =~ s/\s+desc//iso)
1212 ? '-' : '';
1213 $sortfields[$i] =~ s/\s//go;
1214 }
1215 if ($sqlstr =~ /select\s+([a-z\.\,_\s]+)into/iso)
1216 {
1217 my $selfields = $1;
1218 my @selfields = split(/\,/o, $selfields);
1219 my @sortvec;
1220 for (my $i=0;$i<=$#selfields;$i++)
1221 {
1222 $selfields[$i] =~ s/\s//go;
1223 }
1224 #DETERMINE WHICH ARRAYS TO SORT BY (SORTVEC).
1225 for (my $j=0;$j<=$#sortfields;$j++)
1226 {
1227 for (my $i=0;$i<=$#selfields;$i++)
1228 {
1229 push (@sortvec, "$sortorders[$j]$i") if ($selfields[$i] eq $sortfields[$j])
1230 }
1231 }
1232 my $sortcmd;
1233 if ($interpolate == 1) #SORT *ALL* VECTORS INCL. KEYS!
1234 {
1235 $sortcmd = "&sort_elements_by_list(["
1236 .join(',',@sortvec).'], [], \@'
1237 .join(',\@', @varlistv).');';
1238 }
1239 else #ONLY SORT NON-KEY VECTORS (KEY VECTORS NOT SAME LENGTH).
1240 { #WARNING - KEY VECTORS WILL NOT LINE UP WITH SELECT VECTORS NOW!
1241 $sortcmd = "&sort_elements_by_list(["
1242 .join(',',@sortvec).'], []';
1243 for (my $i=0;$i<=$#selfields;$i++)
1244 {
1245 $sortcmd .= ',\@'.$varlistv[$i];
1246 }
1247 $sortcmd .= ');';
1248 }
1249 eval $sortcmd;
1250 }
1251 }
1252 }
1253 }
1254 0 return $rowcnt;
1255 }
1256 else
1257 {
1258 0 NOBIND:
1259 return undef;
1260 }
1261 }
1262  
1263 sub commit
1264 0 ▶{
Subroutine commit: not called CC=2 SCAR=17.9
Pod documented
1265 0 my ($self) = shift;
1266
1267 0 local ($_);
1268 0 $lastdb = $self;
1269 #return $self->{DBI}->commit; #AUTOCOMMIT IS ON!
1270  
1271 0 ▶ return $self->{DBI}->commit unless ($self->{DBI}->{AutoCommit}); #AUTOCOMMIT IS ON!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DBI"}{"AutoCommit"} 0 0 0
1272 0 return 0;
1273 }
1274  
1275 sub rollback
1276 0 ▶{
Subroutine rollback: not called CC=2 SCAR=17.9
Pod documented
1277 0 my ($self) = shift;
1278  
1279 0 local ($_);
1280 0 ▶ return $self->{DBI}->rollback unless ($self->{DBI}->{AutoCommit}); #AUTOCOMMIT IS ON!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DBI"}{"AutoCommit"} 0 0 0
1281 0 return 0;
1282 }
1283  
1284 sub autocommit #CALL WITH 1 ARG UNLESS DB ALREADY OPEN!
1285 0 ▶{
Subroutine autocommit: not called CC=3 SCAR=24.8
Pod documented
1286 0 my ($self) = shift;
1287 0 my ($ac) = shift;
1288  
1289 0 ▶ return $self->{autocommit} unless (defined($ac) && $ac);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ac and $ac 0 0 0
Condition0%0/3
defined $ac and $ac
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ac and $ac
defined $ac $ac
Truth table0%0/3
A and B
A= defined $acB= $ac
ABresult
0X0
100
111
1290  
1291 0 $lastdb = $self;
1292 0 $self->{DBI}->{AutoCommit} = $ac;
1293 0 $self->{autocommit} = $ac;
1294 0 return 1;
1295 }
1296  
1297 sub jdbix_autocommit #CALL WITH 1 ARG UNLESS DB ALREADY OPEN!
1298 0 ▶{
Subroutine jdbix_autocommit: not called CC=3 SCAR=24.8
Pod documented
1299 0 my ($ac) = shift;
1300 0 ▶ return $autocommit unless (defined($ac) && $ac);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ac and $ac 0 0 0
Condition0%0/3
defined $ac and $ac
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ac and $ac
defined $ac $ac
Truth table0%0/3
A and B
A= defined $acB= $ac
ABresult
0X0
100
111
1301  
1302 0 $autocommit = $ac;
1303 0 return 1;
1304 }
1305  
1306 sub jdbix_err
1307 0 ▶{
Subroutine jdbix_err: not called CC=3 SCAR=24.8
Pod documented
1308 0 ▶ my ($self) = shift || $lastdb;
Condition0%0/3
shift() || $lastdb
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $lastdb
shift() $lastdb
Truth table0%0/3
A || B
A= shift()B= $lastdb
ABresult
1X1
011
000
1309  
1310 0 ▶ return $self ? $self->err() : $DBI::err;
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
1311 }
1312  
1313 sub err
1314 0 ▶{
Subroutine err: not called CC=5 SCAR=34.0
Pod documented
1315 0 my $self = shift;
1316  
1317 0 ▶ return $self->{DBI}->err if ($self->{DBI} && $self->{DBI}->err);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"} and $self->{"DBI"}->err 0 0 0
Condition0%0/3
$self->{"DBI"} and $self->{"DBI"}->err
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"DBI"} and $self->{"DBI"}->err
$self->{"DBI"} $self->{"DBI"}->err
Truth table0%0/3
A and B
A= $self->{"DBI"}B= $self->{"DBI"}->err
ABresult
0X0
100
111
1318 0 ▶ return ${$self->{err}} if (ref $self->{err});
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"err"} 0 0 0
1319 0 ▶ return $DBI::err if ($DBI::err);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::err 0 0 0
1320 0 return undef;
1321 }
1322  
1323 sub jdbix_errstr
1324 0 ▶{
Subroutine jdbix_errstr: not called CC=3 SCAR=24.8
Pod documented
1325 0 ▶ my ($self) = shift || $lastdb;
Condition0%0/3
shift() || $lastdb
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $lastdb
shift() $lastdb
Truth table0%0/3
A || B
A= shift()B= $lastdb
ABresult
1X1
011
000
1326  
1327 # return 'Not logged in, invalid database, id, password?' unless ($self);
1328 0 ▶ return $self ? $self->errstr() : $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
1329 }
1330  
1331 sub errstr
1332 0 ▶{
Subroutine errstr: not called CC=4 SCAR=30.0
Pod documented
1333 0 my $self = shift;
1334 0 ▶ return $self->{DBI}->errstr if ($self->{DBI} && $self->{DBI}->errstr);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DBI"} and $self->{"DBI"}->errstr 0 0 0
Condition0%0/3
$self->{"DBI"} and $self->{"DBI"}->errstr
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"DBI"} and $self->{"DBI"}->errstr
$self->{"DBI"} $self->{"DBI"}->errstr
Truth table0%0/3
A and B
A= $self->{"DBI"}B= $self->{"DBI"}->errstr
ABresult
0X0
100
111
1335 # return $$self->{errstr} if (ref $self->{errstr});
1336 0 ▶ return $DBI::errstr if ($DBI::errstr);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::errstr 0 0 0
1337 0 return $self->err();
1338 }
1339  
1340 package JDBIx::csr;
1341  
1342 2 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
1343  
1344 sub new
1345 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
1346 0 my $class = shift;
1347  
1348 0 my $self = {};
1349
1350 0 bless $self, $class;
1351  
1352 0 return $self;
1353 }
1354
1355 sub bind #NOTE: BIND ARGS MUST APPEAR IN ORDER (ie. :1, :2, :3)!
1356 0 ▶{
Subroutine bind: not called CC=24 SCAR=64.0
1357 0 my ($mycsr, @bindvals) = @_;
1358 0 my ($t);
1359  
1360 0 $lastdb = $mycsr->{dB};
1361 0 my $fetchcnt = 0;
1362 0 my $cleansql = $mycsr->{cleansql};
1363 0 my $sqlstr = $mycsr->{sql};
1364 0 ▶ if ($mycsr->{dB}->{noplaceholders})
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{"dB"}{"noplaceholders"}) 0 0 0
1365 {
1366 0 ▶ $mycsr->{csr}->finish() if ($mycsr->{csr});
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->{"csr"} 0 0 0
1367 0 ▶ while (@bindvals)
Branch: 1 branch
BranchTrueFalseTotal
if (@bindvals) 0 0 0
1368 {
1369 0 $t = shift(@bindvals);
1370 0 $t =~ s/\'/\'\'/gs;
1371 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
1372 0 $sqlstr =~ s/\x02\^3jSpR1tE\x02/\'$t\'/s;
1373 }
1374 0 $mycsr->{csr} = $mycsr->{dB}->{DBI}->prepare($sqlstr);
1375 0 ▶ return undef unless ($mycsr->{csr});
Branch: 1 branch
BranchTrueFalseTotal
unless $mycsr->{"csr"} 0 0 0
1376 }
1377 0 my ($res) = $mycsr->{csr}->execute(@bindvals);
1378 0 ▶ return undef if ($mycsr->{csr}->err);
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->{"csr"}->err 0 0 0
1379 0 ▶ if ($mycsr->{select})
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{'select'}) { } 0 0 0
1380 {
1381 0 ▶ for (my $i=0;$i<=$mycsr->{varcnt};$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $mycsr->{"varcnt"}) 0 0 0
1382 {
1383 0 ${${$mycsr->{refsclrv}}[$i]} = '';
1384 0 @{${$mycsr->{reflistv}}[$i]} = ();
1385 }
1386 0 ▶ if ($mycsr->{varcnt} >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{"varcnt"} >= 0) 0 0 0
1387 {
1388 0 my (@myline);
1389 0 $fetchcnt = 0;
1390 0 ▶ while ((@myline) = $mycsr->{csr}->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->{"csr"}->fetchrow_array) 0 0 0
1391 {
1392 0 ▶ last if ($mycsr->{dB}->{DBI}->err > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->{"dB"}{"DBI"}->err > 0 0 0 0
1393 0 ▶ for (my $i=0;$i<=$mycsr->{varcnt};$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $mycsr->{"varcnt"}) 0 0 0
1394 {
1395 0 ▶ ${${$mycsr->{refsclrv}}[$i]} = $myline[$i] unless ($fetchcnt);
Branch: 1 branch
BranchTrueFalseTotal
unless $fetchcnt 0 0 0
1396 #CORRECTED ABOVE BUG 20001205 WHICHED RETURNED LAST RECORD (SHOULD BE 1ST)!
1397 0 push(@{${$mycsr->{reflistv}}[$i]},$myline[$i]);
1398  
1399 }
1400 0 ++$fetchcnt;
1401 };
1402 }
1403 }
1404 else #ADDED 20010228 TO LOG NON-SELECTS DONE W/BIND!
1405 {
1406 #NEXT 5 ADDED 20030922 TO MAKE SEQUENCE-RETRIEVAL DATABASE-INDEPENDENT.
1407 0 ▶ if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/sio)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/iso) 0 0 0
1408 {
1409 0 $mycsr->{dB}->{lastsequencetable} = $1;
1410 0 $mycsr->{dB}->{lastsequencename} = $2;
1411 }
1412 0 ▶ if ($mycsr->{dB}->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{"dB"}{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$mycsr->{"dB"}{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$mycsr->{"dB"}{"logfid"} or $logfid
$mycsr->{"dB"}{"logfid"} $logfid
Truth table0%0/3
A or B
A= $mycsr->{"dB"}{"logfid"}B= $logfid
ABresult
1X1
011
000
1413 {
1414 0 $sqlstr =~ s/\s+$//o;
1415 0 $sqlstr =~ s/^\s+//o;
1416 0 ▶ for (my $i=0;$i<=$#bindvals;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#bindvals) 0 0 0
1417 {
1418 0 $t = $bindvals[$i];
1419 0 $t =~ s/\'/\'\'/go;
1420 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
1421 0 $sqlstr =~ s/\x02\^3jSpR1tE\x02/\'$t\'/s;
1422 }
1423 0 ▶ $sqlstr .= ';' if ($mycsr->{$dB}->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->{$dB}{"addsemicolon"} 0 0 0
1424 $sqlstr =~ s/\&/\'\|\|\'\&\'\|\|\'/go
1425 0 ▶ if ($mycsr->{$dB}->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->{$dB}{"addsemicolon"} == 1 0 0 0
1426 0 ▶ if ($mycsr->{dB}->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{"dB"}{"logfid"}) 0 0 0
1427 {
1428 0 my $logfh = $mycsr->{dB}->{logfh}; #NEEDED FOR PERL TO COMPILE.
1429 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1430 0 print $logfh "$sqlstr\n";
1431 0 flock $logfh, 8; #UNLOCK.
1432 }
1433 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
1434 {
1435 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1436 0 print $logfh "$sqlstr\n";
1437 0 flock $logfh, 8; #UNLOCK.
1438 }
1439 }
1440 }
1441 0 ▶ if ($fetchcnt) #ADDED 20001205 TO FIX ERRONIOUS RESULT FROM ORACLE DBI::PROXY OF 250.
Branch: 2 branches
BranchTrueFalseTotal
if ($fetchcnt) { } 0 0 0
elsif ($res) { } 0 0 0
1442 {
1443 0 return $fetchcnt;
1444 }
1445 elsif ($res)
1446 {
1447 0 ▶ return $mycsr->{csr}->rows ? $mycsr->{csr}->rows : $res;
Branch: 1 branch
BranchTrueFalseTotal
$mycsr->{'csr'}->rows ? : 0 0 0
1448 }
1449 else
1450 {
1451 0 return $res;
1452 }
1453 }
1454  
1455 sub fetch
1456 0 ▶{
Subroutine fetch: not called CC=3 SCAR=24.8
1457 0 my $mycsr = shift;
1458  
1459 0 $lastdb = $mycsr->{dB};
1460 0 my @myline = $mycsr->{csr}->fetchrow_array();
1461 0 ▶ if ($mycsr->{select})
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr->{"select"}) 0 0 0
1462 {
1463 0 ▶ for (my $i=0;$i<=$mycsr->{varcnt};$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $mycsr->{"varcnt"}) 0 0 0
1464 {
1465 0 ${${$mycsr->{refsclrv}}[$i]} = $myline[$i];
1466 }
1467 }
1468 0 return @myline;
1469 }
1470  
1471 sub fetchall
1472 0 ▶{
Subroutine fetchall: not called CC=7 SCAR=40.3
1473 0 my $mycsr = shift;
1474  
1475 0 my ($myline, @res, $nores);
1476
1477 0 $lastdb = $mycsr->{dB};
1478 0 ▶ $nores = 1 unless (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
1479 0 my ($fetchcnt) = 0;
1480 0 ▶ while ((@myline) = $mycsr->{csr}->fetchrow_array())
Branch: 1 branch
BranchTrueFalseTotal
if (@myline = $mycsr->{"csr"}->fetchrow_array) 0 0 0
1481 {
1482 #THIS FOR-LOOP IS CURRENTLY DEPRECIATED BECAUSE FETCH WILL NOT RETURN VALUES IF VARCNT > 0 (THEY'VE ALREADY BEEN FETCHED BY BIND)!
1483 0 ▶ for (my $i=0;$i<=$mycsr->{varcnt};$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $mycsr->{"varcnt"}) 0 0 0
1484 {
1485 0 ▶ ${${$mycsr->{refsclrv}}[$i]} = $myline[$i] unless ($fetchcnt);
Branch: 1 branch
BranchTrueFalseTotal
unless $fetchcnt 0 0 0
1486 0 push (@{${$mycsr->{reflistv}}[$i]}, $myline[$i]);
1487 }
1488 0 ▶ push (@res, [@myline]) unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
1489 0 ++$fetchcnt;
1490 }
1491 0 ▶ return @res unless ($nores);
Branch: 1 branch
BranchTrueFalseTotal
unless $nores 0 0 0
1492 0 return $fetchcnt;
1493 }
1494  
1495 sub closecsr
1496 0 ▶{
Subroutine closecsr: not called CC=2 SCAR=17.9
1497 0 my $mycsr = shift;
1498  
1499 0 ▶ return undef unless ($mycsr->{csr});
Branch: 1 branch
BranchTrueFalseTotal
unless $mycsr->{"csr"} 0 0 0
1500 0 my $res = $mycsr->{csr}->finish();
1501 0 $mycsr->{csr} = undef;
1502 0 return $res;
1503 }
1504  
1505 package JDBIx;
1506  
1507 sub opencsr
1508 0 ▶{
Subroutine opencsr: not called CC=18 SCAR=58.3
Pod documented
1509 0 my ($self, $sqlstr, $xeqflag) = @_;
1510  
1511 0 $lastdb = $self;
1512  
1513 0 ▶ $sqlstr =~ s/\:\d+/\?/go unless ($xeqflag);
Branch: 1 branch
BranchTrueFalseTotal
unless $xeqflag 0 0 0
1514 0 my ($myres, $cleansql);
1515 0 my ($mycsr) = new JDBIx::csr();
1516
1517 0 $cleansql = $sqlstr;
1518 0 ▶ if ($sqlstr =~ /^\s*select\s/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /^\s*select\s/io) { } 0 0 0
1519 {
1520 0 $mycsr->{select} = 1;
1521 0 ▶ if ($sqlstr =~ /\binto\b/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /\binto\b/io) { } 0 0 0
1522 {
1523 0 my (@varlistv) = ($sqlstr =~ /:\D\w*/go);
1524 0 foreach $i (@varlistv)
1525 {
1526 0 $i =~s/\:/$self->{calling_package}\:\:/;
1527 0 $i =~s/,//o;
1528 0 @{$i} = (); #INITIALIZE TO CLEAR ANY OLD VALUES!
1529 0 ${$i} = '';
1530 0 push (@{$mycsr->{reflistv}},\@{$i});
1531 0 push (@{$mycsr->{refsclrv}},\${$i});
1532 }
1533 0 $mycsr->{varcnt} = $#varlistv;
1534 0 $cleansql =~ s/\binto\b//io;
1535 0 ▶ $nores = 1 unless (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
1536 0 $cleansql =~ s/\:[^\s\,\:]+\,?//go;
1537 }
1538 else
1539 {
1540 0 $mycsr->{varcnt} = -1;
1541 }
1542 }
1543 else
1544 {
1545 0 $mycsr->{select} = 0;
1546 }
1547 0 ▶ if ($self->{noplaceholders} && !$xeqflag)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'noplaceholders'} and not $xeqflag) { } 0 0 0
Condition0%0/3
$self->{"noplaceholders"} and not $xeqflag
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"noplaceholders"} and not $xeqflag
$self->{"noplaceholders"} not $xeqflag
Truth table0%0/3
A and not(B)
A= $self->{"noplaceholders"}B= not $xeqflag
ABresult
0X0
100
111
1548 {
1549 0 $cleansql =~ s/([\'\"])([^\1]*?)\1/
1550 0 my ($quote) = $1;
1551 0 my ($str) = $2;
1552 0 $str =~ s|\?|\x02\^2jSpR1tE\x02|go; #PROTECT ?'S IN QUOTES.
1553 0 "$quote$str$quote"
1554 /egs;
1555 0 $cleansql =~ s/\?/\x02\^3jSpR1tE\x02/gso; #PROTECT OTHER(BIND) ?'S
1556 0 $cleansql =~ s/\x02\^2jSpR1tE\x02/\?/gso; #UNPROTECT ?'S IN QUOTES.
1557 0 $mycsr->{sql} = $cleansql; #ADDED 20010228 FOR USE IN BIND.
1558 0 $mycsr->{cleansql} = $cleansql; #ADDED 20020715 FOR USE IN BIND.
1559 0 $mycsr->{cleansql} =~ s/\x02\^3jSpR1tE\x02/\?/gso;
1560 0 $mycsr->{dB} = $self; #ADDED 20010228 FOR USE IN BIND.
1561 }
1562 else
1563 {
1564 0 $mycsr->{cleansql} = $cleansql; #ADDED 20020715 FOR USE IN BIND.
1565 0 $mycsr->{dB} = $self; #ADDED 20010228 FOR USE IN BIND.
1566 0 $mycsr->{csr} = $self->{DBI}->prepare($cleansql);
1567 0 ▶ return undef unless (defined($mycsr->{csr}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mycsr->{"csr"} 0 0 0
1568
1569 0 ▶ if ($xeqflag && $mycsr->{csr})
Branch: 1 branch
BranchTrueFalseTotal
if ($xeqflag and $mycsr->{"csr"}) 0 0 0
Condition0%0/3
$xeqflag and $mycsr->{"csr"}
!ll&&!rl&&r
000
MC/DC0%0/2
$xeqflag and $mycsr->{"csr"}
$xeqflag $mycsr->{"csr"}
Truth table0%0/3
A and B
A= $xeqflagB= $mycsr->{"csr"}
ABresult
0X0
100
111
1570 {
1571 0 $myres = $mycsr->{csr}->execute();
1572 0 ▶ if ($self->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$self->{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfid"} or $logfid
$self->{"logfid"} $logfid
Truth table0%0/3
A or B
A= $self->{"logfid"}B= $logfid
ABresult
1X1
011
000
1573 {
1574 0 $cleansql =~ s/\s+$//o;
1575 0 $cleansql =~ s/^\s+//o;
1576 0 ▶ $cleansql .= ';' if ($self->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} 0 0 0
1577 0 ▶ $cleansql =~ s/\&/\'\|\|\'\&\'\|\|\'/go if ($self->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} == 1 0 0 0
1578 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
1579 {
1580 0 my $logfh = $self->{logfh}; #NEEDED FOR PERL TO COMPILE.
1581 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1582 0 print $logfh "$cleansql\n";
1583 0 flock $logfh, 8; #UNLOCK.
1584 }
1585 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
1586 {
1587 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1588 0 print $logfh "$cleansql\n";
1589 0 flock $logfh, 8; #UNLOCK.
1590 }
1591 }
1592 }
1593 0 $cleansql =~ s/\?/\x02\^3jSpR1tE\x02/gso; #PROTECT OTHER(BIND) ?'S
1594 0 $mycsr->{sql} = $cleansql; #ADDED 20010228 FOR USE IN BIND.
1595 }
1596 0 ▶ return wantarray ? ($mycsr, $myres) : $mycsr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1597 }
1598  
1599 sub do1
1600 0 ▶{
Subroutine do1: not called CC=29 SCAR=67.7
Pod documented
1601 0 my ($self, $sqlstr, @bindvals) = @_;
1602 0 my ($res, $t);
1603  
1604 0 local ($_);
1605 0 $lastdb = $self;
1606 0 ▶ $sqlstr =~ s/\:\d+/\?/go if ($#bindvals >= 0); #CONVERT LEGACY PLACEHOLDERS, IE. :1, :2, ETC.
Branch: 1 branch
BranchTrueFalseTotal
if $#bindvals >= 0 0 0 0
1607  
1608 0 ▶ if ($self->{dbtype} =~ /^odbc/io && $sqlstr =~ /insert.*\w+\.NEXTVAL/so)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so) { } 0 0 0
Condition0%0/3
$self->{"dbtype"} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dbtype"} =~ /^odbc/io and $sqlstr =~ /insert.*\w+\.NEXTVAL/so
$self->{"dbtype"} =~ /^odbc/io $sqlstr =~ /insert.*\w+\.NEXTVAL/so
Truth table0%0/3
A and B
A= $self->{"dbtype"} =~ /^odbc/ioB= $sqlstr =~ /insert.*\w+\.NEXTVAL/so
ABresult
0X0
100
111
1609 {
1610 0 $sqlstr = &_fixNEXTVAL($self, $sqlstr);
1611 }
1612 else
1613 {
1614 $sqlstr =~ s/([\,\(]\s*)\w+\.NEXTVAL(\s*[\,\)])/$1NULL$2/g
1615 0 ▶ if ($self->{dbtype} =~ /^mysql/o); #MYSQL DOES SEQUENCES DIFFERENTLY (see AUTO_INCREMENT)!
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbtype"} =~ /^mysql/o 0 0 0
1616 }
1617 #ADDED 20030904 TO MAKE SEQUENCE-RETRIEVAL DATABASE-INDEPENDENT.
1618 0 ▶ if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/sio)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /insert\s+into\s+(\w+).*?(\w+)\.NEXTVAL/iso) 0 0 0
1619 {
1620 0 $self->{lastsequencetable} = $1;
1621 0 $self->{lastsequencename} = $2;
1622 }
1623 0 ▶ if ($self->{noplaceholders})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"noplaceholders"}) 0 0 0
1624 {
1625 0 $sqlstr =~ s/([\'\"])([^\1]*?)\1/
1626 0 my ($quote) = $1;
1627 0 my ($str) = $2;
1628 0 $str =~ s|\?|\x02\^2jSpR1tE\x02|go; #PROTECT ?'S IN QUOTES.
1629 0 "$quote$str$quote"
1630 /egs;
1631 0 ▶ while (@bindvals)
Branch: 1 branch
BranchTrueFalseTotal
if (@bindvals) 0 0 0
1632 {
1633 0 $t = shift(@bindvals);
1634 0 $t =~ s/\'/\'\'/so;
1635 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
1636 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
1637 0 $sqlstr =~ s/\?/\'$t\'/s;
1638 }
1639 0 $sqlstr =~ s/\x02\^2jSpR1tE\x02/\?/gso; #UNPROTECT ?'S.
1640 }
1641 0 my ($mycsr) = $self->{DBI}->prepare($sqlstr);
1642 0 ▶ if ($mycsr)
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr) 0 0 0
1643 {
1644 #if ($sqlstr =~ /^\s+select/i) #CHGD TO NEXT 20011121!
1645 0 ▶ if ($sqlstr =~ /^\s*select/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /^\s*select/io) { } 0 0 0
1646 {
1647 0 $res = $mycsr->execute(@bindvals); #bindvals ADDED HERE 20000217.
1648 0 ▶ return undef unless(defined($res));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
1649 0 ▶ $res = $mycsr->rows if ($res && $mycsr->rows);
Branch: 1 branch
BranchTrueFalseTotal
if $res and $mycsr->rows 0 0 0
Condition0%0/3
$res and $mycsr->rows
!ll&&!rl&&r
000
MC/DC0%0/2
$res and $mycsr->rows
$res $mycsr->rows
Truth table0%0/3
A and B
A= $resB= $mycsr->rows
ABresult
0X0
100
111
1650 0 ▶ if ($res > 0 || $res eq '0E0')
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0 or $res eq "0E0") 0 0 0
Condition0%0/3
$res > 0 or $res eq "0E0"
l!l&&r!l&&!r
000
MC/DC0%0/2
$res > 0 or $res eq "0E0"
$res > 0 $res eq "0E0"
Truth table0%0/3
A or B
A= $res > 0B= $res eq "0E0"
ABresult
1X1
011
000
1651 {
1652 0 @myline = $mycsr->fetchrow_array();
1653 0 $mycsr->finish();
1654 0 ▶ return wantarray ? ($res, @myline) : $res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1655 }
1656 }
1657 else
1658 {
1659 0 $res = $mycsr->execute(@bindvals);
1660 0 ▶ return undef unless(defined($res));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
1661 0 ▶ if ($self->{logfid} || $logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"} or $logfid) 0 0 0
Condition0%0/3
$self->{"logfid"} or $logfid
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"logfid"} or $logfid
$self->{"logfid"} $logfid
Truth table0%0/3
A or B
A= $self->{"logfid"}B= $logfid
ABresult
1X1
011
000
1662 {
1663 0 $sqlstr =~ s/\s+$//o;
1664 0 $sqlstr =~ s/^\s+//o;
1665 0 ▶ if ($#bindvals >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#bindvals >= 0) 0 0 0
1666 {
1667 0 $sqlstr =~ s/([\'\"])([^\1]*?)\1/
1668 0 my ($quote) = $1;
1669 0 my ($str) = $2;
1670 0 $str =~ s|\?|\x02\^2jSpR1tE\x02|go; #PROTECT ?'S IN QUOTES.
1671 0 "$quote$str$quote"
1672 /egs;
1673  
1674 0 ▶ for (my $i=0;$i<=$#bindvals;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#bindvals) 0 0 0
1675 {
1676 0 $t = $bindvals[$i];
1677 0 $t =~ s/\'/\'\'/go;
1678 0 $t =~ s/\?/\x02\^2jSpR1tE\x02/gso;
1679 0 $sqlstr =~ s/\?/\'$t\'/;
1680 }
1681 0 $sqlstr =~ s/\x02\^2jSpR1tE\x02/\?/gso; #UNPROTECT ?'S.
1682 }
1683 0 ▶ $sqlstr .= ';' if ($self->{addsemicolon});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} 0 0 0
1684 0 ▶ $sqlstr =~ s/\&/\'\|\|\'\&\'\|\|\'/go if ($self->{addsemicolon} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"addsemicolon"} == 1 0 0 0
1685 0 ▶ if ($self->{logfid})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logfid"}) 0 0 0
1686 {
1687 0 my $logfh = $self->{logfh}; #NEEDED FOR PERL TO COMPILE.
1688 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1689 0 print $logfh "$sqlstr\n";
1690 0 flock $logfh, 8; #UNLOCK.
1691 }
1692 0 ▶ if ($logfid)
Branch: 1 branch
BranchTrueFalseTotal
if ($logfid) 0 0 0
1693 {
1694 0 flock $logfh, 2; #EXCLUSIVE LOCK.
1695 0 print $logfh "$sqlstr\n";
1696 0 flock $logfh, 8; #UNLOCK.
1697 }
1698 }
1699 0 ▶ if ($res > 0 || $res eq '0E0')
Branch: 1 branch
BranchTrueFalseTotal
if ($res > 0 or $res eq "0E0") 0 0 0
Condition0%0/3
$res > 0 or $res eq "0E0"
l!l&&r!l&&!r
000
MC/DC0%0/2
$res > 0 or $res eq "0E0"
$res > 0 $res eq "0E0"
Truth table0%0/3
A or B
A= $res > 0B= $res eq "0E0"
ABresult
1X1
011
000
1700 {
1701 0 ▶ $res = $mycsr->rows if ($mycsr->rows);
Branch: 1 branch
BranchTrueFalseTotal
if $mycsr->rows 0 0 0
1702 0 $mycsr->finish();
1703 0 ▶ return wantarray ? ($res) : $res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1704 }
1705 }
1706 0 $mycsr->finish();
1707 }
1708 0 return undef;
1709 }
1710  
1711 sub fetchseq #ADDED 20030904 TO MAKE SEQUENCE-RETRIEVAL DATABASE-INDEPENDENT.
1712 0 ▶{
Subroutine fetchseq: not called CC=17 SCAR=57.2
Pod documented
1713 0 my $self = shift;
1714 0 my $seqfield = shift;
1715 0 ▶ my $seqname = shift || $self->{lastsequencename};
Condition0%0/3
shift() || $self->{'lastsequencename'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'lastsequencename'}
shift() $self->{'lastsequencename'}
Truth table0%0/3
A || B
A= shift()B= $self->{'lastsequencename'}
ABresult
1X1
011
000
1716 0 ▶ my $tablename = shift || $self->{lastsequencetable};
Condition0%0/3
shift() || $self->{'lastsequencetable'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->{'lastsequencetable'}
shift() $self->{'lastsequencetable'}
Truth table0%0/3
A || B
A= shift()B= $self->{'lastsequencetable'}
ABresult
1X1
011
000
1717  
1718 #ADD CODE FOR YOUR FAVORITE DATABASE HERE, OR TAKE THE DEFAULT (LAST OPTION)!
1719  
1720 return $self->{DBI}->{sprite_insertid}
1721 if ($self->{dbtype} eq 'Sprite' && defined($self->{DBI}->{sprite_insertid})
1722 0 ▶ && $self->{DBI}->{sprite_insertid} =~ /\d/o);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbtype"} eq "Sprite" and defined $self->{"DBI"}{"sprite_insertid"} and $self->{"DBI"}{"sprite_insertid"} =~ /\d/o 0 0 0
Condition0%0/6
$self->{"dbtype"} eq "Sprite" and defined $self->{"DBI"}{"sprite_insertid"} and $self->{"DBI"}{"sprite_insertid"} =~ /\d/o
!ll&&!rl&&r
000
$self->{"dbtype"} eq "Sprite" and defined $self->{"DBI"}{"sprite_insertid"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"dbtype"} eq "Sprite" and defined $self->{"DBI"}{"sprite_insertid"} and $self->{"DBI"}{"sprite_insertid"} =~ /\d/o
$self->{"dbtype"} eq "Sprite" defined $self->{"DBI"}{"sprite_insertid"} $self->{"DBI"}{"sprite_insertid"} =~ /\d/o
Truth table0%0/4
A and B and C
A= $self->{"dbtype"} eq "Sprite"B= defined $self->{"DBI"}{"sprite_insertid"}C= $self->{"DBI"}{"sprite_insertid"} =~ /\d/o
ABCresult
0XX0
10X0
1100
1111
1723 0 ▶ if ($self->{dbtype} =~ /^(?:Oracle|Sprite)/o)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /^(?:Oracle|Sprite)/o) { } 0 0 0
elsif ($self->{'dbtype'} =~ /^mysql/o) { } 0 0 0
elsif ($self->{'dbtype'} =~ /^SQLite/o) { } 0 0 0
1724 {
1725 0 my $mycsr;
1726 0 ▶ if ($mycsr = $self->{DBI}->prepare("select $seqname.CURRVAL from DUAL"))
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr = $self->{"DBI"}->prepare("select $seqname.CURRVAL from DUAL")) 0 0 0
1727 {
1728 0 my $myexe;
1729 0 ▶ if ($myexe = $mycsr->execute())
Branch: 1 branch
BranchTrueFalseTotal
if ($myexe = $mycsr->execute) 0 0 0
1730 {
1731 0 ($lastseq) = $mycsr->fetchrow_array();
1732 0 $mycsr->finish();
1733 0 ▶ return $lastseq if ($lastseq =~ /\d/o);
Branch: 1 branch
BranchTrueFalseTotal
if $lastseq =~ /\d/o 0 0 0
1734 }
1735 }
1736 }
1737 elsif ($self->{dbtype} =~ /^mysql/o)
1738 {
1739 0 ▶ return $self->{DBI}->{mysql_insert_id} if (defined $self->{DBI}->{mysql_insert_id} && $self->{DBI}->{mysql_insert_id} =~ /\d/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/ 0 0 0
Condition0%0/3
defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
defined $self->{"DBI"}{"mysql_insert_id"} $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
Truth table0%0/3
A and B
A= defined $self->{"DBI"}{"mysql_insert_id"}B= $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
ABresult
0X0
100
111
1740 }
1741 elsif ($self->{dbtype} =~ /^SQLite/o)
1742 {
1743 0 return $self->{DBI}->sqlite_last_insert_rowid();
1744 }
1745 0 ▶ if ($seqfield) #IF ALL ELSE FAILS, FETCH A DESCENDING LIST OF VALUES FOR THE FIELD THE SEQUENCE WAS INSERTED INTO (USER MUST SPECIFY THE FIELD!)
Branch: 1 branch
BranchTrueFalseTotal
if ($seqfield) 0 0 0
1746 {
1747 0 my $sql = <<END_SQL;
1748 select $seqfield
1749 from $tablename
1750 order by $seqfield desc
1751 END_SQL
1752 0 ▶ if ($mycsr = $self->{DBI}->prepare($sql))
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr = $self->{"DBI"}->prepare($sql)) 0 0 0
1753 {
1754 0 my $myexe;
1755 0 ▶ if ($myexe = $mycsr->execute())
Branch: 1 branch
BranchTrueFalseTotal
if ($myexe = $mycsr->execute) 0 0 0
1756 {
1757 0 ($lastseq) = $mycsr->fetchrow_array();
1758 0 $mycsr->finish();
1759 0 return $lastseq;
1760 }
1761 }
1762 0 return undef;
1763 }
1764 0 return undef;
1765 }
1766  
1767 sub fetchnextseq
1768 0 ▶{
Subroutine fetchnextseq: not called CC=15 SCAR=54.8
Pod documented
1769 0 my $self = shift;
1770 0 ▶ my $seqname = shift || '.dbixseq';
Condition0%0/2
shift() || '.dbixseq'
l!l
00
MC/DC0%0/1
shift() || '.dbixseq'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1771  
1772 #ADD CODE FOR YOUR FAVORITE DATABASE HERE, OR TAKE THE DEFAULT (LAST OPTION)!
1773  
1774 0 ▶ if ($self->{dbtype} =~ /^(?:Oracle|Sprite)/o)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'dbtype'} =~ /^(?:Oracle|Sprite)/o) { } 0 0 0
elsif ($self->{'dbtype'} =~ /^mysql/o) { } 0 0 0
elsif ($self->{'dbtype'} =~ /^SQLite/o) { } 0 0 0
1775 {
1776 0 my $mycsr;
1777 0 ▶ if ($mycsr = $self->{DBI}->prepare("select $seqname.NEXTVAL from DUAL"))
Branch: 1 branch
BranchTrueFalseTotal
if ($mycsr = $self->{"DBI"}->prepare("select $seqname.NEXTVAL from DUAL")) 0 0 0
1778 {
1779 0 my $myexe;
1780 0 ▶ if ($myexe = $mycsr->execute())
Branch: 1 branch
BranchTrueFalseTotal
if ($myexe = $mycsr->execute) 0 0 0
1781 {
1782 0 ($lastseq) = $mycsr->fetchrow_array();
1783 0 $mycsr->finish();
1784 0 ▶ return $lastseq if ($lastseq =~ /\d/o);
Branch: 1 branch
BranchTrueFalseTotal
if $lastseq =~ /\d/o 0 0 0
1785 }
1786 }
1787 }
1788 elsif ($self->{dbtype} =~ /^mysql/o)
1789 {
1790 0 ▶ return $self->{DBI}->{mysql_insert_id} if (defined $self->{DBI}->{mysql_insert_id} && $self->{DBI}->{mysql_insert_id} =~ /\d/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/ 0 0 0
Condition0%0/3
defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"DBI"}{"mysql_insert_id"} and $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
defined $self->{"DBI"}{"mysql_insert_id"} $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
Truth table0%0/3
A and B
A= defined $self->{"DBI"}{"mysql_insert_id"}B= $self->{"DBI"}{"mysql_insert_id"} =~ /\d/
ABresult
0X0
100
111
1791 }
1792 elsif ($self->{dbtype} =~ /^SQLite/o)
1793 {
1794 0 return $self->{DBI}->sqlite_last_insert_rowid();
1795 }
1796  
1797 #IF ALL ELSE FAILS, USE OUR OWN SPECIAL SEQUENCE FILE!
1798  
1799 0 my $seq_file = $ENV{HOME};
1800 0 ▶ $seq_file .= '/' unless ($seq_file =~ m#\/$#o);
Branch: 1 branch
BranchTrueFalseTotal
unless $seq_file =~ m[\/$]o 0 0 0
1801 0 ▶ $seq_file = '' if ($seq_file eq '/');
Branch: 1 branch
BranchTrueFalseTotal
if $seq_file eq "/" 0 0 0
1802 0 $seq_file .= $seqname;
1803 0 ▶ if (open(T, "<$seq_file"))
Branch: 1 branch
BranchTrueFalseTotal
if (open T, "<$seq_file") { } 0 0 0
1804 {
1805 0 my $x = <T>;
1806 0 chomp($x);
1807 0 my ($seqval, $seqincby) = split(/\,/o, $x);
1808 0 close (T);
1809 }
1810 else
1811 {
1812 0 $seqval = 0;
1813 0 $seqincby = 1;
1814 }
1815 0 ▶ if (open (T, ">$seq_file"))
Branch: 1 branch
BranchTrueFalseTotal
if (open T, ">$seq_file") { } 0 0 0
1816 {
1817 0 ▶ $seqval += ($seqincby || 1);
Condition0%0/2
$seqincby || 1
l!l
00
MC/DC0%0/1
$seqincby || 1
$seqincby
Truth table0%0/2
A
A= $seqincby
Aresult
11
00
1818 0 print T "$seqval,$seqincby\n";
1819 0 close (T);
1820 0 return $seqval;
1821 }
1822 else
1823 {
1824 0 $lasterr = "$@/$? (file:$seq_file)";
1825 }
1826 0 return undef;
1827 }
1828  
1829 sub _fixNEXTVAL
1830 0 ▶{
Subroutine _fixNEXTVAL: not called CC=5 SCAR=34.0
1831 0 my ($self, $sqlstr) = @_;
1832  
1833 0 ▶ if ($sqlstr =~ /^\s*insert\s+into\s+ # Keyword
Branch: 1 branch
BranchTrueFalseTotal
if ($sqlstr =~ /^\s*insert\s+into\s+ # Keyword (\S+)\s* # Table (?:\((.+?)\)\s*)? # Keys values\s* # 'values' \((.+)\)\s*$/iosx) 0 0 0
1834 (\S+)\s* # Table
1835 (?:\((.+?)\)\s*)? # Keys
1836 values\s* # 'values'
1837 \((.+)\)\s*$/isxo)
1838 {
1839 0 my ($table, $columns, $values) = ($1, $2, $3);
1840 0 my ($origvalues) = $values;
1841
1842 0 $columns =~ s/\s//go;
1843 0 ▶ unless ($columns =~ /\S/o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($columns =~ /\S/o) 0 0 0
1844 {
1845 0 my $csr = $self->{DBI}->prepare("select * from $table");
1846 0 $csr->execute();
1847 0 $columns = join(',', @{$csr->{NAME}});
1848 0 $csr->finish();
1849 }
1850 0 my (@columns) = split(/,/o, $columns);
1851 0 $columns = '';
1852 0 $values =~ s/\\\\/\x02/go; #PROTECT "\\"
1853 0 $values =~ s/\\\'/\x03/go; #PROTECT "", \", '', AND \'.
1854
1855 0 $values =~ s/\'(.*?)\'/
1856 0 my ($j)=$1;
1857 0 $j =~ s|,|\x04|go; #PROTECT "," IN QUOTES.
1858 0 "'$j'"
1859 /eg;
1860
1861 0 @values = split(/,/,$values);
1862 0 for $i (0..$#values)
1863 {
1864 0 $values[$i] =~ s/^\s+//o; #STRIP LEADING & TRAILING SPACES.
1865 0 $values[$i] =~ s/\s+$//o;
1866 0 $values[$i] =~ s/\x03/\'\'/go; #RESTORE PROTECTED SINGLE QUOTES HERE.
1867 0 $values[$i] =~ s/\x02/\\/go; #RESTORE PROTECTED SINGLE QUOTES HERE.
1868 0 $values[$i] =~ s/\x04/,/go; #RESTORE PROTECTED SINGLE QUOTES HERE.
1869 0 ▶ if ($values[$i] =~ /\s*(\w+).NEXTVAL\s*$/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($values[$i] =~ /\s*(\w+).NEXTVAL\s*$/o) { } 0 0 0
1870 {
1871 0 my ($t) = $1;
1872 0 $origvalues =~ s/\s*$t\.NEXTVAL\s*\,?\s*//;
1873 }
1874 else
1875 {
1876 0 $columns .= $columns[$i] . ',';
1877 }
1878 };
1879 0 chop ($columns);
1880
1881 0 $sqlstr = "insert into $table ($columns) values ($origvalues) ";
1882 }
1883 0 return ($sqlstr);
1884 }
1885  
1886 2 1
1887  
1888 __END__
↑ Summary