File: fail.t

package info (click to toggle)
libdbd-sybase-perl 1.24-3
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: ansic: 5,629; perl: 2,216; makefile: 4
file content (114 lines) | stat: -rw-r--r-- 2,743 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/local/bin/perl
#
# $Id: fail.t,v 1.9 2005/10/01 13:05:13 mpeppler Exp $

use lib 'blib/lib';
use lib 'blib/arch';

use strict;

use lib 't';
use _test;

use Test::More tests=>12; #qw(no_plan);

BEGIN { use_ok('DBI');
        use_ok('DBD::Sybase');}

use vars qw($Pwd $Uid $Srv $Db);

($Uid, $Pwd, $Srv, $Db) = _test::get_info();

my $dbh = DBI->connect("dbi:Sybase:$Srv;database=$Db", $Uid, $Pwd, {PrintError => 0, syb_flush_finish => 1});

ok(defined($dbh), 'Connect');

if(!$dbh) {
  warn "No connection - did you set the user, password and server name correctly in PWD?\n";
  for (4 .. 12) {
	  ok(0);
  }
  exit(0);
}


my $rc;
my $sth;
#DBI->trace(4);
# This test only works with Sybase - apparently MS-SQL will not compile the whole batch (the 3 sql statements)
# in one go, and therefore won't flag the error until the second SELECT is executed.
# Sybase compiles the batch in one go, and will return the error immediately.
SKIP: {
  skip 1, "Test does not work with MS-SQL" if $dbh->{syb_server_version} eq 'Unknown' || $dbh->{syb_server_version} eq 'MS-SQL';
  my $sth = $dbh->prepare("
select * from sysusers
select * from no_such_table
select * from master..sysdatabases
");
  $rc = $sth->execute;

  ok(!defined($rc), 'Missing table');
}

$sth = $dbh->prepare("select * from sysusers\n");
$rc = $sth->execute;
ok(defined($rc), 'Sysusers');

while(my $d = $sth->fetch) {
  ;
}

$rc = $dbh->do("create table #test(one int not null primary key, two int not null, three int not null, check(two != three))");

ok(defined($rc), 'Create table');

SKIP: {
    skip '? placeholders not supported', 3 unless $dbh->{syb_dynamic_supported};

    $sth = $dbh->prepare("insert #test (one, two, three) values(?,?,?)");
    $rc = $sth->execute(3, 4, 5);
    ok(defined($rc), 'prepare w/placeholder');

    $rc = $sth->execute(3, 4, 5);
    ok(!defined($rc), 'execute w/placeholder');

    $rc = $sth->execute(5, 3, 3);
    ok(!defined($rc), 'execute w/placeholder');
}

$sth = $dbh->prepare("
insert #test(one, two, three) values (1, 2, 3)
insert #test(one, two, three) values (4, 5, 6)
insert #test(one, two, three) values (1, 2, 3)
insert #test(one, two, three) values (8, 9, 10)
");
$rc = $sth->execute;
ok(!defined($rc), 'prepare');

$sth = $dbh->prepare("select * from #test");
$rc = $sth->execute;
ok(defined($rc), 'select');

while(my $d = $sth->fetch) {
  print "@$d\n";
}
#print "ok 11\n";


$sth = $dbh->prepare("
insert #test(one, two, three) values (11, 12, 13)
select * from #test
insert #test(one, two, three) values (11, 12, 13)
");
$rc = $sth->execute;
ok(defined($rc), 'prepare/execute multi');
do {
  while(my $d = $sth->fetch) {
    print "@$d\n";
  }
} while($sth->{syb_more_results});

$dbh->do("drop table #test");