File: testundef2.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 (34 lines) | stat: -rwxr-xr-x 992 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
#!perl -w
# $Id: testundef2.pl 11680 2008-08-28 08:23:27Z mjevans $

use strict;
use DBI qw(:sql_types);

my $dbh=DBI->connect() or die "Can't connect";

eval {$dbh->do("DROP TABLE table1");};
eval {$dbh->do("CREATE TABLE table1 (v varchar(4000), d datetime)");};

unlink("dbitrace.log") if (-e "dbitrace.log") ;
$dbh->trace(8, "dbitrace.log");

my $sth = $dbh->prepare ("INSERT INTO table1 (d, v) VALUES (?, ?)");
$sth->bind_param (1, undef, SQL_TYPE_TIMESTAMP);
$sth->bind_param (2, undef, SQL_LONGVARCHAR);
$sth->execute();
$sth->bind_param (1, "2002-07-12 17:07:37.350", SQL_TYPE_TIMESTAMP);
$sth->bind_param (2, "real data", SQL_LONGVARCHAR);
$sth->execute();
$sth->bind_param (1, undef, SQL_TYPE_TIMESTAMP);
$sth->bind_param (2, undef, SQL_LONGVARCHAR);
$sth->execute();

$sth = $dbh->prepare("select d, v from table1");
$sth->execute;
my @row;

while (@row = $sth->fetchrow_array) {
   foreach (@row) { $_ = "" if (!defined($_)); }
   print join(", ", @row), "\n";
}
$dbh->disconnect;