« blib/lib/blx/xsdsql/schema_repository/sql/oracle/binding.pm
↑ Summary
blib/lib/blx/xsdsql/generator/sql/generic/handle/create_extra_tables.pm »
| 1 | package blx::xsdsql::schema_repository::sql::pg::binding; | ||
| 2 | |||
| 3 | use strict; # use strict is for PBP | ||
| 4 | use Filter::Include; | ||
| 5 | include blx::xsdsql::include; | ||
| 6 | #line 7 | ||
| 7 | |||
| 8 | use base qw(blx::xsdsql::schema_repository::sql::generic::binding); | ||
| 9 | |||
| 10 | use blx::xsdsql::ut::ut qw(nvl); | ||
| 11 | |||
| 12 | |||
| 13 | sub _manip_value { | ||
| 14 | my ($self,$col,$value,%params)=@_; | ||
| 15 | my $t=$col->get_attrs_value(qw(TYPE_DUMPER)); | ||
| 16 | affirm { defined $t } "attribute TYPE_DUMPER not set for column ".nvl($col->get_full_name); | ||
| 17 | if (defined $value) { | ||
| 18 | if ($t->{BASE} eq 'boolean') { | ||
| 19 | if ($value eq 'true' || $value eq '1') { | ||
| 20 | $value=1 ; | ||
| 21 | } | ||
| 22 | elsif($value eq 'false' || $value eq '0') { | ||
| 23 | $value=0; | ||
| 24 | } | ||
| 25 | else { | ||
| 26 | croak "'$value': unknow value for type boolean" | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | $value; | ||
| 31 | } | ||
| 32 | sub _get_sql_drop_table { | ||
| 33 | my ($self,%params)=@_; | ||
| 34 | 'drop table if exists %t cascade'; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub _get_sql_drop_view { | ||
| 38 | my ($self,%params)=@_; | ||
| 39 | 'drop view if exists %v'; | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | sub _get_next_sequence { | ||
| 44 | my ($self,%params)=@_; | ||
| 45 | $self->{PREPARE_SEQUENCE}=$self->{DB_CONN}->prepare("select nextval('".$self->{SEQUENCE_NAME}."')") | ||
| 46 | unless defined $self->{PREPARE_SEQUENCE}; | ||
| 47 | $self->{PREPARE_SEQUENCE}->execute; | ||
| 48 | my $r=$self->{PREPARE_SEQUENCE}->fetchrow_arrayref; | ||
| 49 | $r->[0]; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub _information_tables { | ||
| 53 | my ($self,%params)=@_; | ||
| 54 | my $prep=undef; | ||
| 55 | my $pref=$self->{EXECUTE_OBJECTS_PREFIX}; | ||
| 56 | if (defined $pref && $pref=~/\.$/) { | ||
| 57 | my ($cat,$schema)=$pref=~/^([^\.]+)\.([^\.]+)/; | ||
| 58 | ($schema)=$pref=~/^([^\.]+)/ unless defined $schema; | ||
| 59 | affirm { defined $schema } "$pref: the param 'EXECUTE_OBJECTS_PREFIX' is not correct" | ||
| 60 | .' - must be [<catalog_name>.]<schema_name>.'; | ||
| 61 | unless (defined $cat) { | ||
| 62 | $prep=$self->{DB_CONN}->prepare(q(select catalog_name from information_schema.schemata)); | ||
| 63 | $prep->execute; | ||
| 64 | my $r=$prep->fetchrow_arrayref; | ||
| 65 | $prep->finish; | ||
| 66 | affirm { defined $r } 'query not return a row'; | ||
| 67 | $cat=$r->[0]; | ||
| 68 | affirm { defined $cat } 'errore retrieve current catalog_name'; | ||
| 69 | } | ||
| 70 | $prep=$self->{DB_CONN}->prepare(q( | ||
| 71 | select table_name | ||
| 72 | from information_schema.tables | ||
| 73 | where table_catalog=? and table_schema=? | ||
| 74 | ) | ||
| 75 | ); | ||
| 76 | $prep->bind_param(1,$cat); | ||
| 77 | $prep->bind_param(2,$schema); | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | $prep=$self->{DB_CONN}->prepare( | ||
| 81 | q( | ||
| 82 | select t.table_name from | ||
| 83 | information_schema.tables t | ||
| 84 | join information_schema.schemata s on t.table_catalog=s.catalog_name and t.table_schema = s.schema_name | ||
| 85 | ) | ||
| 86 | ); | ||
| 87 | } | ||
| 88 | $prep->execute; | ||
| 89 | my @t=(); | ||
| 90 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 91 | push @t,$r->[0]; | ||
| 92 | } | ||
| 93 | $prep->finish; | ||
| 94 | return wantarray ? @t : \@t; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub finish { | ||
| 98 | my ($self,%params)=@_; | ||
| 99 | local $self->{DB_CONN}->{RaiseError}=1; | ||
| 100 | (delete $self->{PREPARE_SEQUENCE})->finish if defined $self->{PREPARE_SEQUENCE}; | ||
| 101 | return $self->SUPER::finish(%params); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | 1; | ||
| 106 | |||
| 107 | |||
| 108 | __END__ |