File: commit.pl

package info (click to toggle)
libdbd-oracle-perl 1.83-3
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 1,724 kB
  • sloc: ansic: 8,354; perl: 7,868; makefile: 20
file content (72 lines) | stat: -rwxr-xr-x 1,427 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env perl
#
# commit.pl
#
# Simple example of using commit and rollback.

use DBI;

use strict;

# Set trace level if '-# trace_level' option is given
DBI->trace( shift ) if 1 < @ARGV && $ARGV[0] =~ /^-#/ && shift;

die "syntax: $0 [-# trace] base user pass" if 3 > @ARGV;
my ( $inst, $user, $pass ) = @ARGV;

# Connect to database
my $dbh = DBI->connect( "dbi:Oracle:$inst", $user, $pass,
    { AutoCommit => 0, RaiseError => 1, PrintError => 0 } )
    or die $DBI::errstr;

# Create the table to hold prime numbers
print "Creating table\n";
eval { $dbh->do( 'CREATE TABLE primes ( prime NUMBER )' ); };
warn $@ if $@;

print "Loading table";
my $sth = $dbh->prepare( 'INSERT INTO primes VALUES ( ? )' );
while ( <DATA> ) {
    chomp;
    print " $_";
    $sth->execute( $_ );
    print " commit (", $dbh->commit, ")" if 11 == $_;
}
print "\n";

my $prime;
print "Reading table for the first time\n";
$sth = $dbh->prepare( 'SELECT prime FROM primes ORDER BY prime' );
$sth->execute;
$sth->bind_columns( {}, \$prime );
while ( $sth->fetch ) {
    print " $prime";
}
$sth->finish;
print "\n";

print "rollback (", $dbh->rollback, ")\n";

print "Reading table for the second time.\n";
$sth->execute;
$sth->bind_columns( {}, \$prime );
while ( $sth->fetch ) {
    print " $prime";
}
$sth->finish;
print "\n";

$dbh->do( 'DROP TABLE primes' );
print "Table Dropped\n";
$dbh->disconnect;
__END__
2
3
5
7
11
13
17
19
23
29