DBI
view release on metacpan or search on metacpan
lib/DBD/DBM.pm view on Meta::CPAN
my $class = $dbh->{ImplementorClass};
$class =~ s/::db$/::Table/;
$table and ( undef, $meta ) = $class->get_table_meta( $dbh, $table, 1 );
$meta or ( $meta = {} and $class->bootstrap_table_meta( $dbh, $meta, $table ) );
my $dver;
my $dtype = $meta->{dbm_type};
eval {
$dver = $meta->{dbm_type}->VERSION();
# *) when we're still alive here, everything went ok - no need to check for $@
$dtype .= " ($dver)";
};
if ( $meta->{dbm_mldbm} )
{
$dtype .= ' + MLDBM';
eval {
$dver = MLDBM->VERSION();
$dtype .= " ($dver)"; # (*)
};
eval {
lib/DBD/File.pm view on Meta::CPAN
sub get_f_versions {
my ($dbh, $table) = @_;
my $class = $dbh->{ImplementorClass};
$class =~ s/::db$/::Table/;
my $dver;
my $dtype = "IO::File";
eval {
$dver = IO::File->VERSION ();
# when we're still alive here, everything went ok - no need to check for $@
$dtype .= " ($dver)";
};
my $f_encoding;
if ($table) {
my $meta;
$table and (undef, $meta) = $class->get_table_meta ($dbh, $table, 1);
$meta and $meta->{f_encoding} and $f_encoding = $meta->{f_encoding};
} # if ($table)
$f_encoding ||= $dbh->{f_encoding};
lib/DBI/DBD.pm view on Meta::CPAN
SQL standard for quoting strings, with the string enclosed in single
quotes and any embedded single quotes replaced by two consecutive
single quotes.
For the two argument form of quote, you need to implement the
C<type_info()> method to provide the information that quote needs.
=item $dbh->ping()
This should be implemented as a simple efficient way to determine
whether the connection to the database is still alive. Typically
code like this:
sub ping {
my $dbh = shift;
$sth = $dbh->prepare_cached(q{
select * from A_TABLE_NAME where 1=0
}) or return 0;
$sth->execute or return 0;
$sth->finish;
return 1;
lib/DBI/DBD/SqlEngine/HowTo.pod view on Meta::CPAN
Woooho - but now the user cannot assign new managers? This is intended,
overwrite C<STORE> to handle it!
sub STORE ($$$)
{
my ( $dbh, $attrib, $value ) = @_;
$dbh->SUPER::STORE( $attrib, $value );
# we're still alive, so no exception is thrown ...
# by DBI::DBD::SqlEngine::db::STORE
if ( $attrib eq "foo_manager_type" )
{
$dbh->{foo_manager} = $dbh->{foo_manager_type}->new();
# ... probably correct some states based on the new
# foo_manager_type - see DBD::Sys for an example
}
}
But ... my driver runs without a manager until someone first assignes
lib/DBI/ProxyServer.pm view on Meta::CPAN
# this IP-address only is meant
mask => '^10\.95\.81\.243$',
# accept (not defer) connections like this
accept => 1,
# only users from this list
# are allowed to log on
users => [ 'informationdesk' ],
# only this statistical query is allowed
# to get results for a web-query
sql => {
alive => 'select count(*) from dual',
statistic_area => 'select count(*) from e01admin.e01e203 where geb_bezei like ?',
}
},
# rule: internal_bad_guy_1
{
mask => '^10\.95\.81\.1$',
accept => 0,
},
lib/DBI/ProxyServer.pm view on Meta::CPAN
=head2 Testing the connection from a remote machine
Call a program "dbish" from your commandline. I take the machine from rule "internal_webserver"
dbish "dbi:Proxy:hostname=oracle.zdf;port=12400;dsn=dbi:Oracle:e01" informationdesk xxx
There will be a shell-prompt:
informationdesk@dbi...> alive
Current statement buffer (enter '/'...):
alive
informationdesk@dbi...> /
COUNT(*)
'1'
[1 rows of 1 fields returned]
=head2 Testing the connection with a perl-script
Create a perl-script like this:
lib/DBI/ProxyServer.pm view on Meta::CPAN
=back
Controlling which SQL-statements are allowed
You can put every SQL-statement you like in simply omitting "sql => ...", but the more important thing is to restrict the connection so that only allowed queries are possible.
If you include an sql-section in your config-file like this:
sql => {
alive => 'select count(*) from dual',
statistic_area => 'select count(*) from e01admin.e01e203 where geb_bezei like ?',
}
The user is allowed to put two queries against the dbi-proxy. The queries are _not_ "select count(*)...", the queries are "alive" and "statistic_area"! These keywords are replaced by the real query. So you can run a query for "alive":
my $sql = "alive";
my $cur = $dbh->prepare($sql);
...
The flexibility is that you can put parameters in the where-part of the query so the query are not static. Simply replace a value in the where-part of the query through a question mark and bind it as a parameter to the query.
my $sql = "statistic_area";
my $cur = $dbh->prepare($sql);
$cur->bind_param(1,'905%');
# A second parameter would be called like this:
# $cur->bind_param(2,'98%');
( run in 2.278 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )