File: sqltmptabs.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 (27 lines) | stat: -rw-r--r-- 722 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
use DBI;
# $Id$
# For MS SQL Server temp tables are only visible if you create them with "do"

my $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS}, { RaiseError => 1});
my $sth;
my $sql = 'CREATE TABLE #foo (id INT PRIMARY KEY, val CHAR(4))';
$dbh->do($sql);
# $sth = $dbh->prepare($sql);
# $sth->execute;
# $sth->finish;

print "Now inserting!\n";
$sth = $dbh->prepare("INSERT INTO #foo (id, val) VALUES (?, ?)");
my $sth2 = $dbh->prepare("INSERT INTO #foo (id, val) VALUES (?, ?)");
$sth2->execute(1, 'foo');
$sth2->execute(2, 'bar');

$sth = $dbh->prepare("Select id, val from #foo");
$sth->execute;
my @row;

while (@row = $sth->fetchrow_array) {
   print join(', ', @row), "\n";
}

$dbh->disconnect;