=head2 fetch_AoH() @aoh = $database->fetch_AoH($sql) =cut sub fetch_AoH { my ($self, @p) = getSelf(@_); my $sql = shift @p; my @r; eval(' my $sth = $dbh->prepare($sql); if(defined $p[0]) { $sth->execute(@p) or warn $dbh->errstr; } else { $sth->execute() or warn $dbh->errstr; } while(my $h = $sth->fetchrow_hashref) { push(@r, $h); } $sth->finish();'); @r = $@ if $@; return @r; } =head2 fetch_hashref() $hashref = $database->fetch_hashref($sql) =cut sub fetch_hashref { my ($self, @p) = getSelf(@_); my $sql = shift @p; my $h; eval(' my $sth = $dbh->prepare($sql); if(defined $p[0]) { $sth->execute(@p) or warn $dbh->errstr; } else { $sth->execute() or warn $dbh->errstr; } my @r; $h = $sth->fetchrow_hashref(); $sth->finish(); '); $h = "$@" if $@; return $h; } =head2 void() void(sql) =cut sub void { my ($self, @p) = getSelf(@_); my $sql = shift @p; my $sth = $dbh->prepare($sql); eval(' if(defined $p[0]) { $sth->execute(@p) or warn $dbh->errstr; } else { $sth->execute() or warn $dbh->errstr; }'); $sth->finish(); return "$@" if $@; } =head2 quote() $quotedString = $database->quote($sql); =cut sub quote { my ($self, @p) = getSelf(@_); my $sql = $p[0]; return $dbh->quote($sql); } =head1 Privat =head2 updateModules() =cut sub updateModules { my ($self, @p) = getSelf(@_); my @q = $self->fetch_array("select title from querys"); $functions{$_} = $_ foreach (@q); } =head2 getSelf() =cut sub getSelf { return @_ if defined($_[0]) && (!ref($_[0])) && ($_[0] eq 'DBI::LZE'); return (defined($_[0]) && (ref($_[0]) eq 'DBI::LZE' || UNIVERSAL::isa($_[0], 'DBI::LZE'))) ? @_ : ($DBI::LZE::DefaultClass->new, @_); } =head2 AUTOLOAD() statements add by addexecute can called like $database->showTables() =cut sub AUTOLOAD { my ($self, @p) = getSelf(@_); our $AUTOLOAD; if($AUTOLOAD =~ /.*::(\w+)$/ and grep $1 eq $_, %functions) { my $attr = $1; { no strict 'refs'; *{$AUTOLOAD} = sub { $self->useexecute($attr, @p); }; } goto &{$AUTOLOAD}; } } package DBI::LZE::db; use vars qw(@ISA); @ISA = qw(DBI::db); =head2 prepare() =cut sub prepare { my ($dbh, @args) = @_; my $sth = $dbh->SUPER::prepare(@args) or return; return $sth; } package DBI::LZE::st; use vars qw(@ISA); @ISA = qw(DBI::st); =head2 execute() =cut sub execute { my ($sth, @args) = @_; my $rv; eval('$rv = $sth->SUPER::execute(@args)'); return "$@" if $@; return $rv; } =head2 fetch() =cut sub fetch { my ($sth, @args) = @_; my $row = $sth->SUPER::fetch(@args) or return; return $row; } 1;