« blib/lib/blx/xsdsql/generator/sql/DBM/handle/insert_dictionary.pm
↑ Summary
blib/lib/blx/xsdsql/schema_repository/sql/oracle/binding.pm »
| 1 | package blx::xsdsql::schema_repository::sql::mysql::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 | use blx::xsdsql::ut::ut qw(nvl); | ||
| 10 | |||
| 11 | |||
| 12 | sub _manip_value { | ||
| 13 | my ($self,$col,$value,%params)=@_; | ||
| 14 | my $t=$col->get_attrs_value(qw(TYPE_DUMPER)); | ||
| 15 | affirm { defined $t } "attribute TYPE_DUMPER not set for column ".nvl($col->get_full_name); | ||
| 16 | if (defined $value) { | ||
| 17 | if ($t->{BASE} eq 'boolean') { | ||
| 18 | if ($value eq 'true' || $value eq '1') { | ||
| 19 | $value=1 ; | ||
| 20 | } | ||
| 21 | elsif($value eq 'false' || $value eq '0') { | ||
| 22 | $value=0; | ||
| 23 | } | ||
| 24 | else { | ||
| 25 | croak "'$value': unknow value for type boolean" | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | $value; | ||
| 30 | } | ||
| 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 | sub _get_next_sequence { | ||
| 43 | my ($self,%params)=@_; | ||
| 44 | my $seq=$self->{SEQUENCE_NAME}; | ||
| 45 | |||
| 46 | my $sql="select * from $seq"; | ||
| 47 | # $self->_debug($params{TAG},$sql); | ||
| 48 | my $prep=$self->{DB_CONN}->prepare($sql); | ||
| 49 | $prep->execute; | ||
| 50 | my $r=$prep->fetchrow_arrayref; | ||
| 51 | my $n=defined $r ? $r->[0] : 0; | ||
| 52 | $prep->finish; | ||
| 53 | |||
| 54 | $sql="delete from $seq"; | ||
| 55 | # $self->_debug($params{TAG},$sql); | ||
| 56 | $prep=$self->{DB_CONN}->prepare($sql); | ||
| 57 | $prep->execute; | ||
| 58 | $prep->finish; | ||
| 59 | |||
| 60 | $sql="insert into $seq values(?)"; | ||
| 61 | # $self->_debug($params{TAG},$sql); | ||
| 62 | $prep=$self->{DB_CONN}->prepare($sql); | ||
| 63 | $prep->bind_param(1,++$n); | ||
| 64 | $prep->execute; | ||
| 65 | $prep->finish; | ||
| 66 | $n; | ||
| 67 | } | ||
| 68 | |||
| 69 | sub _information_tables { | ||
| 70 | my ($self,%params)=@_; | ||
| 71 | my $prep=undef; | ||
| 72 | my $pref=$self->{EXECUTE_OBJECTS_PREFIX}; | ||
| 73 | if (defined $pref && $pref=~/\.$/) { | ||
| 74 | my ($cat,$schema)=$pref=~/^([^\.]+)\.([^\.]+)/; | ||
| 75 | ($schema)=$pref=~/^([^\.]+)/ unless defined $schema; | ||
| 76 | affirm { defined $schema } "$pref: the param 'EXECUTE_OBJECTS_PREFIX' is not correct" | ||
| 77 | .' - must be [<catalog_name>.]<schema_name>.'; | ||
| 78 | unless (defined $cat) { | ||
| 79 | $prep=$self->{DB_CONN}->prepare(q(select distinct catalog_name from information_schema.schemata)); | ||
| 80 | $prep->execute; | ||
| 81 | my $r=$prep->fetchrow_arrayref; | ||
| 82 | $prep->finish; | ||
| 83 | affirm { defined $r } 'query not return a row'; | ||
| 84 | $cat=$r->[0]; | ||
| 85 | affirm { defined $cat } 'errore retrieve current catalog_name'; | ||
| 86 | } | ||
| 87 | $prep=$self->{DB_CONN}->prepare(q( | ||
| 88 | select table_name | ||
| 89 | from information_schema.tables | ||
| 90 | where table_catalog=? and table_schema=? | ||
| 91 | ) | ||
| 92 | ); | ||
| 93 | $prep->bind_param(1,$cat); | ||
| 94 | $prep->bind_param(2,$schema); | ||
| 95 | } | ||
| 96 | else { | ||
| 97 | $prep=$self->{DB_CONN}->prepare( | ||
| 98 | q{ | ||
| 99 | select t.table_name from | ||
| 100 | information_schema.tables t | ||
| 101 | where | ||
| 102 | t.table_schema = schema() | ||
| 103 | } | ||
| 104 | ); | ||
| 105 | } | ||
| 106 | $prep->execute; | ||
| 107 | my @t=(); | ||
| 108 | while(my $r=$prep->fetchrow_arrayref) { | ||
| 109 | push @t,$r->[0]; | ||
| 110 | } | ||
| 111 | $prep->finish; | ||
| 112 | wantarray ? @t : \@t; | ||
| 113 | } | ||
| 114 | |||
| 115 | sub finish { | ||
| 116 | my ($self,%params)=@_; | ||
| 117 | local $self->{DB_CONN}->{RaiseError}=1; | ||
| 118 | (delete $self->{PREPARE_SEQUENCE})->finish if defined $self->{PREPARE_SEQUENCE}; | ||
| 119 | $self->SUPER::finish(%params); | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | 1; | ||
| 124 | |||
| 125 | |||
| 126 | __END__ |