File: testproc2.pl

package info (click to toggle)
libdbd-odbc-perl 1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,392 kB
  • ctags: 496
  • sloc: perl: 8,818; ansic: 6,376; makefile: 33; sql: 8
file content (46 lines) | stat: -rwxr-xr-x 1,182 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
#!perl -w
# $Id$

use strict;
use DBI;

# Connect to the database, and create two tables and a stored procedure:
my $dbh=DBI->connect() or die "Can't connect";

eval {$dbh->do("DROP TABLE table1");};
eval {$dbh->do("CREATE TABLE table1 (i INTEGER)");};

eval {$dbh->do("DROP TABLE table2");};
eval {$dbh->do("CREATE TABLE table2 (i INTEGER)");};

eval {$dbh->do("DROP PROCEDURE proc1");};
eval {$dbh->do("CREATE PROCEDURE proc1 AS ".
                "BEGIN  INSERT INTO table1 VALUES (1);  END;");};

unlink "dbitrace.log" if (-e "dbitrace.log");

$dbh->trace(9, "dbitrace.log");

# Insert a row into table1, either directly or indirectly:
my $direct = 0;
my $sth1;
if ($direct) {
   $sth1 = $dbh->prepare ("INSERT INTO table1 VALUES (1)");
} else {
   $sth1 = $dbh->prepare ("{ call proc1 }");
}
$sth1->execute();
$sth1->execute();
$sth1->execute();

# Insert a row into table2 (this fails after an indirect insertion):
my $sth2 = $dbh->prepare ("INSERT INTO table2 VALUES (2)");
$sth2->execute();

my $sth = $dbh->prepare("select i from table1 union select i from table2");
my @row;
$sth->execute;
while (@row = $sth->fetchrow_array) {
   print $row[0], "\n";
}
$dbh->disconnect;