File: multi_sth.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 (388 lines) | stat: -rw-r--r-- 8,075 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# -*-Perl-*-
# $Id: multi_sth.t,v 1.3 2005/10/01 13:05:13 mpeppler Exp $
#
#
# Multiple sth on single dbh test.

use lib 't';
use _test;
use strict;

use Test::More tests => 49;

#use Test::More 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,
    AutoCommit => 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 .. 49 ) {
    ok(0);
  }
  exit(0);
}

test1($dbh);
test2($dbh);
test3($dbh);
test4($dbh);
test5($dbh);
test6($dbh);

test_cached($dbh);
# Vanilla test - do the "correct" prepare/execute handling.
sub test1 {
  my $dbh = shift;

  my $rc;

  my $sth1 = $dbh->prepare("select * from master..sysprocesses");
  ok( defined($sth1), 'test1 prepare1' );
  my $sth2 = $dbh->prepare("select * from sysusers");
  ok( defined($sth2), 'test1 prepare2' );

  $rc = $sth1->execute;
  ok( defined($rc), 'test1 execute1' );
  $rc = 0;
  while ( my $d = $sth1->fetch ) {
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
  }
  if ( $sth1->err ) {
    $rc = $sth1->err;
  }
  ok( $rc == 0, "test1 fetch1" );
  $rc = $sth2->execute;
  ok( defined($rc), 'test1 execute2' );
  $rc = 0;
  while ( my $d = $sth2->fetch ) {
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
  }
  if ( $sth2->err ) {
    $rc = $sth2->err;
  }
  ok( $rc == 0, "test1 fetch2" );
}

# Same thing, with placeholders.
sub test2 {
  my $dbh = shift;

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

    my $rc;

    my $sth1 =
      $dbh->prepare("select * from master..sysprocesses where spid = ?");
    ok( defined($sth1), 'test2 prepare1' );
    my $sth2 = $dbh->prepare("select * from sysusers where uid = ?");
    ok( defined($sth2), 'test2 prepare2' );

    $rc = $sth1->execute(1);
    ok( defined($rc), 'test2 execute1' );
    $rc = 0;
    while ( my $d = $sth1->fetch ) {
      if ( $sth1->err ) {
        $rc = $sth1->err;
      }
    }
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
    ok( $rc == 0, "test2 fetch1" );
    $rc = $sth2->execute(1);
    ok( defined($rc), 'test2 execute2' );
    $rc = 0;
    while ( my $d = $sth2->fetch ) {
      if ( $sth2->err ) {
        $rc = $sth2->err;
      }
    }
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
    ok( $rc == 0, "test2 fetch2" );
  }    # SKIP
}

# Same thing, with placeholders.
sub test3 {
  my $dbh = shift;

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

    my $sth1 =
      $dbh->prepare("select * from master..sysprocesses where spid = ?");
    ok( defined($sth1), 'test3 prepare1' );
    my $sth2 = $dbh->prepare("select * from sysusers where uid = ?");
    ok( defined($sth2), 'test3 prepare2' );

    $rc = $sth1->execute(1);
    ok( defined($rc), 'test3 execute1' );

    # Interleaved execute()

    $rc = $sth2->execute(1);
    ok( defined($rc), 'test3 execute2' );

    $rc = 0;
    while ( my $d = $sth1->fetch ) {
      if ( $sth1->err ) {
        $rc = $sth1->err;
      }
    }
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
    ok( $rc == 0, "test3 fetch1" );

    $rc = 0;

    #DBI->trace(4);
    while ( my $d = $sth2->fetch ) {
      if ( $sth2->err ) {
        $rc = $sth2->err;
      }
    }
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
    ok( $rc == 0, "test3 fetch2" );
  }    #SKIP
}

# Same thing, first with placeholders, second without
sub test4 {
  my $dbh = shift;

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

    my $rc;

    my $sth1 =
      $dbh->prepare("select * from master..sysprocesses where spid = ?");
    ok( defined($sth1), 'test4 prepare1' );
    my $sth2 = $dbh->prepare("select * from sysusers");
    ok( defined($sth2), 'test4 prepare2' );

    $rc = $sth1->execute(1);
    ok( defined($rc), 'test4 execute1' );

    # Interleaved execute()
    $rc = $sth2->execute();
    ok( defined($rc), 'test4 execute2' );

    $rc = 0;
    while ( my $d = $sth1->fetch ) {
      if ( $sth1->err ) {
        $rc = $sth1->err;
      }
    }
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
    ok( $rc == 0, "test4 fetch1" );

    $rc = 0;

    #DBI->trace(4);
    while ( my $d = $sth2->fetch ) {
      if ( $sth2->err ) {
        $rc = $sth2->err;
      }
    }
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
    ok( $rc == 0, "test4 fetch2" );
  }    #SKIP
}

