blib/lib/blx/xsdsql/xml/reader.pm untested

filter: Statementstmt 0.0% 0 / 659 Branchbran 0.0% 0 / 242 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 38 Podpod 0.0% 0 / 33 totaltotal 0.0% 0 / 1002 CC 122 SCAR 61.1
CC
122
Cov
0%
_start_node
1640.0
_end_node
156.0
_resolve_path
132.0
CRAP 451.1
1 package blx::xsdsql::xml::reader;
2  
3 use strict; # use strict is for PBP
4 use Filter::Include;
5 include blx::xsdsql::include;
6 #line 7
7 use XML::Parser;
8  
9 use blx::xsdsql::ut::ut qw(nvl);
10 use base qw(blx::xsdsql::xml::base);
11  
12 sub _decode {
13 my $self=shift;
14 return $_[0] if scalar(@_) <= 1;
15 @_;
16 }
17 sub _debug_stack {
18 return $_[0] unless $_[0]->{DEBUG};
19 my ($self,$n,%params)=@_;
20 my $stack=nvl($params{STACK},$self->{STACK});
21 $params{INDEX}= [ (0..scalar(@$stack) - 1) ] unless defined $params{INDEX};
22 $params{INDEX}=[ $params{INDEX} ] if ref($params{INDEX}) eq '';
23 for my $i(@{$params{INDEX}}) {
24 my @line=();
25 my $h=$stack->[$i];
26 for my $k(sort keys %$h) {
27 my $v=$h->{$k};
28 my $r=ref($v);
29 if ($r =~/::binding$/) {
30 push @line,"$k: EXECUTE ".($v->is_execute_pending ? 'PENDING' : 'COMPLETED').' for table '.$v->get_binding_table->get_sql_name;
31 }
32 elsif ($r eq '') {
33 if (defined $v) {
34 push @line,"$k => $v";
35 }
36 else {
37 push @line,"$k => undef";
38 }
39 }
40 else {
41 push @line,"$k => $r";
42 }
43 }
44 $self->_debug($n,@line);
45 }
46 $self;
47 }
48  
49 sub _insert_seq_inc {
50 my ($p,%params)=@_;
51 my $colv=($p->get_binding_columns(PK_ONLY => 1))[1];
52 $p->insert_binding(undef,TAG => $params{TAG},NO_PK => 1);
53 $p->bind_column($colv->{COL},$colv->{VALUE} + 1,TAG => $params{TAG});
54 $p;
55 }
56  
57 sub _resolve_path {
58 my ($self,$path,%params)=@_;
59 my $schema=$self->{SCHEMA};
60 my $tc=undef;
61 my $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
62 unless (defined $stack_frame) { # is the root path
63 my ($ns)=$path=~/^\/([^:]+):/;
64 my @schemas=($schema);
65 unless (defined $self->{NSPREFIXES}) {
66 affirm { defined $params{NODE_ATTRS} } "param NODE_ATTRS not set";
67 my %namespaces=map {
68 my @out=();
69 @out=($1,$params{NODE_ATTRS}->{$_}) if /^xmlns:([^:]+)/;
70 @out;
71 } keys %{$params{NODE_ATTRS}};
72 $self->{NSPREFIXES}=\%namespaces;
73 }
74 if (defined $ns) { # path as namespace prefix
75 my $namespace=$self->_find_namespace_from_abbr($ns);
76 affirm { defined $namespace } "$ns: no such namespace from this namespace abbr";
77 my @child_schemas=$schema->find_schemas_from_namespace($namespace);
78 affirm { scalar(@child_schemas) } "$namespace: no such schema from this namespace";
79 @schemas=@child_schemas;
80 }
81 else {
82 my $ns=$params{NODE_ATTRS}->{xmlns};
83 my @child_schemas=$schema->find_schemas_from_namespace($ns);
84 affirm { scalar(@child_schemas) } nvl($ns,'<global_namespace>').": no such schema from this namespace";
85 @schemas=@child_schemas;
86 }
87 for my $sc(@schemas) {
88 $tc=$sc->resolve_path($path);
89 if (defined $tc) {
90 $self->{_PARAMS}->{CURRENT_SCHEMA}=$sc;
91 last;
92 }
93 }
94 affirm { defined $tc } "$path: path not resolved";
95 }
96 else {
97 $tc=$self->{_PARAMS}->{CURRENT_SCHEMA}->resolve_path($path);
98 affirm { defined $tc } "$path: path not resolved";
99 }
100 if ($self->{DEBUG}) {
101 my $tag=$params{TAG};
102 if (ref($tc) eq 'HASH') {
103 $self->_debug($tag,$path,'mapping to column',$tc->{C}->get_full_name);
104 }
105 elsif (ref($tc) eq 'ARRAY') {
106 $self->_debug(
107 $tag
108 ,$path
109 ,"mapping to tables\n"
110 ,sub {
111 my @out=();
112 for my $i(0..scalar(@$tc) - 1) {
113 my $t=$tc->[$i];
114 push @out,
115 "\t\t\t"
116 .$t->{T}->get_sql_name
117 .(defined $t->{C} ? '.'.$t->{C}->get_sql_name : '')
118 .($i == scalar(@$tc) - 1 ? '' : "\n");
119 }
120 return @out;
121 }->()
122 );
123 }
124 else {
125 croak ref($tc).": not a hash or array";
126 }
127 }
128 $tc;
129 }
130  
131 sub _get_stack_frame {
132 my ($self,%params)=@_;
133 return unless scalar(@{$self->{STACK}});
134 my $s=$self->{STACK}->[-1];
135 if ($self->{DEBUG} && !$params{NOT_DEBUG}) {
136 my @a=map {
137 my $key=$_;
138 my $p=$s->{$key};
139 my @out=("$key => ");
140 if (ref($p) =~/::binding$/) {
141 push @out,"'".$p->get_binding_table->get_sql_name."'";
142 }
143 elsif (ref($p) eq '') {
144 push @out,nvl($p,'<undef>');
145 }
146 elsif (ref($p)=~/::/) {
147 push @out,"'".ref($p)."'";
148 }
149 elsif (grep($key eq $_,qw(INTERNAL_REFERENCE EXTERNAL_REFERENCE UNPATH_PREPARED PREPARED STACK))) {
150 push @out,ref($p);
151 }
152 else {
153 my $v=Dumper($p);
154 $v=~s/^\$VAR1\s+=\s+//;
155 $v=join(" ",map {
156 my $v=$_;
157 $v=~s/^\s+//;
158 $v=~s/\s+$//;
159 $v;
160 } split("\n",$v));
161 push @out,("'$v'");
162 }
163 @out;
164 } sort keys %$s;
165 $self->_debug($params{TAG},'GET STACK',@a);
166 }
167 $s;
168 }
169  
170 sub _prepared_insert {
171 my ($self,$table,%params)=@_;
172 affirm { defined $table } "param 1 not set";
173 my $sqlname=$table->get_sql_name;
174 $self->{PREPARED}->{$sqlname}->{INSERT}=$self->{BINDING}->get_clone
175 unless defined $self->{PREPARED}->{$sqlname}->{INSERT};
176 $self->{PREPARED}->{$sqlname}->{INSERT}->insert_binding(
177 $table
178 ,TAG => $params{TAG}
179 ,NO_PENDING_CHECK => $params{NO_PENDING_CHECK}
180 ,PK_ID_VALUE => $params{PK_ID_VALUE}
181 );
182 $self->{PREPARED}->{$sqlname}->{INSERT};
183 }
184  
185 sub _push {
186 my ($self,$v,%params)=@_;
187 if ($self->{DEBUG}) {
188 $self->_debug($params{TAG},'PUSH STACK'
189 ,sub {
190 my $p=$v->{PREPARED};
191 my @a= $p
192 ? ("table ",$p->get_binding_table->get_sql_name)
193 : ();
194 affirm {defined $v->{PATH} } "no PATH in push";
195 push @a," - path ".$v->{PATH};
196 return @a;
197 }->());
198 }
199 push @{$self->{STACK}},$v;
200 $v;
201 }
202  
203 sub _pop {
204 my ($self,%params)=@_;
205 affirm { scalar(@{$self->{STACK}}) > 0 } "empty stack ";
206 if ($self->{DEBUG}) {
207 my $v=$self->{STACK}->[-1];
208 $self->_debug($params{TAG},'POP STACK'
209 ,sub {
210 my $p=$v->{PREPARED};
211 my @a=defined $p
212 ? ("table ",$p->get_binding_table->get_sql_name)
213 : ();
214 push @a," - path ".$v->{PATH};
215 return @a;
216 }->());
217  
218 my @p=$self->_execute($v,%params,CHECK_ONLY => 1);
219 my $e=0;
220 for my $p(@p) {
221 if ($p->is_execute_pending) {
222 $self->_debug($params{TAG},'EXECUTE PENDING - table ',$p->get_binding_table->get_sql_name,' has execute pending');
223 ++$e;
224 }
225 }
226 affirm { $e == 0 } "execute pending\nkeys ".join(' ',keys(%$v));
227 }
228 my $stack=pop @{$self->{STACK}};
229 scalar(@{$self->{STACK}}) == 0 ? undef : $self->{STACK}->[-1];
230 }
231  
232 sub _is_equal {
233 my ($self,$t1,$t2,%params)=@_;
234 affirm { defined $t1 } "param 1 not set";
235 affirm { defined $t2 } "param 2 not set";
236 my $r=$t1 == $t2 #same point r
237 || $t1->get_sql_name eq $t2->get_sql_name ? 1 : 0;
238 return $r unless $self->{DEBUG};
239 $self->_debug($params{TAG},'not equal ',$t1->get_sql_name,' <==> ',$t2->get_sql_name)
240 unless $r;
241 $r;
242 }
243  
244 sub _execute {
245 my ($self,$p,%params)=@_;
246 my $r=ref($p);
247 my @out=();
248 if ($r eq 'HASH') {
249 for my $v(values %$p) {
250 push @out,$self->_execute($v,%params);
251 }
252 }
253 elsif ($r =~ /::binding$/) {
254 if ($params{CHECK_ONLY}) {
255 return ($p);
256 }
257 else {
258 if ($params{IGNORE_NOT_PENDING}) {
259 $p->execute(%params) if $p->is_execute_pending;
260 }
261 else {
262 $p->execute(%params);
263 }
264 }
265 }
266 @out;
267 }
268  
269 sub _unpath_table {
270 my ($self,$stack_frame,$tc,%params)=@_;
271 affirm { $tc->{T}->is_unpath } $tc->{T}->get_sql_name."table is not an unpath sequence table";
272 my $prepared_tag=$tc->{T}->get_sql_name;
273 if ($stack_frame->{UNPATH_PREPARED}->{$prepared_tag}) {
274 if ($stack_frame->{UNPATH_COLSEQ}->{$prepared_tag} >= $tc->{C}->get_column_sequence) {
275 $stack_frame->{UNPATH_PREPARED}->{$prepared_tag}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
276 _insert_seq_inc($stack_frame->{UNPATH_PREPARED}->{$prepared_tag},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
277 }
278 }
279 else {
280 my $sth=$self->_prepared_insert($tc->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
281 my ($id)=$sth->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
282 my $trf=$tc->{STACK}->[-1];
283 my $p=$trf->{T}->is_unpath
284 ? $stack_frame->{UNPATH_PREPARED}->{$trf->{T}->get_sql_name}
285 : $stack_frame->{PREPARED};
286  
287 $p->bind_column($trf->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
288 $stack_frame->{UNPATH_PREPARED}->{$prepared_tag}=$sth;
289 }
290 $stack_frame->{UNPATH_COLSEQ}->{$prepared_tag}=$tc->{C}->get_column_sequence;
291 $stack_frame->{UNPATH_PREPARED}->{$prepared_tag};
292 }
293  
294 sub _bind_mixed_value {
295 my ($self,$stack_frame,%params)=@_;
296 affirm { defined $stack_frame->{MIXED} } " param MIXED not set into stack frame";
297 affirm { defined $params{TAG} } " param TAG not set into stack frame";
298 if (defined (my $mixed=$stack_frame->{MIXED})) {
299 my $count=$mixed->{COUNT}++;
300 if (length($mixed->{VALUE})) {
301 my $table=$stack_frame->{PREPARED}->get_binding_table;
302 my $col=$table->find_column_by_mixed_count($count);
303 affirm { defined $col } "not mixed column having count $count in table ".$table->get_sql_name;
304 if ($self->{DEBUG}) {
305 my $v=$mixed->{VALUE};
306 $v=~s/\n/\\n/g;
307 $self->_debug(undef," starting number $count mixed column with value '$v'");
308 }
309 $stack_frame->{PREPARED}->bind_column($col,$mixed->{VALUE},TAG => $params{TAG});
310 $mixed->{VALUE}='';
311 }
312 }
313 $self;
314 }
315  
316 sub _xmldecl_node {
317 my ($expect,@decl)=@_;
318 my $self=$expect->{LOAD_INSTANCE};
319 $self->{_XMLDECL}=\@decl;
320 undef;
321 }
322
323 sub _start_node {
324 my ($expect,$node,%node_attrs)=@_;
325 my $self=$expect->{LOAD_INSTANCE};
326 my $current_path=$self->_decode('/'.join('/',(@{$expect->{Context}},($node))));
327 $self->_debug(undef,'> (start path)',$current_path);
328 my $tc=_resolve_path($self,$current_path,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},NODE_ATTRS => \%node_attrs);
329 my $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
330 unless (defined $stack_frame) { # prepare the root table if the stack is empty
331 $self->{_XMLDECL}=[] unless defined $self->{_XMLDECL};
332 $self->{_XMLDECL}->[1]='UTF-8' unless defined $self->{_XMLDECL}->[1];
333 $self->{_XMLDECL}->[1]='UTF-8' if $self->{_XMLDECL}->[1]=~/utf[\-]{0,1}8/i;
334 $self->{BINDING}->set_attrs_value(DATA_LOCALE => $self->{_XMLDECL}->[1]); # for now it's not used
335 binmode(STDERR,':encoding(UTF-8)');
336 my $root_table=ref($tc) eq 'ARRAY' ? $tc->[0]->{T} : $tc->{T};
337 affirm { defined $root_table } "the root table is not set";
338 affirm { $root_table->is_root_table } $root_table->get_sql_name.": is not a root table";
339 affirm { defined $self->{_ROOT_ID} } "_ROOT_ID not set";
340 my $insert=$self->_prepared_insert($root_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},PK_ID_VALUE => $self->{_ROOT_ID});
341 $self->_push({ PREPARED => $insert,TABLE => $root_table,PATH => $current_path },TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
342 $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
343 }
344 if (ref($tc) eq 'ARRAY') { #is a path for a table
345 if (scalar(@$tc) == 2) {
346 $self->_bind_mixed_value($stack_frame,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if defined $stack_frame->{MIXED};
347 my ($table,$parent_table,$parent_column)=($tc->[-1]->{T},$tc->[0]->{T},$tc->[0]->{C});
348 if ($parent_column->get_max_occurs > 1) {
349 my $prepared_tag=$parent_column->get_sql_name;
350 if ($stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag}) {
351 _insert_seq_inc($stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #increment the value of the seq column
352 $self->_bind_node_attrs($stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag},\%node_attrs,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if scalar keys %node_attrs;
353 }
354 else {
355 my $p=$self->_prepared_insert($parent_column->get_table_reference,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
356 $self->_bind_node_attrs($p,\%node_attrs,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if scalar keys %node_attrs;
357 my ($id)=$p->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
358 $stack_frame->{PREPARED}->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
359 $stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag}=$p;
360 }
361 my %v=(PREPARED => $self->_get_prepared_insert($table),PATH => $current_path);
362 if ($table->is_mixed) {
363 $v{MIXED}={ COUNT => 0,VALUE => ''};
364 $self->_debug(undef,' init MIXED into frame stack for table ',$table->get_sql_name);
365 }
366 $stack_frame=$self->_push(\%v,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
367 }
368 else {
369 $self->_prepared_insert($table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
370 my $p=$self->_get_prepared_insert($table);
371 my ($id)=$p->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
372 $stack_frame->{PREPARED}->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
373 $self->_bind_node_attrs($p,\%node_attrs,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if scalar keys %node_attrs;
374 my %v=(PREPARED => $p);
375 if ($table->is_mixed) {
376 $v{MIXED}={ COUNT => 0,VALUE => ''};
377 $self->_debug(undef,' init MIXED into frame stack for table ',$table->get_sql_name);
378 }
379 $v{PATH}=$current_path;
380 $stack_frame=$self->_push(\%v,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
381 }
382 }
383 elsif (scalar(@$tc) == 3) {
384 my ($gran_parent_table,$gran_parent_column)=($tc->[-3]->{T},$tc->[-3]->{C});
385 my ($parent_table,$parent_column)=($tc->[-2]->{T},$tc->[-2]->{C});
386 my ($curr_table,$curr_column)=($tc->[-1]->{T},$tc->[-1]->{C});
387 my $parent_tag=$parent_table->get_sql_name;
388
389 if ($parent_table->is_unpath) {
390 if (my $p=$stack_frame->{UNPATH_PREPARED}->{$parent_tag}) {
391 if ($stack_frame->{UNPATH_COLSEQ}->{$parent_tag} >= $parent_column->get_xsd_seq) {
392 $p->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
393 _insert_seq_inc($p,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
394 }
395 }
396 else {
397 my $sth=$self->_prepared_insert($parent_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
398 my ($id)=$sth->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
399 $stack_frame->{PREPARED}->bind_column($gran_parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
400 $stack_frame->{UNPATH_PREPARED}->{$parent_tag}=$sth;
401 }
402 $stack_frame->{UNPATH_COLSEQ}->{$parent_tag}=$parent_column->get_xsd_seq;
403 }
404 else {
405 $self->_debug(undef,'(W) ',$curr_table->get_sql_name,': table is not an unpath table');
406 }
407  
408 if ($self->_is_equal($stack_frame->{PREPARED}->get_binding_table,$curr_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})) {
409 if ($stack_frame->{COLSEQ} >= $curr_column->get_column_sequence) {
410 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
411 _insert_seq_inc($stack_frame->{PREPARED},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
412 }
413 else {
414 croak "not implemented\n";
415 }
416 }
417 else {
418 my $prepared_tag=$parent_column->get_sql_name;
419 if ($parent_column->get_max_occurs > 1 && $stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag}) {
420 _insert_seq_inc($stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #increment the value of the seq column
421 my $curr_tag=$curr_table->get_sql_name;
422 $stack_frame=$self->_push({ PREPARED => $self->{PREPARED}->{$curr_tag}->{INSERT},PATH => $current_path},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
423 }
424 else {
425 my $sth=$self->_prepared_insert($curr_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
426 my ($id)=$sth->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
427 if ($stack_frame->{UNPATH_PREPARED}) {
428 $stack_frame->{UNPATH_PREPARED}->{$parent_tag}->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
429 }
430 else {
431 $stack_frame->{PREPARED}->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
432 $stack_frame->{EXTERNAL_REFERENCE}->{$prepared_tag}=$sth if $parent_column->get_max_occurs > 1;
433 }
434 $stack_frame=$self->_push({ PREPARED => $sth,PATH => $current_path },TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
435 }
436 }
437 }
438 else {
439 croak $current_path.": tc return < 2 or > 3 elements \n";
440 }
441 }
442 elsif ($tc->{C}->is_internal_reference) { #the column is an occurs of simple types
443 $self->_debug(undef,$tc->{C}->get_full_name,' has internal reference');
444 my $prepared_tag=$tc->{C}->get_sql_name;
445 if (defined (my $prep=$stack_frame->{INTERNAL_REFERENCE}->{$prepared_tag})) {
446 _insert_seq_inc($prep->{PREPARED},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #increment the value of the seq column
447 $prep->{MIXED}->{COUNT}=0 if defined $prep->{MIXED};
448 }
449 else {
450 $self->_bind_mixed_value($stack_frame,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if defined $stack_frame->{MIXED};
451 my $p=$self->_prepared_insert($tc->{C}->get_table_reference,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
452 my ($id)=$p->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
453 $self->_bind_node_attrs($p,\%node_attrs,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if scalar keys %node_attrs;
454 unless($self->_is_equal($stack_frame->{PREPARED}->get_binding_table,$tc->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})) {
455 if ($tc->{T}->is_unpath) {
456 my $sth=$self->_unpath_table($stack_frame,$tc);
457 $sth->bind_column($tc->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
458 }
459 elsif ($tc->{T}->is_group_type) {
460 $stack_frame=$self->_start_group_type($tc);
461 $stack_frame->{PREPARED}->bind_column($tc->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
462 }
463 else {
464 $self->_debug_stack(__LINE__,INDEX => -1);
465 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
466 while(1) {
467 $stack_frame=$self->_pop(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
468 last if $self->_is_equal($stack_frame->{PREPARED}->get_binding_table,$tc->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
469 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
470 }
471 $stack_frame->{PREPARED}->bind_column($tc->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #if is set fail on test 004
472 }
473 }
474 else {
475 $stack_frame->{PREPARED}->bind_column($tc->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
476 }
477 my %v=(PREPARED => $p);
478 if ($p->get_binding_table->is_mixed) {
479 $v{MIXED}={ COUNT => 0,VALUE => ''};
480 $self->_debug(undef,' init MIXED into frame stack for table ',$p->get_binding_table->get_sql_name);
481 }
482 $stack_frame->{INTERNAL_REFERENCE}->{$prepared_tag}=\%v;
483 }
484 $stack_frame->{VALUE}='';
485 }
486 elsif (my $table_ref=$tc->{C}->get_table_reference) {
487 croak $current_path.": ref to '".$tc->{C}->get_path_reference."' not implemented\n";
488 }
489 else { #normal data column
490 $self->_bind_mixed_value($stack_frame,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if defined $stack_frame->{MIXED};
491 $self->_debug(undef,' starting column',$tc->{C}->get_full_name);
492 $stack_frame->{VALUE}='';
493  
494 if ($tc->{T}->is_unpath) {
495 $self->_debug(undef,'elab unpath table',$tc->{T}->get_sql_name);
496 my $sth=$self->_unpath_table($stack_frame,$tc);
497 }
498 elsif ($tc->{T}->is_group_type) {
499 $self->_debug(undef,'elab group type table',$tc->{T}->get_sql_name);
500 $stack_frame=$self->_start_group_type($tc);
501 }
502 else {
503 #empty
504 }
505 $self->_bind_node_attrs($stack_frame->{PREPARED},\%node_attrs,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if scalar keys %node_attrs;
506 }
507 undef;
508 } # Start
509  
510
511 sub _end_node {
512 my $self=$_[0]->{LOAD_INSTANCE};
513 my $current_path=$self->_decode('/'.join('/',(@{$_[0]->{Context}},($_[1]))));
514 $self->_debug(undef,'< (end path)',$current_path,"\n");
515 my $tc=_resolve_path($self,$current_path,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
516 my $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
517 affirm { defined $stack_frame } "stack frame not set";
518 if (ref($tc) eq 'ARRAY') { #path ref a table
519 my ($parent_table,$parent_column)=($tc->[-2]->{T},$tc->[-2]->{C});
520 delete $stack_frame->{INTERNAL_REFERENCE}; #for execute in error
521 delete $stack_frame->{EXTERNAL_REFERENCE}; #for execute in error
522 $self->_bind_mixed_value($stack_frame,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}) if defined $stack_frame->{MIXED};
523 $self->_execute($stack_frame,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},IGNORE_NOT_PENDING => 1);
524 if ($stack_frame->{PREPARED}->get_binding_table->is_group_type) {
525 while(1) {
526 $stack_frame=$self->_pop(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
527 last if $self->_is_equal($stack_frame->{PREPARED}->get_binding_table,$tc->[0]->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
528 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
529 }
530 }
531 else {
532 $stack_frame=$self->_pop(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
533 }
534 }
535 elsif ($tc->{C}->is_internal_reference) { #the column is an occours of simple types
536 my $prepared_tag=$tc->{C}->get_sql_name;
537 my $sth=$stack_frame->{INTERNAL_REFERENCE}->{$prepared_tag}->{PREPARED};
538 my $value_column_idx=$sth->get_valuecol_idx;
539 affirm { defined $value_column_idx } $sth->{BINDING_TABLE}->get_sql_name.": not has a VALUE_COL column";
540 my $value_column=(($sth->get_binding_columns)[$value_column_idx])->{COL};
541 $sth->bind_column($value_column,$stack_frame->{VALUE},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
542 if (defined (my $mixed=$stack_frame->{INTERNAL_REFERENCE}->{$prepared_tag}->{MIXED})) {
543 $mixed->{VALUE}=delete $stack_frame->{MIXED}->{VALUE};
544 $self->_bind_mixed_value($stack_frame->{INTERNAL_REFERENCE}->{$prepared_tag},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
545 }
546 $sth->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
547 delete $stack_frame->{VALUE};
548 }
549 elsif (my $table_ref=$tc->{C}->get_table_reference) {
550 croak $current_path.": ref to ".$tc->{C}->get_path_reference." not implemented";
551 }
552 else { #normal data column
553 $self->_debug(undef,'ending column',$tc->{C}->get_full_name);
554
555 if ($tc->{T}->is_unpath) {
556 my $prepared_tag=$tc->{T}->get_sql_name;
557 $stack_frame->{UNPATH_PREPARED}->{$prepared_tag}->bind_column($tc->{C},$stack_frame->{VALUE},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
558 }
559 else {
560 if ($stack_frame->{STACK}) {
561 my $p=$stack_frame->{STACK_INDEX};
562 for my $i($p..scalar(@{$stack_frame->{STACK}}) - 1) {
563 my $e=$stack_frame->{STACK}->[$i];
564 if ($e->{STH}->is_execute_pending) {
565 $e->{STH}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
566 }
567 else {
568 $self->_debug(undef,$e->{STH}->get_binding_table->get_sql_name,': execute non pending');
569 }
570 }
571 }
572 my $value=delete $stack_frame->{VALUE};
573 while (!$self->_is_equal($tc->{T},$stack_frame->{PREPARED}->get_binding_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})) { #
574 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
575 $stack_frame=$self->_pop(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
576 }
577 $stack_frame->{PREPARED}->bind_column($tc->{C},$value,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
578 }
579 }
580 if (scalar(@{$self->{STACK}}) == 1) { # is the frame of the root table
581 $stack_frame->{PREPARED}->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
582 $self->{ID}=($stack_frame->{PREPARED}->get_binding_values)[0];
583 $self->_debug(undef,'root row inserted with id ',$self->{ID});
584 $self->_pop;
585 delete $self->{NSPREFIXES}; #are cached
586 delete $self->{_PARAMS}->{CURRENT_SCHEMA}; #are cached
587 }
588 undef;
589 } #End
590  
591 sub _char_node {
592 my $self=$_[0]->{LOAD_INSTANCE};
593 return if scalar(@{$self->{STACK}}) < 1;
594 my ($path,$value)=($self->_decode('/'.join('/',@{$_[0]->{Context}})),$self->_decode($_[1]));
595 my $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},NOT_DEBUG => 1);
596 if (defined $stack_frame->{VALUE}) {
597 $stack_frame->{VALUE}.=$value;
598 }
599 elsif (defined (my $mixed=$stack_frame->{MIXED})) {
600 if ($self->{DEBUG}) {
601 my $v=$value;
602 $v=~s/\n/\\n/g;
603 $self->_debug(undef,"value of mixed node: '$v'");
604 }
605 $mixed->{VALUE}.=$value;
606 }
607 undef;
608 }
609  
610  
611  
612 sub _doctype_node {
613 my ($expect,$name,$sysid,$pubid,$internal,@dummy)=@_;
614 $internal=$internal ? 1: 0;
615 my $self=$expect->{LOAD_INSTANCE};
616 affirm { defined $self->{_ROOT_ID} } "_ROOT_ID not set";
617 my $extra_tables=$self->{EXTRA_TABLES};
618 my $table=$extra_tables->get_extra_table('DOCTYPE_TABLE');
619 my $sth=$self->_prepared_insert($table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},PK_ID_VALUE => $self->{_ROOT_ID});
620 my $cols=$table->get_columns;
621 my @values=($name,$sysid,$pubid,$internal);
622 my $id_colseq=($table->get_pk_columns)[0]->get_column_sequence;
623 affirm { defined $id_colseq } "the table ".$table->get_sql_name." not have ID pk column";
624 for my $i(0..scalar(@values) - 1) {
625 $sth->bind_column($cols->[$id_colseq + 1 + $i],$values[$i]);
626 }
627 $sth->execute;
628 $table=$extra_tables->get_extra_table('DTDSEQ_TABLE');
629 $cols=$table->get_columns;
630 $self->{PREPARED_DTD_NODE_DTDSEQ_TABLE}=$self->_prepared_insert($table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},PK_ID_VALUE => $self->{_ROOT_ID});
631 undef;
632 }
633  
634 sub _dtd_node {
635 my ($expect,$type,@values)=@_;
636 my $self=$expect->{LOAD_INSTANCE};
637 my $extra_tables=$self->{EXTRA_TABLES};
638 my $prepseq=$self->{PREPARED_DTD_NODE_DTDSEQ_TABLE};
639 affirm { defined $prepseq } "key PREPARED_DTD_NODE_DTDSEQ_TABLE not set\n";
640 my $table=$extra_tables->get_extra_table('DTDSEQ_TABLE');
641 my $cols=$table->get_columns;
642 my $seq_colseq=($table->get_pk_columns)[1]->get_column_sequence;
643 affirm { defined $seq_colseq } "the table ".$table->get_sql_name." not have SEQ pk column";
644 $prepseq->bind_column($cols->[$seq_colseq + 1],$type);
645 $prepseq->execute;
646
647 $table=$extra_tables->get_extra_table($type);
648 my ($id,$seq)=$prepseq->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
649 my $sth=$self->_prepared_insert($table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},PK_ID_VALUE => $id);
650 $cols=$table->get_columns;
651 $seq_colseq=($table->get_pk_columns)[1]->get_column_sequence;
652 affirm { defined $seq_colseq } "the table ".$table->get_sql_name." not have SEQ pk column";
653 $sth->bind_column($cols->[$seq_colseq],$seq,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
654 for my $i(0..scalar(@values) - 1) {
655 $sth->bind_column($cols->[$seq_colseq + 1 + $i],$values[$i],TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
656 }
657 $sth->execute;
658 _insert_seq_inc($prepseq,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #increment the value of the seq column
659 undef;
660 }
661  
662 sub _doctypefin_node {
663 my ($expect,@dummy)=@_;
664 my $self=$expect->{LOAD_INSTANCE};
665 affirm { defined $self->{PREPARED_DTD_NODE_DTDSEQ_TABLE} } "attribute PREPARED_DTD_NODE_DTDSEQ_TABLE not set";
666 affirm { defined $self->{SCHEMA} } "SCHEMA not set";
667 delete $self->{PREPARED_DTD_NODE_DTDSEQ_TABLE};
668 my $extra_tables=$self->{EXTRA_TABLES};
669 my @dtd_tables=map { $extra_tables->get_extra_table($_) }$extra_tables->get_extra_table_types('DTD_TABLES');
670 for my $t(@dtd_tables) {
671 my $sth=$self->_prepared_insert($t,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},NO_PK => 1,NO_PENDING_CHECK => 1);
672 $sth->finish(NO_PENDING_CHECK => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
673 }
674 undef;
675 }
676  
677 sub _notation_node {
678 my ($expect,$notation,$base,$sysid,$pubid,@dummy)=@_;
679 _dtd_node($expect,'NOTATION_TABLE',$notation,$base,$sysid,$pubid);
680 }
681  
682 sub _entity_node {
683 my ($expect,$name,$val,$sysid,$pubid,$ndata,$isparam,@dummy)=@_;
684 $isparam=$isparam ? 1 : undef;
685 _dtd_node($expect,'ENTITY_TABLE',$name,$val,$sysid,$pubid,$ndata,$isparam);
686 };
687  
688 sub _element_node {
689 my ($expect,$name,$model,@dummy)=@_;
690 $model=''.$model; #convert into string
691 _dtd_node($expect,'ELEMENT_TABLE',$name,$model);
692 }
693  
694 sub _attlist_node {
695 my ($expect,$elname,$attname,$type,$default,$fixed,@dummy)=@_;
696 if (defined $default) {
697 $default=~s/^'//;
698 $default=~s/'$//;
699 }
700 if (defined $fixed) {
701 $fixed=~s/^'//;
702 $fixed=~s/'$//;
703 }
704 _dtd_node($expect,'ATTLIST_TABLE',$elname,$attname,$type,$default,$fixed);
705 }
706  
707 sub _externent_node {
708 my($expect,$base,$sysid,$pubid,@dummy)=@_;
709 croak "ExternEnt is not implemented\n"
710 }
711  
712 sub _unparser_node {
713 croak "set this handler is in conflict with the handle Entity\n"
714 }
715  
716 sub _start_group_type {
717 my ($self,$tc,%params)=@_;
718 affirm { $tc->{T}->is_group_type } $tc->{T}->get_sql_name.": is not a group type table";
719 $self->_debug(undef,"start group type for column",$tc->{C}->get_full_name);
720 my $stack_frame=$self->_get_stack_frame(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
721 if ($self->_is_equal($tc->{T},$stack_frame->{PREPARED}->get_binding_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})) { #
722 if (defined $stack_frame->{GROUP_TYPE_COLSEQ}) {
723 if ($stack_frame->{GROUP_TYPE_COLSEQ} >= $tc->{C}->get_column_sequence) {
724 my $sth=$stack_frame->{PREPARED};
725 delete $stack_frame->{EXTERNAL_REFERENCE};
726 $sth->execute(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
727 _insert_seq_inc($sth,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}); #increment the value of the seq column
728 }
729 }
730 }
731 else {
732 affirm { !(scalar(@{$tc->{STACK}}) > 0 && $tc->{STACK}->[0]->{T}->is_group_type) } "bad group stack";
733 if ($tc->{STACK} && scalar(@{$tc->{STACK}}) > 1) {
734 my ($pt_name)=($stack_frame->{PREPARED}->get_binding_table(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})->get_sql_name);
735 my $p=undef;
736 for my $i(0..scalar(@{$tc->{STACK}}) - 1) {
737 my $st=$tc->{STACK}->[$i];
738 if ($st->{T}->get_sql_name eq $pt_name) {
739 $p=$i;
740 last;
741 }
742 }
743 affirm { defined $p } "$pt_name: not found into stack";
744 if ($self->{DEBUG}) {
745 for my $i($p..scalar(@{$tc->{STACK}}) - 1) {
746 my $st=$tc->{STACK}->[$i];
747 $self->_debug(undef,"group_stack index $i for $pt_name",$st->{C}->get_full_name);
748 }
749 }
750 $tc->{STACK}->[$p]->{STH}=$stack_frame->{PREPARED};
751  
752 for my $i($p+1..scalar(@{$tc->{STACK}}) - 1) {
753 my $st=$tc->{STACK}->[$i];
754 $st->{STH}=$self->_prepared_insert($st->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
755 my ($id)=$st->{STH}->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
756 my $parent=$tc->{STACK}->[$i - 1];
757 $parent->{STH}->bind_column($parent->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});#
758 }
759  
760 my $sth=$self->_prepared_insert($tc->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
761 my ($id)=$sth->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
762 my $parent=$tc->{STACK}->[-1];
763 $parent->{STH}->bind_column($parent->{C},$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
764 $stack_frame=$self->_push({ PREPARED => $sth,VALUE => '',PATH => ' <group type>' },TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
765 $stack_frame->{STACK}=$tc->{STACK};
766 $stack_frame->{STACK_INDEX}=$p + 1;
767 }
768 else {
769 my $trf=$tc->{STACK}->[-1];
770 my ($parent_table,$parent_column)=($trf->{T},$trf->{C});
771 my $sth=$self->_prepared_insert($tc->{T},TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__},NO_PENDING_CHECK => 1);
772 my ($id)=$sth->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
773 if ($self->_is_equal($parent_table,$stack_frame->{PREPARED}->get_binding_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__})) {
774 $stack_frame->{PREPARED}->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
775 $stack_frame=$self->_push({ PREPARED => $sth,VALUE => '',PATH => '<group type>' },TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
776 }
777 else {
778 my $p=$self->_search_into_stack($parent_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
779 for my $i($p..scalar(@{$self->{STACK}}) - 1) {
780 my $st=$self->{STACK}->[$i]->{PREPARED};
781 my ($id)=$st->get_binding_values(PK_ONLY => 1,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
782 my $st_parent=$self->{STACK}->[$i - 1]->{PREPARED};
783 my $parent_column=$self->_resolve_link($st_parent->get_binding_table,$st->get_binding_table,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
784 $st_parent->bind_column($parent_column,$id,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});#
785 }
786 }
787 }
788 }
789
790 $stack_frame->{GROUP_TYPE_COLSEQ}=$tc->{C}->get_column_sequence;
791 $stack_frame;
792 }
793  
794 sub _search_into_stack {
795 my ($self,$f,%params)=@_;
796 my $stack=delete $params{STACK};
797 $stack=$self->{STACK} unless defined $stack;
798 my $p=undef;
799 if (ref($f) =~/::table$/) {
800 for my $i(0..scalar(@$stack) - 1) {
801 my $st=$stack->[$i];
802 if ($self->_is_equal($st->{PREPARED}->get_binding_table,$f,%params)) {
803 $p=$i;
804 last;
805 }
806 }
807 }
808 elsif (ref($f) eq 'CODE') {
809 for my $i(0..scalar(@$stack) - 1) {
810 my $st=$stack->[$i];
811 if ($f->($st)) {
812 $p=$i;
813 last;
814 }
815 }
816 }
817 else {
818 croak ref($f).": unknow type\n";
819 }
820 $p;
821 }
822  
823 sub _resolve_link {
824 my ($self,$t1,$t2,%params)=@_;
825 my $tag=delete $params{TAG};
826 my $column=$self->{SCHEMA}->resolve_column_link($t1,$t2,%params);
827 if ($self->{DEBUG}) {
828 $self->_debug($tag,$column->get_full_name,' => '.$t2->get_sql_name);
829 }
830 $column;
831 }
832  
833 sub _get_prepared_insert {
834 my ($self,$tag,%params)=@_;
835 $tag=$tag->get_sql_name if ref($tag) =~/::table$/;
836 affirm { ref($tag) eq '' } "not a string or table";
837 $self->{PREPARED}->{$tag}->{INSERT};
838 }
839  
840 sub _bind_node_attrs {
841 my ($self,$prep,$attrs,%params)=@_;
842 my $table=$prep->get_binding_table;
843 my @keys=keys %$attrs;
844 my @cols=$self->{SCHEMA}->resolve_attributes($table,$self->{NSPREFIXES},@keys);
845 for my $i(0..scalar(@cols) - 1) {
846 my $col=$cols[$i];
847 if (defined $col) {
848 $prep->bind_column($col,$attrs->{$keys[$i]},%params);
849 }
850 else { # is system attribute
851 my $col=$table->get_sysattrs_column;
852 my $v=$keys[$i].'="'.$attrs->{$keys[$i]}.'"';
853 $prep->bind_column($col,$v,%params,APPEND => 1,SEP => ' ');
854 }
855 }
856 $self;
857 }
858  
859 sub _find_namespace_from_abbr {
860 my ($self,$ns,%params)=@_;
861 affirm { defined $ns } "1^ param not set";
862 my $uri=$self->{NSPREFIXES}->{$ns};
863 $self->_debug(undef,"$ns: no such namespace (URI) from this namespace abbr") unless defined $uri;
864 $uri;
865 }
866  
867 sub new {
868 my ($class,%params)=@_;
869 affirm { defined $params{BINDING} } 'param BINDING not set';
870 affirm { defined $params{SCHEMA} } 'param SCHEMA not set';
871 affirm { defined $params{EXTRA_TABLES} } 'param EXTRA_TABLES not set';
872
873 $params{PARSER}=XML::Parser->new unless defined $params{PARSER};
874 $params{PARSER}->setHandlers(
875 Start => \&_start_node
876 ,End => \&_end_node
877 ,Char => \&_char_node
878 ,Doctype => \&_doctype_node
879 ,Notation => \&_notation_node
880 ,Entity => \&_entity_node
881 ,Element => \&_element_node
882 ,Attlist => \&_attlist_node
883 ,ExternEnt => \&_externent_node
884 ,DoctypeFin => \&_doctypefin_node
885 # ,CDataStart => \&_cdatastart_node
886 ,XMLDecl => \&_xmldecl_node
887 );
888 $class->SUPER::_new(%params);
889 }
890  
891 sub read {
892 my ($self,%params)=@_;
893 $self->{BINDING}->set_attrs_value(SEQUENCE_NAME => $self->{EXTRA_TABLES}->get_sequence_name)
894 unless defined $self->{BINDING}->get_attrs_value(qw(SEQUENCE_NAME));
895 $self->{STACK}=[];
896 $self->{ID}=undef;
897 $self->{_ROOT_ID}=$self->{BINDING}->get_next_sequence;
898 my $fd=nvl($params{FD},*STDIN);
899 $self->{PARSER}->parse($fd,LOAD_INSTANCE => $self);
900 $self->{BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
901 my $id=delete $self->{ID};
902 affirm { defined $id } "returning id not set";
903 affirm { $id == $self->{_ROOT_ID}} "returning id is not equal at initialization";
904 delete $self->{_ROOT_ID};
905 delete $self->{STACK};
906 my $table=$self->{EXTRA_TABLES}->get_extra_table(qw(XML_ENCODING));
907 my $n=$self->{BINDING}->insert_row_from_generic(
908 $table
909 ,[$id,$self->{_XMLDECL}->[1]]
910 ,TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__}
911 );
912 $self->{BINDING}->finish(TAG => { PACKAGE => __PACKAGE__,LINE => __LINE__});
913 affirm { defined $n && $n == 1 } "the rows inserted is not 1";
914 $id;
915 }
916  
917  
918  
919  
920 1;
921  
922  
923  
924 __END__