~ubuntu-branches/ubuntu/precise/libdbd-pg-perl/precise

« back to all changes in this revision

Viewing changes to t/12placeholders.t

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2008-12-15 20:20:37 UTC
  • mfrom: (1.1.18 upstream) (4.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20081215202037-zey31ccjr422db1b
Tags: 2.11.7-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
if (! defined $dbh) {
16
16
        plan skip_all => 'Connection to database failed, cannot continue testing';
17
17
}
18
 
plan tests => 28;
 
18
plan tests => 45;
19
19
 
20
20
my $t='Connect to database for placeholder testing';
21
21
isnt ($dbh, undef, $t);
232
232
};
233
233
is ($@, q{}, $t);
234
234
 
 
235
$t='Prepare works with placeholders after double slashes';
 
236
eval {
 
237
        $dbh->do(q{CREATE OPERATOR // ( PROCEDURE=bit, LEFTARG=int, RIGHTARG=int )});
 
238
        $sth = $dbh->prepare(q{SELECT ? // ?});
 
239
        $sth->execute(1,2);
 
240
        $sth->finish();
 
241
};
 
242
is ($@, q{}, $t);
 
243
 
 
244
$t='Dollar quotes starting with a number are not treated as valid identifiers';
 
245
eval {
 
246
        $sth = $dbh->prepare(q{SELECT $123$  $123$});
 
247
        $sth->execute(1);
 
248
        $sth->finish();
 
249
};
 
250
like ($@, qr{Invalid placeholders}, $t);
 
251
 
 
252
$t='Dollar quotes with invalid characters are not parsed as identifiers';
 
253
for my $char (qw!+ / : @ [ `!) {
 
254
        eval {
 
255
                $sth = $dbh->prepare(qq{SELECT \$abc${char}\$ 123 \$abc${char}\$});
 
256
                $sth->execute();
 
257
                $sth->finish();
 
258
        };
 
259
        like ($@, qr{syntax error}, $t);
 
260
}
 
261
 
 
262
$t='Dollar quotes with valid characters are parsed as identifiers';
 
263
$dbh->rollback();
 
264
for my $char (qw{0 9 A Z a z}) {
 
265
        eval {
 
266
                $sth = $dbh->prepare(qq{SELECT \$abc${char}\$ 123 \$abc${char}\$});
 
267
                $sth->execute();
 
268
                $sth->finish();
 
269
        };
 
270
        is ($@, q{}, $t);
 
271
}
 
272
 
 
273
$t='Backslash quoting inside double quotes is parsed correctly';
 
274
eval {
 
275
        $sth = $dbh->prepare(q{SELECT * FROM "\" WHERE a=?});
 
276
        $sth->execute(1);
 
277
        $sth->finish();
 
278
};
 
279
like ($@, qr{relation ".*" does not exist}, $t);
 
280
$dbh->rollback();
 
281
 
 
282
SKIP: {
 
283
        skip 'Setting standard_conforming_strings not available', 2 if ! defined $scs;
 
284
        $t='Backslash quoting inside single quotes is parsed correctly with standard_conforming_strings off';
 
285
        eval {
 
286
                $dbh->do(q{SET standard_conforming_strings = 'off'});
 
287
                $sth = $dbh->prepare(q{SELECT '\', ?});
 
288
                $sth->execute();
 
289
                $sth->finish();
 
290
        };
 
291
        like ($@, qr{unterminated quoted string}, $t);
 
292
        $dbh->rollback();
 
293
 
 
294
        $t='Backslash quoting inside single quotes is parsed correctly with standard_conforming_strings on';
 
295
        eval {
 
296
                $dbh->do(q{SET standard_conforming_strings = 'on'});
 
297
                $sth = $dbh->prepare(q{SELECT '\', ?::int});
 
298
                $sth->execute(1);
 
299
                $sth->finish();
 
300
        };
 
301
        is ($@, q{}, $t);
 
302
}
 
303
 
235
304
## Begin custom type testing
236
305
 
237
 
 
238
 
 
239
 
 
240
306
$dbh->rollback();
241
307
 
242
308
cleanup_database($dbh,'test');