# This time, set the "no_child_con" flag, and execute the statements
# sequentially.
sub test5 {
  my $dbh = shift;

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

    $dbh->{syb_no_child_con} = 1;

    my $sth1 =
      $dbh->prepare("select * from master..sysprocesses where spid = ?");
    ok( defined($sth1), 'test5 prepare1' );

    $rc = $sth1->execute(1);
    ok( defined($rc), 'test5 execute1' );

    $rc = 0;
    while ( my $d = $sth1->fetch ) {
      if ( $sth1->err ) {
        $rc = $sth1->err;
      }
    }
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
    ok( $rc == 0, "test5 fetch1" );

    my $sth2 = $dbh->prepare("select * from sysusers");
    ok( defined($sth2), 'test5 prepare2' );
    $rc = $sth2->execute();
    ok( defined($rc), 'test5 execute2' );

    $rc = 0;

    #DBI->trace(4);
    while ( my $d = $sth2->fetch ) {
      if ( $sth2->err ) {
        $rc = $sth2->err;
      }
    }
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
    ok( $rc == 0, "test5 fetch2" );

    $rc = $sth1->execute(1);
    ok( defined($rc), 'test5 execute3' );

    $rc = 0;
    while ( my $d = $sth1->fetch ) {
      if ( $sth1->err ) {
        $rc = $sth1->err;
      }
    }
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
    ok( $rc == 0, "test5 fetch3" );
  }    #SKIP

  $dbh->{syb_no_child_con} = 0;

}

# This time, set the "no_child_con" flag, and execute the statements
# sequentially. Same as test5, but no dynamic SQL.
sub test6 {
  my $dbh = shift;

  my $rc;

  $dbh->{syb_no_child_con} = 1;

  my $sth1 = $dbh->prepare("select * from master..sysprocesses");
  ok( defined($sth1), 'test6 prepare1' );

  $rc = $sth1->execute();
  ok( defined($rc), 'test6 execute1' );

  $rc = 0;
  while ( my $d = $sth1->fetch ) {
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
  }
  if ( $sth1->err ) {
    $rc = $sth1->err;
  }
  ok( $rc == 0, "test6 fetch1" );

  my $sth2 = $dbh->prepare("select * from sysusers");
  ok( defined($sth2), 'test6 prepare2' );
  $rc = $sth2->execute();
  ok( defined($rc), 'test6 execute2' );

  $rc = 0;

  #DBI->trace(4);
  while ( my $d = $sth2->fetch ) {
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
  }
  if ( $sth2->err ) {
    $rc = $sth2->err;
  }
  ok( $rc == 0, "test6 fetch2" );

  $rc = $sth1->execute();
  ok( defined($rc), 'test6 execute3' );

  $rc = 0;
  while ( my $d = $sth1->fetch ) {
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
  }
  if ( $sth1->err ) {
    $rc = $sth1->err;
  }
  ok( $rc == 0, "test6 fetch3" );

  $dbh->{syb_no_child_con} = 0;

}

sub test_cached {
  my $dbh = shift;

  my $sth1 = $dbh->prepare_cached("select * from master..sysprocesses", undef, 0);
  ok( defined($sth1), "test_cache prepare1");
  my $rc = $sth1->execute();
  ok( defined($rc), "test_cache execute1");
  $rc = 0;
  while ( my $d = $sth1->fetch ) {
    if ( $sth1->err ) {
      $rc = $sth1->err;
    }
  }
  if ( $sth1->err ) {
    $rc = $sth1->err;
  }
  ok( $rc == 0, "test_cache fetch1" );


  my $sth2 = $dbh->prepare_cached("select * from master..sysprocesses", undef, 0);
  ok( defined($sth2), "test_cache prepare2");
  $rc = $sth2->execute();
  ok( defined($rc), "test_cache execute2");
  $rc = 0;
  while ( my $d = $sth2->fetch ) {
    if ( $sth2->err ) {
      $rc = $sth2->err;
    }
  }
  if ( $sth2->err ) {
    $rc = $sth2->err;
  }
  ok( $rc == 0, "test_cache fetch2" );

}