Skip to content

Commit

Permalink
preliminary ISQL-like tool using DBD::Firebird
Browse files Browse the repository at this point in the history
Could be used in situations where stock isql is not suitable
  • Loading branch information
real-dam committed Nov 24, 2011
1 parent c3306d5 commit af758fd
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions eg/pisql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/perl

use warnings;
use strict;

use DBD::FirebirdEmbedded;

my $dbh;

while (1) {
print "> ";
my $in = <>;
last unless defined($in);

next if $in =~ /^\s*--/;

if ( $in =~ /^\s*create\s*database\s*'([^']+)'\s*$/ ) {
my $db_path = $1;
DBD::FirebirdEmbedded->create_database({db_path => $1});
$dbh = DBI->connect( "dbi:FirebirdEmbedded:db=$1", undef, undef,
{ AutoCommit => 0 } );
}
elsif ( $in =~ /^\s*connect '([^']+)'\s*$/ ) {
$dbh = DBI->connect( "dbi:FirebirdEmbedded:db=$1", undef, undef,
{ AutoCommit => 0 } );
}
elsif ( $in =~ /^\s*exit\s*/i ) {
$dbh->commit if $dbh;
last;
}
elsif ( $in =~ /^\s*quit\s*/i ) {
$dbh->rollback if $dbh;
last;
}
else {
if ($dbh) {
my $sth = $dbh->prepare_cached($in);
$sth->execute();
if ( $sth->{NUM_OF_FIELDS} > 0 ) {
print join( "\t", @{ $sth->{NAME} } ), "\n";
while ( my $row = $sth->fetchrow_arrayref ) {
print
join( "\t", map( defined($_) ? $_ : 'NULL', @$row ) ),
"\n";
}
$sth->finish;
}
}
else {
warn "E: Not connected to a database.\n";
}
}
}

if ($dbh) {
$dbh->rollback;
$dbh->disconnect;
}

0 comments on commit af758fd

Please sign in to comment.