JLdap.pm

filter: Statementstmt 1.7% 12 / 690 Branchbran 0.0% 0 / 310 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 11.1% 3 / 27 Podpod 0.0% 0 / 24 totaltotal 1.3% 15 / 1134 CC 190 SCAR 65.9
CC
190
Cov
1%
select
1640.0
update
1482.0
parse_expression
650.0
CRAP 724.9
↑ Summary DBD/LDAP.pm »
1 #!/usr/bin/perl
2  
3 package JLdap;
4  
5 1 require 5.002;
6  
7 1 ▶use Net::LDAP::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶no warnings qw (uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #use Fcntl;
11  
12 ##++
13 ## Global Variables. Declare lock constants manually, instead of
14 ## importing them from Fcntl.
15 ##
16 1 ▶use vars qw ($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 ##--
18  
19 1 $JLdap::VERSION = '1.00';
20  
21 #my $NUMERICTYPES = '^(NUMBER|FLOAT|DOUBLE|INT|INTEGER|NUM)$'; #20000224
22 #my $STRINGTYPES = '^(VARCHAR|CHAR|VARCHAR|DATE|LONG|BLOB|MEMO)$';
23  
24 ##++
25 ## Public Methods and Constructor
26 ##--
27  
28 sub new
29 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $class = shift;
31 0 my $self;
32  
33 0 $self = {
34 commands => 'select|update|delete|alter|insert|create|drop|primary_key_info',
35 column => '[A-Za-z0-9\~\x80-\xFF][\w\x80-\xFF]+',
36 _select => '[\w\x80-\xFF\*,\s\~]+',
37 path => '[\w\x80-\xFF\-\/\.\:\~\\\\]+',
38 table => '',
39 timestamp => 0,
40 fields => {},
41 use_fields => '',
42 key_fields => '',
43 order => [],
44 types => {},
45 lengths => {},
46 scales => {},
47 defaults => {},
48 records => [],
49 errors => {},
50 lasterror => 0, #JWT: ADDED FOR ERROR-CONTROL
51 lastmsg => '',
52 CaseTableNames => 0, #JWT: 19990991 TABLE-NAME CASE-SENSITIVITY?
53 LongTruncOk => 0, #JWT: 19991104: ERROR OR NOT IF TRUNCATION.
54 RaiseError => 0, #JWT: 20000114: ADDED DBI RAISEERROR HANDLING.
55 silent => 0,
56 ldap_dbh => 0,
57 ldap_sizelimit => 0, #JWT: LIMIT #RECORDS FETCHED, IF SET.
58 ldap_timelimit => 0, #JWT: LIMIT #RECORDS FETCHED, IF SET.
59 ldap_deref => 0, #JWT: LIMIT #RECORDS FETCHED, IF SET.
60 ldap_typesonly => 0,
61 ldap_callback => 0,
62 ldap_scope => 0,
63 ldap_inseparator => '|',
64 ldap_outseparator => '|',
65 ldap_firstonly => 0,
66 ldap_nullsearchvalue => ' ', #ADDED 20040330 TO FOR BACKWARD COMPATABILITY.
67 ldap_appendbase2ins => 0, #ADDED 20060719 FOR BACKWARD COMPAT. - 0.08+ NO LONGER APPENDS BASE TO ALWAYSINSERT PER REQUEST.
68 dirty => 0, #JWT: 20000229: PREVENT NEEDLESS RECOMMITS.
69 tindx => 0 #REPLACES GLOBAL VARIABLE.
70 };
71  
72 0 bless $self, $class;
73  
74 0 ▶ for (my $i=0;$i<scalar(@_);$i+=2) #ADDED: 20040330 TO ALLOW SETTING ATTRIBUTES IN INITIALIZATION!
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
75 {
76 0 $self->{$_[$i]} = $_[$i+1];
77 }
78  
79 0 $self->initialize;
80 0 return $self;
81 }
82 sub initialize
83 0 ▶{
Subroutine initialize: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my $self = shift;
85  
86 0 $self->define_errors;
87 }
88  
89 sub sql
90 0 ▶{
Subroutine sql: not called CC=14 SCAR=53.5
Pod undocumented
91 0 my ($self, $csr, $query) = @_;
92  
93 0 my ($command, $status, $base, $fields);
94 #print STDERR "-sql1($command,$status,$base,$fields)";
95 0 ▶ return wantarray ? () : -514 unless ($query);
Branch: 2 branches
BranchTrueFalseTotal
unless $query 0 0 0
wantarray ? : 0 0 0
96 0 $self->{lasterror} = 0;
97 0 $self->{lastmsg} = '';
98 0 $query =~ s/\n/ /gso;
99 0 $query =~ s/^\s*(.*?)\s*$/$1/;
100 0 ▶ $query = 'select tables' if ($query =~ /^show\s+tables$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /^show\s+tables$/i 0 0 0
101 0 ▶ $query = 'select tables' if ($query =~ /^select\s+TABLE_NAME\s+from\s+USER_TABLES$/i); #ORACLE-COMPATABILITY.
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /^select\s+TABLE_NAME\s+from\s+USER_TABLES$/i 0 0 0
102 0 $command = '';
103  
104 0 ▶ if ($query =~ /^($self->{commands})/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^($self->{'commands'})/io) { } 0 0 0
105 {
106 0 $command = $1;
107 0 $command =~ tr/A-Z/a-z/; #ADDED 19991202!
108 0 $status = $self->$command ($csr, $query);
109 0 ▶ if (!defined($status)) #NEXT 5 ADDED PER PATCH REQUEST 20091101:
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $status) { } 0 0 0
elsif (ref $status eq 'ARRAY') { } 0 0 0
110 {
111 0 $self->display_error(-599);
112 0 ▶ return wantarray ? () : -599;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
113 }
114 elsif (ref ($status) eq 'ARRAY') #SELECT RETURNED OK (LIST OF RECORDS).
115 {
116 0 ▶ return wantarray ? @$status : $status;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
117 }
118 else
119 {
120 0 ▶ if ($status < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($status < 0) { } 0 0 0
121 { #SQL RETURNED AN ERROR!
122 #print STDERR "-sql6 status=$status=\n";
123 0 $self->display_error ($status);
124 #return ($status);
125 0 ▶ return wantarray ? () : $status;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
126 }
127 else
128 { #SQL RETURNED OK.
129 #print STDERR "-sql7 status=$status= at=$@= cash=$_= bang=$!= query=$?=\n";
130 0 ▶ return wantarray ? ($status) : $status;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
131 }
132 }
133 }
134 else
135 {
136 0 ▶ return wantarray ? () : -514;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
137 }
138 }
139  
140 sub select
141 0 ▶{
Subroutine select: not called CC=40 SCAR=74.0
Pod undocumented
142 0 my ($self, $csr, $query) = @_;
143  
144 0 my (@ordercols) = ();
145 0 $regex = $self->{_select};
146 0 $path = $self->{path};
147 0 my (@rtnvals) = ();
148  
149 0 my $distinct;
150 0 ▶ $distinct = 1 if ($query =~ s/select\s+distinct(\s+\w|\s*\(|\s+\*)/select $1/i);
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ s/select\s+distinct(\s+\w|\s*\(|\s+\*)/select $1/i 0 0 0
151 0 my ($dbh) = $csr->FETCH('ldap_dbh');
152 0 my ($tablehash);
153  
154 0 ▶ if ($query =~ /^select tables$/io)
Branch: 2 branches
BranchTrueFalseTotal
if ($query =~ /^select tables$/io) { } 0 0 0
elsif ($query =~ /^select\s+ # Keyword ($regex)\s+ # Columns from\s+ # 'from' ($path)(.*)$/iox) { } 0 0 0
155 {
156 0 $tablehash = $dbh->FETCH('ldap_tablenames');
157 0 $self->{use_fields} = 'TABLE_NAME'; #ADDED 20000224 FOR DBI!
158 0 $values_or_error = [];
159 0 ▶ for ($i=0;$i<=$#{$tablehash};$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$tablehash;}) 0 0 0
160 {
161 0 push (@$values_or_error,[$tablehash->[$i]]);
162 }
163 0 unshift (@$values_or_error, ($#{$tablehash}+1));
164 0 return $values_or_error;
165 }
166 elsif ($query =~ /^select\s+ # Keyword
167 ($regex)\s+ # Columns
168 from\s+ # 'from'
169 ($path)(.*)$/iox)
170 {
171 0 ($attbs, $table, $extra) = ($1, $2, $3);
172  
173 0 ▶ $table =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
174 0 $self->{file} = $table;
175 0 ▶ if ($extra =~ s/([\s|\)]+)order\s+by\s*(.*)/$1/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($extra =~ s/([\s|\)]+)order\s+by\s*(.*)/$1/i) 0 0 0
176 {
177 0 $orderclause = $2;
178 0 @ordercols = split(/,/,$orderclause);
179 0 $descorder = ($ordercols[$#ordercols] =~ s/(\w+\W+)desc(?:end|ending)?$/$1/i); #MODIFIED 20000721 TO ALLOW "desc|descend|descending"!
180 0 for $i (0..$#ordercols)
181 {
182 0 $ordercols[$i] =~ s/\s//igo; #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
183 0 $ordercols[$i] =~ s/[\(\)]+//igo;
184 }
185 }
186 0 $tablehash = $dbh->FETCH('ldap_tables');
187 0 ▶ return (-524) unless ($tablehash->{$table});
Branch: 1 branch
BranchTrueFalseTotal
unless $tablehash->{$table} 0 0 0
188  
189 0 my ($base, $objfilter, $dnattbs, $allattbs, $alwaysinsert) = split(/\:/o ,$tablehash->{$table});
190 0 ▶ $attbs = $allattbs if ($allattbs && $attbs =~ s/\*//o);
Branch: 1 branch
BranchTrueFalseTotal
if $allattbs and $attbs =~ s/\*//o 0 0 0
Condition0%0/3
$allattbs and $attbs =~ s/\*//o
!ll&&!rl&&r
000
MC/DC0%0/2
$allattbs and $attbs =~ s/\*//o
$allattbs $attbs =~ s/\*//o
Truth table0%0/3
A and B
A= $allattbsB= $attbs =~ s/\*//o
ABresult
0X0
100
111
191 0 $attbs =~ s/\s//go;
192 0 $attbs =~ tr/A-Z/a-z/;
193 0 ▶ @{$self->{order}} = split(/,/o, $attbs) unless ($attbs eq '*');
Branch: 1 branch
BranchTrueFalseTotal
unless $attbs eq "*" 0 0 0
194 0 my $fieldnamehash = ();
195 0 my $attbcnt = 0;
196 0 foreach my $i (@{$self->{order}})
197 {
198 0 $fieldnamehash{$i} = $attbcnt++;
199 }
200 0 my ($ldap) = $csr->FETCH('ldap_ldap');
201 0 ▶ $objfilter ||= 'objectclass=*';
Condition0%0/2
$objfilter ||= "objectclass=*"
l!l
00
MC/DC0%0/1
$objfilter ||= "objectclass=*"
$objfilter
Truth table0%0/2
A
A= $objfilter
Aresult
11
00
202 0 ▶ $objfilter = "($objfilter)" unless ($objfilter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $objfilter =~ /^\(/o 0 0 0
203 #print "<BR>-where=$extra=\n";
204 0 ▶ if ($extra =~ /^\s+where\s*(.+)$/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($extra =~ /^\s+where\s*(.+)$/io) { } 0 0 0
205 {
206 0 $filter = $self->parse_expression($1);
207 0 ▶ $filter = '('.$filter.')' unless ($filter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $filter =~ /^\(/o 0 0 0
208 0 $filter = "(&$objfilter$filter)";
209 }
210 else
211 {
212 0 $filter = $objfilter;
213 }
214 #print "<BR>-filter =$filter=\n";
215 0 my $data;
216 0 my (@searchops) = (
217 'base' => $base,
218 'filter' => $filter,
219 'attrs' => [split(/\,/o, $attbs)]
220 );
221 0 foreach my $i (qw(ldap_sizelimit ldap_timelimit deref typesonly
222 callback))
223 {
224 0 $j = $i;
225 0 $j =~ s/^ldap_//o;
226 0 ▶ push (@searchops, ($j, $self->{$i})) if ($self->{$i});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$i} 0 0 0
227 }
228 0 ▶ push (@searchops, ('scope', ($self->{ldap_scope} || 'one')));
Condition0%0/2
$self->{'ldap_scope'} || 'one'
l!l
00
MC/DC0%0/1
$self->{'ldap_scope'} || 'one'
$self->{'ldap_scope'}
Truth table0%0/2
A
A= $self->{'ldap_scope'}
Aresult
11
00
229 #print "--- ATTBS =$attbs=\n";
230 #print "--- SEARCH OPS =".join('|',@searchops)."=\n";
231 0 ▶ $data = $ldap->search(@searchops)
Branch: 1 branch
BranchTrueFalseTotal
$data = $ldap->search(@searchops) or return $self->ldap_error($@, "Search failed to return object: filter=$filter (" . $data->error . ')') 0 0 0
232 or return($self->ldap_error($@,"Search failed to return object: filter=$filter (".$data->error().")"));
233 #print "--- data=$data=\n";
234 0 my ($j) = 0;
235 0 my (@varlist) = ();
236 0 ▶ while (my $entry = $data->shift_entry())
Branch: 1 branch
BranchTrueFalseTotal
if (my $entry = $data->shift_entry) 0 0 0
237 {
238 0 $dn = $entry->dn();
239 0 ▶ next unless ($dn =~ /$base$/i); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
Branch: 1 branch
BranchTrueFalseTotal
unless $dn =~ /$base$/i 0 0 0
240 0 @attributes = $entry->attributes;
241 0 ▶ unless ($attbcnt)
Branch: 1 branch
BranchTrueFalseTotal
unless ($attbcnt) 0 0 0
242 {
243 0 $attbs = join(',',@attributes);
244 0 $attbcnt = 0;
245 0 @{$self->{order}} = @attributes;
246 0 foreach my $i (@{$self->{order}})
247 {
248 0 $fieldnamehash{$i} = $attbcnt++;
249 }
250 }
251 0 $varlist[$j] = [];
252 0 ▶ for (my $i=0;$i<$attbcnt;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $attbcnt) 0 0 0
253 {
254 0 $varlist[$j][$i] = '';
255 }
256 0 $i = 0;
257 0 foreach my $attr (@{$self->{order}})
258 {
259 # $valuesref = $entry->get($attr); #CHGD. TO NEXT PER PATCH REQUEST 20091101:
260 0 $valuesref = $entry->get_value($attr, asref => 1);
261 0 ▶ if ($self->{ldap_firstonly} && $self->{ldap_firstonly} <= scalar (@{$valuesref}))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ldap_firstonly'} and $self->{'ldap_firstonly'} <= scalar @{$valuesref;}) { } 0 0 0
Condition0%0/3
$self->{"ldap_firstonly"} and $self->{"ldap_firstonly"} <= scalar @{$valuesref;}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"ldap_firstonly"} and $self->{"ldap_firstonly"} <= scalar @{$valuesref;}
$self->{"ldap_firstonly"} $self->{"ldap_firstonly"} <= scalar @{$valuesref;}
Truth table0%0/3
A and B
A= $self->{"ldap_firstonly"}B= $self->{"ldap_firstonly"} <= scalar @{$valuesref;}
ABresult
0X0
100
111
262 {
263 #$varlist[$j][$fieldnamehash{$attr}] = join($self->{ldap_outseparator}, $valuesref->[0]); #CHGD. 20010829 TO NEXT.
264 0 $varlist[$j][$fieldnamehash{$attr}] = join($self->{ldap_outseparator}, @{$valuesref}[0..($self->{ldap_firstonly}-1)]);
265 }
266 else
267 {
268 0 ▶ $varlist[$j][$fieldnamehash{$attr}] = join($self->{ldap_outseparator}, @$valuesref) || '';
Condition0%0/2
join($self->{'ldap_outseparator'}, @$valuesref) || ''
l!l
00
MC/DC0%0/1
join($self->{'ldap_outseparator'}, @$valuesref) || ''
join($self->{'ldap_outseparator'}, @$valuesref)
Truth table0%0/2
A
A= join($self->{'ldap_outseparator'}, @$valuesref)
Aresult
11
00
269 }
270 0 ▶ unless ($valuesref[0])
Branch: 1 branch
BranchTrueFalseTotal
unless ($valuesref[0]) 0 0 0
271 {
272 0 ▶ $varlist[$j][$fieldnamehash{dn}] = $dn if ($attr eq 'dn');
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "dn" 0 0 0
273 }
274 0 $i++;
275 }
276 0 ++$j;
277 }
278 0 $self->{use_fields} = $attbs;
279 0 ▶ if ($distinct) #THIS MAKES "DISTINCT" WORK.
Branch: 1 branch
BranchTrueFalseTotal
if ($distinct) 0 0 0
280 {
281 0 my (%disthash);
282 0 ▶ for (my $i=0;$i<=$#varlist;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#varlist) 0 0 0
283 {
284 0 ++$disthash{join("\x02",@{$varlist[$i]})};
285 }
286 0 @varlist = ();
287 0 foreach my $i (keys(%disthash))
288 {
289 0 push (@varlist, [split(/\x02/o, $i, -1)]);
290 }
291 }
292 0 ▶ if ($#ordercols >= 0) #SORT 'EM!
Branch: 1 branch
BranchTrueFalseTotal
if ($#ordercols >= 0) 0 0 0
293 {
294 0 my @SV;
295 0 ▶ for (my $i=0;$i<=$#varlist;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#varlist) 0 0 0
296 {
297 0 $SV[$i] = '';
298 0 foreach my $j (@ordercols)
299 {
300 0 $SV[$i] .= $varlist[$i][$fieldnamehash{$j}] . "\x01";
301 }
302 }
303 0 @sortvector = &sort_elements(\@SV);
304 0 ▶ @sortvector = reverse(@sortvector) if ($descorder);
Branch: 1 branch
BranchTrueFalseTotal
if $descorder 0 0 0
305 0 @SV = ();
306 0 ▶ while (@sortvector)
Branch: 1 branch
BranchTrueFalseTotal
if (@sortvector) 0 0 0
307 {
308 0 push (@SV, $varlist[shift(@sortvector)]);
309 }
310 0 @varlist = @SV;
311 0 @SV = ();
312 }
313 0 return [($#attributes+1), @varlist];
314 }
315 else #INVALID SELECT STATEMENT!
316 {
317 0 return (-503);
318 }
319 }
320  
321 sub sort_elements
322 0 ▶{
Subroutine sort_elements: not called CC=12 SCAR=50.5
Pod undocumented
323 0 my (@elements, $line, @sortlist, @sortedlist, $j, $t, $argcnt, $linedata,
324 $vectorid, @sortvector);
325  
326 0 my ($lo) = 0;
327 0 my ($hi) = 0;
328 0 ▶ $lo = shift unless (ref($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
329 0 ▶ $hi = shift unless (ref($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
330  
331 0 ▶ if ($lo || $hi)
Branch: 1 branch
BranchTrueFalseTotal
if ($lo or $hi) 0 0 0
Condition0%0/3
$lo or $hi
l!l&&r!l&&!r
000
MC/DC0%0/2
$lo or $hi
$lo $hi
Truth table0%0/3
A or B
A= $loB= $hi
ABresult
1X1
011
000
332 {
333 0 ▶ for ($j=0;$j<=$#{$_[0]};$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#{$_[0];}) 0 0 0
334 {
335 0 $sortvector[$j] = $j;
336 }
337 }
338 0 ▶ $hi ||= $#{$_[0]};
Condition0%0/3
$hi ||= $#{$_[0];}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hi ||= $#{$_[0];}
$hi $#{$_[0];}
Truth table0%0/3
A ||= B
A= $hiB= $#{$_[0];}
ABresult
1X1
011
000
339 0 $argcnt = scalar(@_);
340 0 ▶ for (my $i=$lo;$i<=$hi;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $hi) 0 0 0
341 {
342 0 $line = $_[0][$i];
343 0 ▶ for ($j=1;$j<$argcnt;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $argcnt) 0 0 0
344 {
345 0 $line .= "\x02" . $_[$j][$i];
346 }
347 0 $line .= "\x04".$i;
348 0 push (@sortlist, $line);
349 }
350  
351 0 @sortedlist = sort @sortlist;
352 0 $i = $lo;
353 0 foreach $line (@sortedlist)
354 {
355 0 ($linedata,$vectorid) = split(/\x04/o, $line);
356 0 (@elements) = split(/\x02/o, $linedata);
357 0 ▶ $t = $#elements unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 0 0
358 0 ▶ for ($j=$t;$j>=1;$j--)
Branch: 1 branch
BranchTrueFalseTotal
if ($j >= 1) 0 0 0
359 {
360 #push (@{$_[$j]}, $elements[$j]);
361 0 ${$_[$j]}[$i] = $elements[$j];
362 }
363 0 $sortvector[$i] = $vectorid;
364 0 $elements[0] =~ s/\s+//go;
365 0 ${$_[0]}[$i] = $elements[$j];
366 0 ++$i;
367 }
368 0 return @sortvector;
369 }
370  
371 sub ldap_error
372 0 ▶{
Subroutine ldap_error: not called CC=5 SCAR=34.0
Pod undocumented
373 0 my ($self,$errcode,$errmsg,$warn) = @_;
374  
375 0 ▶ $err = $errcode || -1;
Condition0%0/2
$errcode || -1
l!l
00
MC/DC0%0/1
$errcode || -1
$errcode
Truth table0%0/2
A
A= $errcode
Aresult
11
00
376 0 $errdetails = $errmsg;
377 0 ▶ $err = -1 * $err if ($err > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $err > 0 0 0 0
378 0 ▶ return ($err) unless (defined($warn) && $warn);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $warn and $warn 0 0 0
Condition0%0/3
defined $warn and $warn
!ll&&!rl&&r
000
MC/DC0%0/2
defined $warn and $warn
defined $warn $warn
Truth table0%0/3
A and B
A= defined $warnB= $warn
ABresult
0X0
100
111
379  
380 # print "Content-type: text/html\nWindow-target: _parent", "\n\n"
381 # if (defined($warn) && $warn == 1);
382  
383 0 return ($self->display_error($errcode));
384 }
385  
386 sub display_error
387 0 ▶{
Subroutine display_error: not called CC=6 SCAR=37.4
Pod undocumented
388 0 my ($self, $error) = @_;
389  
390 0 ▶ $other = $@ || $! || 'None';
Condition0%0/5
$@ || $! || 'None'
l!l
00
$@ or $!
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $! || 'None'
$@ $!
Truth table0%0/3
A or B
A= $@B= $!
ABresult
1X1
011
000
391  
392 0 ▶ print STDERR <<Error_Message unless ($self->{silent});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"silent"} 0 0 0
393  
394 Oops! The following error occurred when processing your request:
395  
396 $self->{errors}->{$error} ($errdetails)
397  
398 Here's some more information to help you:
399  
400 file: $self->{file}
401 $other
402  
403 Error_Message
404  
405 #JWT: ADDED FOR ERROR-CONTROL.
406  
407 0 $self->{lasterror} = $error;
408 0 $self->{lastmsg} = "$error:" . $self->{errors}->{$error};
409 0 ▶ $self->{lastmsg} .= '('.$errdetails.')' if ($errdetails); #20000114
Branch: 1 branch
BranchTrueFalseTotal
if $errdetails 0 0 0
410  
411 0 $errdetails = ''; #20000114
412 0 ▶ die $self->{lastmsg} if ($self->{RaiseError}); #20000114.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"RaiseError"} 0 0 0
413  
414 #return (1);
415 0 return ($error);
416 }
417  
418 sub commit
419 0 ▶{
Subroutine commit: not called CC=4 SCAR=30.0
Pod undocumented
420 0 my ($self) = @_;
421 0 my ($status) = 1;
422 0 my ($dbh) = $self->FETCH('ldap_dbh');
423 0 my ($autocommit) = $dbh->FETCH('AutoCommit');
424  
425 0 ▶ $status = $dbh->commit() unless ($autocommit);
Branch: 1 branch
BranchTrueFalseTotal
unless $autocommit 0 0 0
426  
427 0 ▶ $self->{dirty} = 0 if ($status > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $status > 0 0 0 0
428 0 ▶ return undef if ($status <= 0); #ADDED 20000103
Branch: 1 branch
BranchTrueFalseTotal
if $status <= 0 0 0 0
429 0 return $status;
430 }
431  
432 ##++
433 ## Private Methods
434 ##--
435  
436 sub define_errors
437 0 ▶{
Subroutine define_errors: not called CC=1 SCAR=6.9
Pod undocumented
438 0 my $self = shift;
439 0 my $errors;
440  
441 0 $errors = {};
442  
443 0 $errors->{'-501'} = 'Could not open specified database.';
444 0 $errors->{'-502'} = 'Specified column(s) not found.';
445 0 $errors->{'-503'} = 'Incorrect format in [select] statement.';
446 0 $errors->{'-504'} = 'Incorrect format in [update] statement.';
447 0 $errors->{'-505'} = 'Incorrect format in [delete] statement.';
448 0 $errors->{'-506'} = 'Incorrect format in [add/drop column] statement.';
449 0 $errors->{'-507'} = 'Incorrect format in [alter table] statement.';
450 0 $errors->{'-508'} = 'Incorrect format in [insert] command.';
451 0 $errors->{'-509'} = 'The no. of columns does not match no. of values.';
452 0 $errors->{'-510'} = 'A severe error! Check your query carefully.';
453 0 $errors->{'-511'} = 'Cannot write the database to output file.';
454 0 $errors->{'-512'} = 'Unmatched quote in expression.';
455 0 $errors->{'-513'} = 'Need to open the database first!';
456 0 $errors->{'-514'} = 'Please specify a valid query.';
457 # $errors->{'-515'} = 'Cannot get lock on database file.';
458 # $errors->{'-516'} = 'Cannot delete temp. lock file.';
459 0 $errors->{'-517'} = "Built-in function failed ($@).";
460 0 $errors->{'-518'} = "Unique Key Constraint violated."; #JWT.
461 0 $errors->{'-519'} = "Field would have to be truncated."; #JWT.
462 0 $errors->{'-520'} = "Can not create existing table (drop first!)."; #20000225 JWT.
463 0 $errors->{'-521'} = "Can not change datatype on non-empty table."; #20000323 JWT.
464 0 $errors->{'-522'} = "Can not decrease field-size on non-empty table."; #20000323 JWT.
465 0 $errors->{'-523'} = "Update Failed to commit changes."; #20000323 JWT.
466 0 $errors->{'-524'} = "No such table."; #20000323 JWT.
467 0 $errors->{'-599'} = 'General error.';
468  
469 0 $self->{errors} = $errors;
470  
471 0 return (1);
472 }
473  
474 sub parse_expression
475 0 ▶{
Subroutine parse_expression: not called CC=25 SCAR=64.8
Pod undocumented
476 0 my ($self, $s) = @_;
477  
478 0 $s =~ s/\s+$//o; #STRIP OFF LEADING AND TRAILING WHITESPACE.
479 0 $s =~ s/^\s+//o;
480 0 ▶ return unless ($s);
Branch: 1 branch
BranchTrueFalseTotal
unless $s 0 0 0
481  
482  
483 0 my $relop = '(?:<|=|>|<=|>=|!=|like|not\s+like|is\s+not|is)';
484 0 my %boolopsym = ('and' => '&', 'or' => '|');
485  
486 0 my $indx = 0;
487  
488 0 my @P = ();
489 0 my @T3 = (); #PROTECTS MULTI-WAY RELOP EXPRESSIONS, IE. (A AND B AND C)
490 0 my $t3indx = 0;
491 0 @T = ();
492 0 my @QS = ();
493  
494 0 $s=~s|\\\'|\x04|go; #PROTECT "\'" IN QUOTES.
495 0 $s=~s|\\\"|\x02|go; #PROTECT "\"" IN QUOTES.
496  
497 #THIS NEXT LOOP STRIPS OUT AND SAVES ALL QUOTED STRING LITERALS
498 #TO PREVENT THEM FROM INTERFEARING WITH OTHER REGICES, IE. DON'T
499 #WANT OPERATORS IN STRINGS TO BE TREATED AS OPERATORS!
500  
501 0 ▶ $indx++ while ($s =~ s/([\'\"])([^\1]*?)\1/
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/([\'\"])([^\1]*?)\1/$QS[$indx] = $2; "\$QS[$indx]";/e and do { ++$indx } 0 0 0
502 0 $QS[$indx] = $2; "\$QS\[$indx]"/e);
503  
504 0 ▶ for (my $i=0;$i<=$#QS;$i++) #ESCAPE LDAP SPECIAL-CHARACTERS.
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#QS) 0 0 0
505 {
506 0 $QS[$i] =~ s/\\x([\da-fA-F][\da-fA-F])/\x05$1/g; #PROTECT PERL HEX TO LDAP HEX (\X## => \##).
507 #$QS[$i] =~ s/([\*\(\)\+\\\<\>])/\\$1/g; #CHGD. TO NEXT. 20020409!
508 0 $QS[$i] =~ s/([\*\(\)\\])/"\\".unpack('H2',$1)/eg;
509 #$QS[$i] =~ s/\\x(\d\d)/\\$1/g; #CONVERT PERL HEX TO LDAP HEX (\X## => \##).
510 0 $QS[$i] =~ s/\x05([\da-fA-F][\da-fA-F])/\\$1/go; #CONVERT PERL HEX TO LDAP HEX (\X## => \##).
511 }
512 #print STDERR "-parse_expression: QS list=".join('|',@QS)."= SSSS=$s=\n";
513 0 $indx = 0;
514  
515 #I TRIED TO ALLOWING ATTRIBUTES TO BE COMPARED W/OTHER ATTRIBUTES, BUT
516 #(20020409), BUT APPARENTLY LDAP ONLY ALLOWS STRING CONSTANTS ON RHS OF OPERATORS!
517  
518 # $indx++ while ($s =~ s/(\w+)\s*($relop)\s*(\$QS\[\d*\]|\w+)/ #THIS WAS TRIED TO COMPARE ATTRIBUTES WITH ATTRIBUTES, BUT APPARENTLY DOESN'T WORK IN LDAP!
519 0 ▶ $indx++ while ($s =~ s/(\w+)\s*($relop)\s*(\$QS\[\d*\])/
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s((\w+)\s*($relop)\s*(\$QS\[\d*\]))(() = ($1, $2, $3); my($regex) = 0; my($opr) = $two; if ($two =~ /(?:not\s+like|is\s+not)/io) { $two = "="; $regex = 2; } elsif ($two =~ /(?:like|is)/io) { $two = "="; $regex = 1; } ; $P[$indx] = $one . $two . $three; my $qsindx; if ($three =~ /\$QS\[(\d+)\]/) { $qsindx = $1; if ($regex > 0) { unless ($opr =~ /is/io) { $QS[$qsindx] =~ s/\%/*/go; } ; } ; $QS[$qsindx] = $self->{"ldap_nullsearchvalue"} unless length $QS[$qsindx]; } ; $P[$indx] = "!($P[$indx])" if $regex == 2 or $opr eq "!=" or $opr eq "=" and not length $QS[$qsindx]; $P[$indx] =~ s/!\=/=/o; "\$P[$indx]";)ie and do { ++$indx } 0 0 0
520 0 my ($one, $two, $three) = ($1, $2, $3);
521 0 my ($regex) = 0;
522 0 my ($opr) = $two;
523 #CONVERT "NOT LIKE" AND "IS NOT" TO "!( = ).
524  
525 0 ▶ if ($two =~ m!(?:not\s+like|is\s+not)!io)
Branch: 2 branches
BranchTrueFalseTotal
if ($two =~ /(?:not\s+like|is\s+not)/io) { } 0 0 0
elsif ($two =~ /(?:like|is)/io) { } 0 0 0
526 {
527 0 $two = '=';
528 0 $regex = 2;
529 }
530 elsif ($two =~ m!(?:like|is)!io) #CONVERT "LIKE" AND "IS" TO "=".
531 {
532 0 $two = '=';
533 0 $regex = 1;
534 }
535 0 $P[$indx] = $one.$two.$three; #SAVE EXPRESSION.
536
537 #CONVERT SQL WILDCARDS INTO LDAP WILDCARDS IN OPERAND.
538
539 0 my ($qsindx);
540 0 ▶ if ($three =~ m!\$QS\[(\d+)\]!)
Branch: 1 branch
BranchTrueFalseTotal
if ($three =~ /\$QS\[(\d+)\]/) 0 0 0
541 {
542 0 $qsindx = $1;
543 0 ▶ if ($regex > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($regex > 0) 0 0 0
544 {
545 0 ▶ if ($opr !~ m!is!io)
Branch: 1 branch
BranchTrueFalseTotal
unless ($opr =~ /is/io) 0 0 0
546 {
547 0 $QS[$qsindx] =~ s!\%!\*!go; #FIX WILDCARD. NOTE - NO FIX FOR "_"!
548 }
549 }
550 0 ▶ $QS[$qsindx] = $self->{ldap_nullsearchvalue} unless (length($QS[$qsindx]));
Branch: 1 branch
BranchTrueFalseTotal
unless length $QS[$qsindx] 0 0 0
551 }
552 0 ▶ $P[$indx] = "!($P[$indx])" if ($regex == 2 || $opr eq '!=' || ($opr eq '=' && !length($QS[$qsindx]))); #INVERT EXPRESSION IF "NOT"!
Branch: 1 branch
BranchTrueFalseTotal
if $regex == 2 or $opr eq "!=" or $opr eq "=" and not length $QS[$qsindx] 0 0 0
Condition0%0/9
$regex == 2 or $opr eq "!=" or $opr eq "=" and not length $QS[$qsindx]
l!l&&r!l&&!r
000
$regex == 2 or $opr eq "!="
l!l&&r!l&&!r
000
$opr eq "=" and not length $QS[$qsindx]
!ll&&!rl&&r
000
MC/DC0%0/4
$regex == 2 or $opr eq "!=" or $opr eq "=" and not length $QS[$qsindx]
$regex == 2 $opr eq "!=" $opr eq "=" not length $QS[$qsindx]
Truth table0%0/5
A or B or C and not(D)
A= $regex == 2B= $opr eq "!="C= $opr eq "="D= not length $QS[$qsindx]
ABCDresult
1XXX1
01XX1
00111
000X0
00100
553 0 $P[$indx] =~ s!\!\=!\=!o; #AFTER INVERSION, FIX "!=" (NOT VALID IN LDAP!)
554 0 "\$P\[$indx]";
555 /ei); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
556 0 $self->{tindx} = 0;
557 0 $s = &parseParins($self, $s);
558  
559 0 ▶ for (my $i=0;$i<=$#T;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#T) 0 0 0
560 {
561 # 1 while ($T[$i] =~ s/(.+?)\s*\band\b\s*(.+)/\&\($1\)\($2\)/i);
562 0 ▶ 1 while ($T[$i] =~ s/([^\(\)]+)\s*\band\b\s*([^\(\)]+)(?:and|or)?/\&\($1\)\($2\)/i);
Branch: 1 branch
BranchTrueFalseTotal
$T[$i] =~ s/([^\(\)]+)\s*\band\b\s*([^\(\)]+)(?:and|or)?/&($1)($2)/i and do { '???' } 0 0 0
563 0 ▶ 1 while ($T[$i] =~ s/([^\(\)]+)\s*\bor\b\s*([^\(\)]+)(?:and|or)?/\|\($1\)\($2\)/i);
Branch: 1 branch
BranchTrueFalseTotal
$T[$i] =~ s/([^\(\)]+)\s*\bor\b\s*([^\(\)]+)(?:and|or)?/|($1)($2)/i and do { '???' } 0 0 0
564 }
565 0 $s =~ s/AND/and/igo;
566 0 $s =~ s/OR/or/igo;
567 # 1 while ($s =~ s/(.+?)\s*\band\b\s*(.+)/\(\&\($1\)\($2\)\)/i); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
568 0 ▶ 1 while ($s =~ s/([^\(\)]+)\s*\band\b\s*([^\(\)]+)(?:and|or)?/\&\($1\)\($2\)/i); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/([^\(\)]+)\s*\band\b\s*([^\(\)]+)(?:and|or)?/&($1)($2)/i and do { '???' } 0 0 0
569 0 ▶ 1 while ($s =~ s/([^\(\)]+)\s*\bor\b\s*([^\(\)]+)(?:and|or)?/\|\($1\)\($2\)/i); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/([^\(\)]+)\s*\bor\b\s*([^\(\)]+)(?:and|or)?/|($1)($2)/i and do { '???' } 0 0 0
570 0 ▶ 1 while ($s =~ s/\bnot\b\s*([^\s\)]+)?/\!\($1\)/);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/\bnot\b\s*([^\s\)]+)?/!($1)/ and do { '???' } 0 0 0
571 0 ▶ 1 while ($s =~ s/\$T\[(\d+)\]/$T[$1]/g);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/\$T\[(\d+)\]/$T[$1]/g and do { '???' } 0 0 0
572 0 $s =~ s/(\w+)\s+is\s+not\s+null?/$1\=\*/gi;
573 0 $s =~ s/(\w+)\s+is\s+null?/\!\($1\=\*\)/gi;
574  
575 #CONVERT SQL WILDCARDS TO PERL REGICES.
576  
577 0 ▶ 1 while ($s =~ s/\$P\[(\d+)\]/$P[$1]/g);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/\$P\[(\d+)\]/$P[$1]/g and do { '???' } 0 0 0
578 0 $s =~ s/ +//go;
579 0 ▶ 1 while ($s =~ s/\$QS\[(\d+)\]/$QS[$1]/g);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/\$QS\[(\d+)\]/$QS[$1]/g and do { '???' } 0 0 0
580 0 $s =~ s/\x04/\'/go; #UNPROTECT AND UNESCAPE QUOTES WITHIN QUOTES.
581 0 ▶ $s = '(' . $s . ')' unless ($s =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /^\(/o 0 0 0
582 0 return $s;
583 }
584  
585 sub parseParins
586 0 ▶{
Subroutine parseParins: not called CC=2 SCAR=17.9
Pod undocumented
587 0 my $self = shift;
588 0 my $s = shift;
589  
590 0 ▶ $self->{tindx}++ while ($s =~ s/\(([^\(\)]+)\)/
Branch: 1 branch
BranchTrueFalseTotal
$s =~ s/\(([^\(\)]+)\)/$T[$self->{"tindx"}] = &parseParins($self, $1); qq[\$T[$self->{"tindx"}]];/e and do { ++$self->{"tindx"} } 0 0 0
591 0 $T[$self->{tindx}] = &parseParins($self, $1); "\$T\[$self->{tindx}]"
592 /e);
593 0 return $s;
594 }
595  
596 sub rollback
597 0 ▶{
Subroutine rollback: not called CC=3 SCAR=24.8
Pod undocumented
598 0 my ($self) = @_;
599  
600 0 my ($status) = 1;
601 0 my ($dbh) = $self->FETCH('ldap_dbh');
602 0 my ($autocommit) = $dbh->FETCH('AutoCommit');
603  
604 0 ▶ $status = $dbh->rollback() unless ($autocommit);
Branch: 1 branch
BranchTrueFalseTotal
unless $autocommit 0 0 0
605  
606 0 ▶ $self->{dirty} = 0 if ($status > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $status > 0 0 0 0
607 0 return $status;
608 }
609  
610 sub update
611 0 ▶{
Subroutine update: not called CC=38 SCAR=73.0
Pod undocumented
612 0 my ($self, $csr, $query) = @_;
613 0 my ($i, $path, $regex, $table, $extra, @attblist, $filter, $all_columns);
614 0 my $status = 0;
615 0 my ($psuedocols) = "CURVAL|NEXTVAL|ROWNUM";
616 #print STDERR "-update10 sql=$query=\n";
617 ##++
618 ## Hack to allow parenthesis to be escaped!
619 ##--
620  
621 0 $query =~ s/\\([()])/sprintf ("%%\0%d: ", ord ($1))/ge;
622 0 $path = $self->{path};
623 0 $regex = $self->{column};
624  
625 0 ▶ if ($query =~ /^update\s+($path)\s+set\s+(.+)$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^update\s+($path)\s+set\s+(.+)$/i) { } 0 0 0
626 {
627 0 ($table, $extra) = ($1, $2);
628 #print STDERR "-update20: table=$table= extra=$extra=\n";
629 #ADDED IF-STMT 20010418 TO CATCH
630 #PARENTHESIZED SET-CLAUSES (ILLEGAL IN ORACLE & CAUSE WIERD PARSING ERRORS!)
631  
632 0 ▶ if ($extra =~ /^\(.+\)\s*where/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($extra =~ /^\(.+\)\s*where/io) 0 0 0
633 {
634 0 $errdetails = 'parenthesis around SET clause?';
635 0 return (-504);
636 }
637 0 ▶ $table =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
638 0 $self->{file} = $table;
639  
640 0 my ($dbh) = $csr->FETCH('ldap_dbh');
641 0 my ($ldap) = $csr->FETCH('ldap_ldap');
642 0 my ($tablehash) = $dbh->FETCH('ldap_tables');
643 0 ▶ return (-524) unless ($tablehash->{$table});
Branch: 1 branch
BranchTrueFalseTotal
unless $tablehash->{$table} 0 0 0
644 0 my ($base, $objfilter, $dnattbs, $allattbs, $alwaysinsert) = split(/\:/,$tablehash->{$table});
645  
646 0 $all_columns = {};
647  
648 0 $extra =~ s/\\\\/\x02/go; #PROTECT "\\"
649 #1$extra =~ s/\'\'/\x03\x03/go; #PROTECT '', AND \'.
650 0 $extra =~ s/\\\'/\x03/go; #PROTECT '', AND \'.
651  
652 0 $extra =~ s/^\s+//o; #STRIP OFF SURROUNDING SPACES.
653 0 $extra =~ s/\s+$//o;
654  
655 #NOW TEMPORARILY PROTECT COMMAS WITHIN (), IE. FN(ARG1,ARG2).
656  
657 0 $column = $self->{column};
658 0 $extra =~ s/($column\s*\=\s*)\'(.*?)\'(,|$)/
659 0 my ($one,$two,$three) = ($1,$2,$3);
660 0 $two =~ s|\,|\x05|go;
661 0 $two =~ s|\(|\x06|go;
662 0 $two =~ s|\)|\x07|go;
663 0 $one."'".$two."'".$three;
664 /eg;
665  
666 0 ▶ 1 while ($extra =~ s/\(([^\(\)]*)\)/
Branch: 1 branch
BranchTrueFalseTotal
$extra =~ s[\(([^\(\)]*)\)][my($args) = $1; $args =~ s/\,/\cE/go; "\cF$args\a";]eg and do { '???' } 0 0 0
667 0 my ($args) = $1;
668 0 $args =~ s|\,|\x05|go;
669 0 "\x06$args\x07";
670 /eg);
671 0 @expns = split(',',$extra);
672 #print STDERR "-update50: extra=$extra= expns=".join('|',@expns)."=\n";
673 0 ▶ for ($i=0;$i<=$#expns;$i++) #PROTECT "WHERE" IN QUOTED VALUES.
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#expns) 0 0 0
674 {
675 0 $expns[$i] =~ s/\x05/\,/go;
676 0 $expns[$i] =~ s/\x06/\(/go;
677 0 $expns[$i] =~ s/\x07/\)/go;
678 0 $expns[$i] =~ s/\=\s*'([^']*?)where([^']*?)'/\='$1\x05$2'/gi;
679 0 $expns[$i] =~ s/\'(.*?)\'/my ($j)=$1;
680 0 $j=~s|where|\x05|gio;
681 0 "'$j'"
682 /eg;
683 }
684 0 $extra = $expns[$#expns]; #EXTRACT WHERE-CLAUSE, IF ANY.
685 0 ▶ $filter = ($extra =~ s/(.*)where(.+)$/where$1/i) ? $2 : '';
Branch: 1 branch
BranchTrueFalseTotal
$extra =~ s/(.*)where(.+)$/where$1/i ? : 0 0 0
686 0 $filter =~ s/\s+//o;
687 0 $expns[$#expns] =~ s/\s*where(.+)$//io; #20000108 REP. PREV. LINE 2FIX BUG IF LAST COLUMN CONTAINS SINGLE QUOTES.
688 0 $column = $self->{column};
689 0 ▶ $objfilter ||= 'objectclass=*';
Condition0%0/2
$objfilter ||= "objectclass=*"
l!l
00
MC/DC0%0/1
$objfilter ||= "objectclass=*"
$objfilter
Truth table0%0/2
A
A= $objfilter
Aresult
11
00
690 0 ▶ $objfilter = "($objfilter)" unless ($objfilter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $objfilter =~ /^\(/o 0 0 0
691 0 ▶ if ($filter)
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) { } 0 0 0
692 {
693 #print STDERR "--update: BEF parse_expn: filter=$filter=\n";
694 0 $filter = $self->parse_expression ($filter);
695 #print STDERR "--update: AFT parse_expn: filter=$filter= objfilter=$objfilter=\n";
696 0 ▶ $filter = '('.$filter.')' unless ($filter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $filter =~ /^\(/o 0 0 0
697 0 $filter = "(&$objfilter$filter)";
698 }
699 else
700 {
701 0 $filter = "$objfilter";
702 }
703 0 $filter =~ s/\x03/\\\'/go; #UNPROTECT '', AND \'. #NEXT 2 ADDED 20091101:
704 0 $filter =~ s/\x02/\\\\/go; #UNPROTECT "\\".
705 # $alwaysinsert .= ',' . $base; #CHGD TO NEXT 200780719 PER REQUEST.
706 0 ▶ $alwaysinsert .= ',' . $base if ($self->{ldap_appendbase2ins});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ldap_appendbase2ins"} 0 0 0
707 0 $alwaysinsert =~ s/\\\\/\x02/go; #PROTECT "\\"
708 0 $alwaysinsert =~ s/\\\,/\x03/go; #PROTECT "\,"
709 0 $alwaysinsert =~ s/\\\=/\x04/go; #PROTECT "\="
710 0 my ($i1, $col, $vals, $j, @l);
711 0 ▶ for ($i=0;$i<=$#expns;$i++) #EXTRACT FIELD NAMES AND
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#expns) 0 0 0
712 #VALUES FROM EACH EXPRESSION.
713 {
714 0 $expns[$i] =~ s/\x03/\\\'/go; #UNPROTECT '', AND \'.
715 0 $expns[$i] =~ s/\x02/\\\\/go; #UNPROTECT "\\".
716 0 $expns[$i] =~ s!\s*($column)\s*=\s*(.+)$!
717 0 my ($var) = $1;
718 0 my ($val) = $2;
719
720 0 ▶ $val = &pscolfn($self,$val) if ($val =~ "$column\.$psuedocols");
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /$column.$psuedocols/ 0 0 0
721 0 $var =~ tr/A-Z/a-z/;
722 0 $val =~ s|%\0(\d+): |pack("C",$1)|ge;
723 0 $val =~ s/^\'//o; #NEXT 2 ADDED 20010530 TO STRIP EXCESS QUOTES.
724 0 $val =~ s/([^\\\'])\'$/$1/;
725 0 $val =~ s/\'$//o;
726 0 $all_columns->{$var} = $val;
727 0 @_ = split(/\,\s*/o, $alwaysinsert);
728 0 ▶ while (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
729 {
730 0 ($col, $vals) = split(/\=/o, shift);
731 0 ▶ next unless ($col eq $var);
Branch: 1 branch
BranchTrueFalseTotal
unless $col eq $var 0 0 0
732 0 $vals =~ s/\x04/\\\=/go; #UNPROTECT "\="
733 0 $vals =~ s/\x03/\\\,/go; #UNPROTECT "\,"
734 0 $vals =~ s/\x02/\\\\/go; #UNPROTECT "\\"
735 0 @l = split(/\Q$self->{ldap_inseparator}\E/, $vals);
736 0 ▶VALUE: for (my $j=0;$j<=$#l;$j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#l) 0 0 0
737 {
738 0 ▶ next if ($all_columns->{$var} =~ /\b$l[$j]\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $all_columns->{$var} =~ /\b$l[$j]\b/ 0 0 0
739 $all_columns->{$var} .= $self->{ldap_inseparator}
740 0 ▶ if ($all_columns->{$var});
Branch: 1 branch
BranchTrueFalseTotal
if $all_columns->{$var} 0 0 0
741 0 $all_columns->{$var} .= $l[$j];
742 }
743 }
744 0 $all_columns->{$var} =~ s/\x02/\\\\/go;
745 # $all_columns->{$var} =~ s/\x03/\'/go; #20091030: REPL. W.NEXT LINE TO KEEP ESCAPE SLASH "\" - RETAIN ORIG. COMMENT:
746 0 $all_columns->{$var} =~ s/\x03/\\\'/go; #20000108 REPL. PREV. LINE - NO NEED TO DOUBLE QUOTES (WE ESCAPE THEM) - THIS AIN'T ORACLE.
747 !e;
748 }
749  
750 0 delete $all_columns->{dn}; #DO NOT ALLOW DN TO BE CHANGED DIRECTLY!
751 #foreach my $xxx (sort keys %{$all_columns}) { print STDERR "---data($xxx)=".$all_columns->{$xxx}."=\n"; };
752 0 my ($data);
753 0 my (@searchops) = (
754 'base' => $base,
755 'filter' => $filter,
756 );
757 0 foreach my $i (qw(ldap_sizelimit ldap_timelimit deref typesonly
758 callback))
759 {
760 0 $j = $i;
761 0 $j =~ s/^ldap_//o;
762 0 ▶ push (@searchops, ($j, $self->{$i})) if ($self->{$i});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$i} 0 0 0
763 }
764 0 ▶ push (@searchops, ('scope', ($self->{ldap_scope} || 'one')));
Condition0%0/2
$self->{'ldap_scope'} || 'one'
l!l
00
MC/DC0%0/1
$self->{'ldap_scope'} || 'one'
$self->{'ldap_scope'}
Truth table0%0/2
A
A= $self->{'ldap_scope'}
Aresult
11
00
765 #print STDERR "-update: filter=$filter= searchops=".join('|',@searchops)."=\n";
766 0 ▶ $data = $ldap->search(@searchops)
Branch: 1 branch
BranchTrueFalseTotal
$data = $ldap->search(@searchops) or return $self->ldap_error($@, "Search failed to return object: filter=$filter (" . $data->error . ')') 0 0 0
767 or return($self->ldap_error($@,"Search failed to return object: filter=$filter (".$data->error().")"));
768 #print STDERR "-update: got thru search; data=$data=\n";
769 0 my (@varlist) = ();
770 0 $dbh = $csr->FETCH('ldap_dbh');
771 0 my ($autocommit) = $dbh->FETCH('AutoCommit');
772 0 ▶ my ($commitqueue) = $dbh->FETCH('ldap_commitqueue') unless ($autocommit);
Branch: 1 branch
BranchTrueFalseTotal
unless $autocommit 0 0 0
773 0 my (@dnattbs) = split(/\,/o, $dnattbs);
774 0 my ($changedn);
775 #print STDERR "-update: going into loop!\n";
776 0 ▶ while (my $entry = $data->shift_entry())
Branch: 1 branch
BranchTrueFalseTotal
if (my $entry = $data->shift_entry) 0 0 0
777 {
778 #print STDERR "----update: in loop entry=$entry=\n";
779 0 $dn = $entry->dn();
780 0 $dn =~ s/\\/\x02/go; #PROTECT "\";
781 0 $dn =~ s/\\\,/\x03/go; #PROTECT "\,";
782 0 $changedn = 0;
783 0 I: foreach my $i (@dnattbs)
784 {
785 0 foreach my $j (keys %$all_columns)
786 {
787 0 ▶ if ($i eq $j)
Branch: 1 branch
BranchTrueFalseTotal
if ($i eq $j) 0 0 0
788 {
789 0 $dn =~ s/(\b$i\=)([^\,]+)/$1$all_columns->{$j}/;
790 0 $changedn = 1;
791 0 next I;
792 }
793 }
794 }
795 0 $dn =~ s/(?:\,\s*)$base$//;
796 0 $dn =~ s/\x03/\\\,/go; #UNPROTECT "\,";
797 0 $dn =~ s/\x02/\\/go; #UNPROTECT "\";
798 0 foreach my $i (keys %$all_columns)
799 {
800 0 $all_columns->{$i} =~ s/(?:\\|\')\'/\'/go; #1UNESCAPE QUOTES IN VALUES.
801 0 @_ = split(/\Q$self->{ldap_inseparator}\E/, $all_columns->{$i});
802 0 ▶ if (!@_)
Branch: 2 branches
BranchTrueFalseTotal
if (not @_) { } 0 0 0
elsif (@_ == 1) { } 0 0 0
803 {
804 0 push (@attblist, ($i, ''));
805 }
806 elsif (@_ == 1)
807 {
808 0 push (@attblist, ($i, shift));
809 }
810 else
811 {
812 0 push (@attblist, ($i, [@_]));
813 }
814 }
815 0 $r1 = $entry->replace(@attblist);
816 #print STDERR "-update: r1=$r1= attblist=".join('|',@attblist)."=\n";
817 0 ▶ if ($r1 > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($r1 > 0) { } 0 0 0
818 {
819 0 ▶ if ($autocommit)
Branch: 1 branch
BranchTrueFalseTotal
if ($autocommit) { } 0 0 0
820 {
821 0 $r2 = $entry->update($ldap); #COMMIT!!!
822 0 ▶ if ($r2->is_error)
Branch: 1 branch
BranchTrueFalseTotal
if ($r2->is_error) 0 0 0
823 {
824 0 $errdetails = $r2->code . ': ' . $r2->error;
825 0 return (-523);
826 }
827 0 ▶ if ($changedn)
Branch: 1 branch
BranchTrueFalseTotal
if ($changedn) 0 0 0
828 {
829 0 $r2 = $ldap->moddn($entry, newrdn => $dn);
830 0 ▶ if ($r2->is_error)
Branch: 1 branch
BranchTrueFalseTotal
if ($r2->is_error) 0 0 0
831 {
832 0 $errdetails = "Could not change dn - "
833 . $r2->code . ': ' . $r2->error . '!';
834 0 return (-523);
835 }
836 }
837 }
838 else
839 {
840 0 push (@{$commitqueue}, (\$entry, \$ldap));
841 0 ▶ push (@{$commitqueue}, "dn=$dn") if ($changedn);
Branch: 1 branch
BranchTrueFalseTotal
if $changedn 0 0 0
842 }
843 0 ++$status;
844 }
845 else
846 {
847 #return($self->ldap_error($@,"Search failed to return object: filter=$filter (".$data->error().")"));
848 0 $errdetails = $data->code . ': ' . $data->error;
849 0 return (-523);
850 }
851 }
852 0 return ($status);
853 }
854 else
855 {
856 0 return (-504);
857 }
858 }
859  
860 sub delete
861 0 ▶{
Subroutine delete: not called CC=15 SCAR=54.8
Pod undocumented
862 0 my ($self, $csr, $query) = @_;
863 0 my ($path, $table, $filter, $wherepart);
864 0 my $status = 0;
865  
866 0 $path = $self->{path};
867 0 ▶ if ($query =~ /^delete\s+from\s+($path)(?:\s+where\s+(.+))?$/io)
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^delete\s+from\s+($path)(?:\s+where\s+(.+))?$/io) { } 0 0 0
868 {
869 0 $table = $1;
870 0 $wherepart = $2;
871 0 ▶ $table =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
872 0 $self->{file} = $table;
873  
874 0 my ($dbh) = $csr->FETCH('ldap_dbh');
875 0 my ($ldap) = $csr->FETCH('ldap_ldap');
876 0 my ($tablehash) = $dbh->FETCH('ldap_tables');
877 0 ▶ return (-524) unless ($tablehash->{$table});
Branch: 1 branch
BranchTrueFalseTotal
unless $tablehash->{$table} 0 0 0
878 0 my ($base, $objfilter, $dnattbs, $allattbs, $alwaysinsert) = split(/\:/,$tablehash->{$table});
879 0 ▶ $objfilter ||= 'objectclass=*';
Condition0%0/2
$objfilter ||= "objectclass=*"
l!l
00
MC/DC0%0/1
$objfilter ||= "objectclass=*"
$objfilter
Truth table0%0/2
A
A= $objfilter
Aresult
11
00
880 0 ▶ $objfilter = "($objfilter)" unless ($objfilter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $objfilter =~ /^\(/o 0 0 0
881 0 ▶ if ($wherepart =~ /\S/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($wherepart =~ /\S/o) { } 0 0 0
882 {
883 0 $filter = $self->parse_expression ($wherepart);
884 0 ▶ $filter = '('.$filter.')' unless ($filter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $filter =~ /^\(/o 0 0 0
885 0 $filter = "(&$objfilter$filter)";
886 }
887 else
888 {
889 0 $filter = "$objfilter";
890 }
891 0 ▶ $filter = '('.$filter.')' unless ($filter =~ /^\(/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $filter =~ /^\(/o 0 0 0
892  
893 0 ▶ $data = $ldap->search(
Branch: 1 branch
BranchTrueFalseTotal
$data = $ldap->search("base", $base, "filter", $filter) or return $self->ldap_error($@, "Search failed to return object: filter=$filter (" . $data->error . ')') 0 0 0
894 base => $base,
895 filter => $filter,
896 ) or return ($self->ldap_error($@,"Search failed to return object: filter=$filter (".$data->error().")"));
897 0 my ($j) = 0;
898 0 my (@varlist) = ();
899 0 $dbh = $csr->FETCH('ldap_dbh');
900 0 my ($autocommit) = $dbh->FETCH('AutoCommit');
901 0 ▶ my ($commitqueue) = $dbh->FETCH('ldap_commitqueue') unless ($autocommit);
Branch: 1 branch
BranchTrueFalseTotal
unless $autocommit 0 0 0
902 0 ▶ while (my $entry = $data->shift_entry())
Branch: 1 branch
BranchTrueFalseTotal
if (my $entry = $data->shift_entry) 0 0 0
903 {
904 0 $dn = $entry->dn();
905 0 ▶ next unless ($dn =~ /$base$/i); #CASE-INSENSITIVITY ADDED NEXT 2: 20050416 PER PATCH BY jmorano
Branch: 1 branch
BranchTrueFalseTotal
unless $dn =~ /$base$/i 0 0 0
906 0 $r1 = $entry->delete();
907 0 ▶ if ($autocommit)
Branch: 1 branch
BranchTrueFalseTotal
if ($autocommit) { } 0 0 0
908 {
909 0 $r2 = $entry->update($ldap); #COMMIT!!!
910 0 ▶ if ($r2->is_error)
Branch: 1 branch
BranchTrueFalseTotal
if ($r2->is_error) 0 0 0
911 {
912 0 $errdetails = $r2->code . ': ' . $r2->error;
913 0 return (-523);
914 }
915 }
916 else
917 {
918 0 push (@{$commitqueue}, (\$entry, \$ldap));
919 }
920 0 ++$status;
921 }
922  
923 0 return $status;
924 }
925 else
926 {
927 0 return (-505);
928 }
929 }
930  
931 sub primary_key_info
932 0 ▶{
Subroutine primary_key_info: not called CC=4 SCAR=30.0
Pod undocumented
933 0 my ($self, $csr, $query) = @_;
934 0 my $table = $query;
935 0 $table =~ s/^.*\s+(\w+)$/$1/;
936 0 ▶ $table =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
937 0 $self->{file} = $table;
938 0 my ($dbh) = $csr->FETCH('ldap_dbh');
939 0 my $tablehash = $dbh->FETCH('ldap_tables');
940 0 ▶ return -524 unless ($tablehash->{$table});
Branch: 1 branch
BranchTrueFalseTotal
unless $tablehash->{$table} 0 0 0
941  
942 0 undef %{ $self->{types} };
943 0 undef %{ $self->{lengths} };
944 0 $self->{use_fields} = 'CAT,SCHEMA,TABLE_NAME,PRIMARY_KEY';
945 0 $self->{order} = [ 'CAT', 'SCHEMA', 'TABLE_NAME', 'PRIMARY_KEY' ];
946 0 $self->{fields}->{CAT} = 1;
947 0 $self->{fields}->{SCHEMA} = 1;
948 0 $self->{fields}->{TABLE_NAME} = 1;
949 0 $self->{fields}->{PRIMARY_KEY} = 1;
950 0 undef @{ $self->{records} };
951 0 my (@keyfields) = split(/\,\s*/o, $self->{key_fields}); #JWT: PREVENT DUP. KEYS.
952 0 ${$self->{types}}{CAT} = 'VARCHAR';
953 0 ${$self->{types}}{SCHEMA} = 'VARCHAR';
954 0 ${$self->{types}}{TABLE_NAME} = 'VARCHAR';
955 0 ${$self->{types}}{PRIMARY_KEY} = 'VARCHAR';
956 0 ${$self->{lengths}}{CAT} = 50;
957 0 ${$self->{lengths}}{SCHEMA} = 50;
958 0 ${$self->{lengths}}{TABLE_NAME} = 50;
959 0 ${$self->{lengths}}{PRIMARY_KEY} = 50;
960 0 ${$self->{defaults}}{CAT} = undef;
961 0 ${$self->{defaults}}{SCHEMA} = undef;
962 0 ${$self->{defaults}}{TABLE_NAME} = undef;
963 0 ${$self->{defaults}}{PRIMARY_KEY} = undef;
964 0 ${$self->{scales}}{PRIMARY_KEY} = 50;
965 0 ${$self->{scales}}{PRIMARY_KEY} = 50;
966 0 ${$self->{scales}}{PRIMARY_KEY} = 50;
967 0 ${$self->{scales}}{PRIMARY_KEY} = 50;
968 0 my $results;
969 0 my $keycnt = scalar(@keyfields);
970 0 ▶ while (@keyfields)
Branch: 1 branch
BranchTrueFalseTotal
if (@keyfields) 0 0 0
971 {
972 0 push (@{$results}, [0, 0, $table, shift(@keyfields)]);
973 }
974 0 unshift (@$results, $keycnt);
975 0 return $results;
976 }
977  
978 sub alter #SQL COMMAND NOT IMPLEMENTED.
979 0 ▶{
Subroutine alter: not called CC=1 SCAR=6.9
Pod undocumented
980 0 $@ = 'SQL "alter" command is not (yet) implemented!';
981 0 return 0;
982 }
983  
984 sub insert
985 0 ▶{
Subroutine insert: not called CC=8 SCAR=42.8
Pod undocumented
986 #my ($self, $query) = @_;
987 0 my ($self, $csr, $query) = @_;
988 0 my ($i, $path, $table, $columns, $values, $status);
989  
990 0 $path = $self->{path};
991 0 ▶ if ($query =~ /^insert\s+into\s+ # Keyword
Branch: 1 branch
BranchTrueFalseTotal
if ($query =~ /^insert\s+into\s+ # Keyword ($path)\s* # Table (?:\((.+?)\)\s*)? # Keys values\s* # 'values' \((.+)\)$/iox) { } 0 0 0
992 ($path)\s* # Table
993 (?:\((.+?)\)\s*)? # Keys
994 values\s* # 'values'
995 \((.+)\)$/ixo)
996 { #JWT: MAKE COLUMN LIST OPTIONAL!
997  
998 0 ($table, $columns, $values) = ($1, $2, $3);
999 0 my ($dbh) = $csr->FETCH('ldap_dbh');
1000 0 my ($tablehash) = $dbh->FETCH('ldap_tables');
1001 0 ▶ $table =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
1002 0 $self->{file} = $table;
1003 0 ▶ return (-524) unless ($tablehash->{$table});
Branch: 1 branch
BranchTrueFalseTotal
unless $tablehash->{$table} 0 0 0
1004 0 my ($base, $objfilter, $dnattbs, $allattbs, $alwaysinsert) = split(/\:/,$tablehash->{$table});
1005 0 $columns =~ s/\s//go;
1006 0 ▶ $columns ||= $allattbs;
Condition0%0/3
$columns ||= $allattbs
l!l&&r!l&&!r
000
MC/DC0%0/2
$columns ||= $allattbs
$columns $allattbs
Truth table0%0/3
A ||= B
A= $columnsB= $allattbs
ABresult
1X1
011
000
1007 0 ▶ $columns = join(',', @{ $self->{order} }) unless ($columns =~ /\S/o); #JWT
Branch: 1 branch
BranchTrueFalseTotal
unless $columns =~ /\S/o 0 0 0
1008  
1009 0 ▶ unless ($columns =~ /\S/o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($columns =~ /\S/o) 0 0 0
1010 {
1011 0 return ($self->display_error (-509));
1012 }
1013 0 $values =~ s/\\\\/\x02/go; #PROTECT "\\"
1014 0 $values =~ s/\\\'/\x03/go; #PROTECT '', AND \'.
1015  
1016 0 $values =~ s/\'(.*?)\'/
1017 0 my ($j)=$1;
1018 0 $j=~s|,|\x04|go; #PROTECT "," IN QUOTES.
1019 0 "'$j'"
1020 /eg;
1021 0 @values = split(/,/o, $values);
1022 0 $values = '';
1023 0 for $i (0..$#values)
1024 {
1025 0 $values[$i] =~ s/^\s+//o; #STRIP LEADING & TRAILING SPACES.
1026 0 $values[$i] =~ s/\s+$//o;
1027 0 $values[$i] =~ s/\x03/\'/go; #RESTORE PROTECTED SINGLE QUOTES HERE.
1028 0 $values[$i] =~ s/\x02/\\/go; #RESTORE PROTECTED SLATS HERE.
1029 0 $values[$i] =~ s/\x04/,/go; #RESTORE PROTECTED COMMAS HERE.
1030 }
1031 0 chop($values);
1032  
1033 0 $status = $self->insert_data ($csr, $base, $dnattbs, $alwaysinsert, $columns, @values);
1034  
1035 0 return $status;
1036 }
1037 else
1038 {
1039 0 return (-508);
1040 }
1041 }
1042  
1043 sub insert_data
1044 0 ▶{
Subroutine insert_data: not called CC=20 SCAR=60.4
Pod undocumented
1045 0 my ($self, $csr, $base, $dnattbs, $alwaysinsert, $column_string, @values) = @_;
1046 0 my (@columns, @attblist, $loop, $column, $j, $k);
1047 0 $column_string =~ tr/A-Z/a-z/;
1048 0 $dnattbs =~ tr/A-Z/a-z/;
1049 0 @columns = split (/\,/o, $column_string);
1050  
1051 0 ▶ if ($#columns = $#values)
Branch: 1 branch
BranchTrueFalseTotal
if ($#columns = $#values) { } 0 0 0
1052 {
1053 0 my $dn = '';
1054 0 my @t = split(/,/o, $dnattbs);
1055 0 ▶ while (@t)
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 0 0 0
1056 {
1057 0 $j = shift (@t);
1058 0 ▶J1: for (my $i=0;$i<=$#columns;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#columns) 0 0 0
1059 {
1060 0 ▶ if ($columns[$i] eq $j)
Branch: 1 branch
BranchTrueFalseTotal
if ($columns[$i] eq $j) 0 0 0
1061 {
1062 0 $dn .= $columns[$i] . '=';
1063 0 ▶ if ($values[$i] =~ /\Q$self->{ldap_inseparator}\E/)
Branch: 1 branch
BranchTrueFalseTotal
if ($values[$i] =~ /\Q$self->{'ldap_inseparator'}\E/) { } 0 0 0
1064 {
1065 0 $dn .= (split(/\Q$self->{ldap_inseparator}\E/,$values[$i]))[0];
1066 }
1067 else
1068 {
1069 0 $dn .= $values[$i];
1070 }
1071 0 $dn .= ', ';
1072 0 last J1;
1073 }
1074 }
1075 }
1076 0 $dn =~ s/\'//go;
1077 0 $dn .= $base;
1078 0 ▶ for (my $i=0;$i<=$#columns;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#columns) 0 0 0
1079 {
1080 0 @l = split(/\Q$self->{ldap_inseparator}\E/,$values[$i]);
1081 0 ▶ while (@l)
Branch: 1 branch
BranchTrueFalseTotal
if (@l) 0 0 0
1082 {
1083 0 $j = shift(@l);
1084 0 $j =~ s/^\'//o;
1085 0 $j =~ s/([^\\\'])\'$/$1/;
1086 0 ▶ unless (!length($j) || $j eq "'" || $columns[$i] eq 'dn')
Branch: 1 branch
BranchTrueFalseTotal
unless (not length $j or $j eq "'" or $columns[$i] eq "dn") 0 0 0
Condition0%0/6
not length $j or $j eq "'" or $columns[$i] eq "dn"
l!l&&r!l&&!r
000
not length $j or $j eq "'"
l!l&&r!l&&!r
000
MC/DC0%0/3
not length $j or $j eq "'" or $columns[$i] eq "dn"
not length $j $j eq "'" $columns[$i] eq "dn"
Truth table0%0/4
not(A) or B or C
A= not length $jB= $j eq "'"C= $columns[$i] eq "dn"
ABCresult
1XX1
01X1
0011
0000
1087 {
1088 0 ▶ $j = "'" if ($j eq "''");
Branch: 1 branch
BranchTrueFalseTotal
if $j eq "''" 0 0 0
1089 0 push (@attblist, $columns[$i]);
1090 0 push (@attblist, $j);
1091 }
1092 }
1093 }
1094 # $alwaysinsert .= ',' . $base; #CHGD TO NEXT 200780719 PER REQUEST.
1095 0 ▶ $alwaysinsert .= ',' . $base if ($self->{ldap_appendbase2ins});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ldap_appendbase2ins"} 0 0 0
1096 0 my ($i1, $found, $col, $vals, $j);
1097 0 @_ = split(/\,\s*/o, $alwaysinsert);
1098 0 ▶ while (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1099 {
1100 0 ($col, $vals) = split(/\=/o, shift);
1101 0 @l = split(/\Q$self->{ldap_inseparator}\E/, $vals);
1102 0 ▶VALUE: for (my $i=0;$i<=$#l;$i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#l) 0 0 0
1103 {
1104 0 ▶ for ($j=0;$j<=$#attblist;$j+=2)
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#attblist) 0 0 0
1105 {
1106 0 ▶ if ($attblist[$j] eq $col)
Branch: 1 branch
BranchTrueFalseTotal
if ($attblist[$j] eq $col) 0 0 0
1107 {
1108 0 ▶ next VALUE if ($attblist[$j+1] eq $l[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $attblist[$j + 1] eq $l[$i] 0 0 0
1109 }
1110 }
1111 0 push (@attblist, $col);
1112 0 push (@attblist, $l[$i]);
1113 }
1114 }
1115 0 my ($ldap) = $csr->FETCH('ldap_ldap');
1116  
1117 0 my $entry = Net::LDAP::Entry->new;
1118 0 $entry->dn($dn);
1119  
1120 0 my $result = $entry->add(@attblist);
1121 0 $_ = $entry->dn();
1122  
1123 0 my ($dbh) = $csr->FETCH('ldap_dbh');
1124 0 my ($autocommit) = $dbh->FETCH('AutoCommit');
1125 0 ▶ if ($autocommit)
Branch: 1 branch
BranchTrueFalseTotal
if ($autocommit) { } 0 0 0
1126 {
1127 0 $r2 = $entry->update($ldap); #COMMIT!!!
1128 0 ▶ if ($r2->is_error)
Branch: 1 branch
BranchTrueFalseTotal
if ($r2->is_error) 0 0 0
1129 {
1130 0 $errdetails = $r2->code . ': ' . $r2->error;
1131 0 return (-523);
1132 }
1133 }
1134 else
1135 {
1136 0 my ($commitqueue) = $dbh->FETCH('ldap_commitqueue');
1137 0 push (@{$commitqueue}, (\$entry, \$ldap));
1138 }
1139  
1140 0 return (1);
1141 }
1142 else
1143 {
1144 0 $errdetails = "$#columns != $#values"; #20000114
1145 0 return (-509);
1146 }
1147 }
1148  
1149 sub create #SQL COMMAND NOT IMPLEMENTED.
1150 0 ▶{
Subroutine create: not called CC=1 SCAR=6.9
Pod undocumented
1151 0 $@ = 'SQL "create" command is not (yet) implemented!';
1152 0 return 0;
1153 }
1154  
1155 sub drop #SQL COMMAND NOT IMPLEMENTED.
1156 0 ▶{
Subroutine drop: not called CC=1 SCAR=6.9
Pod undocumented
1157 0 $@ = 'SQL "drop" command is not (yet) implemented!';
1158 0 return 0;
1159 }
1160  
1161 sub pscolfn
1162 0 ▶{
Subroutine pscolfn: not called CC=7 SCAR=40.3
Pod undocumented
1163 0 my ($self,$id) = @_;
1164 0 ▶ return $id unless ($id =~ /CURVAL|NEXTVAL|ROWNUM/);
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /CURVAL|NEXTVAL|ROWNUM/ 0 0 0
1165 0 my ($value) = '';
1166 0 my ($seq_file,$col) = split(/\./o, $id);
1167 0 $seq_file = $self->get_path_info($seq_file) . '.seq';
1168  
1169 0 ▶ $seq_file =~ tr/A-Z/a-z/ unless ($self->{CaseTableNames}); #JWT:TABLE-NAMES ARE NOW CASE-INSENSITIVE!
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CaseTableNames"} 0 0 0
1170 0 ▶ open (FILE, "<$seq_file") || return (-511);
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$seq_file" or return -511 0 0 0
1171 0 $x = <FILE>;
1172 #chomp($x);
1173 0 $x =~ s/\s+$//o; #20000113
1174 0 ($incval, $startval) = split(/\,/o, $x);
1175 0 close (FILE);
1176 0 ▶ if ($id =~ /NEXTVAL/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /NEXTVAL/o) 0 0 0
1177 {
1178 0 ▶ open (FILE, ">$seq_file") || return (-511);
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$seq_file" or return -511 0 0 0
1179 0 ▶ $incval += ($startval || 1);
Condition0%0/2
$startval || 1
l!l
00
MC/DC0%0/1
$startval || 1
$startval
Truth table0%0/2
A
A= $startval
Aresult
11
00
1180 0 print FILE "$incval,$startval\n";
1181 0 close (FILE);
1182 }
1183 0 $value = $incval;
1184 0 return $value;
1185 }
1186  
1187 sub SYSTIME
1188 0 ▶{
Subroutine SYSTIME: not called CC=1 SCAR=6.9
Pod undocumented
1189 0 return time;
1190 }
1191  
1192 sub NUM
1193 0 ▶{
Subroutine NUM: not called CC=1 SCAR=6.9
Pod undocumented
1194 0 return shift;
1195 }
1196  
1197 sub NULL
1198 0 ▶{
Subroutine NULL: not called CC=1 SCAR=6.9
Pod undocumented
1199 0 return '';
1200 }
1201  
1202 1 1;
↑ Summary DBD/LDAP.pm »