File: testproc3.pl

package info (click to toggle)
libdbd-odbc-perl 1.24-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,012 kB
  • ctags: 398
  • sloc: perl: 6,314; ansic: 4,875; makefile: 29; sql: 8
file content (50 lines) | stat: -rwxr-xr-x 1,189 bytes parent folder | download | duplicates (2)
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
#!perl -w
# $Id: testproc3.pl 11680 2008-08-28 08:23:27Z mjevans $


use strict;
use DBI;
my $dbh = DBI->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 \@inputval int AS ".
                "INSERT INTO table1 VALUES (\@inputval); " .   
			"	return \@inputval;");};
if ($@) { print $@, "\n"; }

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;
$sth1 = $dbh->prepare ("{? = call proc1(?) }");

my $output = 0;
my $i = 0;

while ($i < 4) {
   # Insert a row into table2 (this fails after an indirect insertion):
   $sth1->bind_param_inout(1, \$output, 50, DBI::SQL_INTEGER);
   $sth1->bind_param(2, $i, DBI::SQL_INTEGER);

   $sth1->execute();
   print "$output\n";
   $i++;
}

my $sth = $dbh->prepare("select * from table1");
$sth->execute;
my @row;
while (@row = $sth->fetchrow_array) {
   print join(', ', @row), "\n";
}

$dbh->disconnect;