~stewart/dbd-drizzle/fixup-for-modern-perl

« back to all changes in this revision

Viewing changes to t_old/40blobs.t

  • Committer: Patrick
  • Date: 2009-04-20 01:10:02 UTC
  • mfrom: (19.1.6 dbd-drizzle-ng)
  • Revision ID: patg@testpatg.com-20090420011002-yif1wb9jmcwawenn
Pre-release clean-up

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!perl -w
2
 
# vim: ft=perl
3
 
#
4
 
#   $Id: 40blobs.t 11244 2008-05-11 15:13:10Z capttofu $
5
 
#
6
 
#   This is a test for correct handling of BLOBS; namely $dbh->quote
7
 
#   is expected to work correctly.
8
 
#
9
 
 
10
 
 
11
 
use DBI ();
12
 
use Test::More;
13
 
use vars qw($table $test_dsn $test_user $test_password);
14
 
use lib '.', 't';
15
 
require 'lib.pl';
16
 
 
17
 
sub ShowBlob($) {
18
 
    my ($blob) = @_;
19
 
    for ($i = 0;  $i < 8;  $i++) {
20
 
        if (defined($blob)  &&  length($blob) > $i) {
21
 
            $b = substr($blob, $i*32);
22
 
        }
23
 
        else {
24
 
            $b = "";
25
 
        }
26
 
        printf("%08lx %s\n", $i*32, unpack("H64", $b));
27
 
    }
28
 
}
29
 
 
30
 
my $dbh;
31
 
eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
32
 
  { RaiseError => 1, AutoCommit => 1}) or ServerError() ;};
33
 
 
34
 
if ($@) {
35
 
    plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
36
 
}
37
 
plan tests => 14;
38
 
 
39
 
my $size= 128;
40
 
 
41
 
ok $dbh->do("DROP TABLE IF EXISTS $table"), "Drop table if exists $table";
42
 
 
43
 
my $create = <<EOT;
44
 
CREATE TABLE $table (
45
 
    id INT(3) NOT NULL DEFAULT 0,
46
 
    name BLOB ) DEFAULT CHARSET=utf8
47
 
EOT
48
 
 
49
 
ok ($dbh->do($create));
50
 
 
51
 
my ($blob, $qblob) = "";
52
 
my $b = "";
53
 
for ($j = 0;  $j < 256;  $j++) {
54
 
    $b .= chr($j);
55
 
}
56
 
for ($i = 0;  $i < $size;  $i++) {
57
 
    $blob .= $b;
58
 
}
59
 
ok ($qblob = $dbh->quote($blob));
60
 
 
61
 
#   Insert a row into the test table.......
62
 
my ($query);
63
 
$query = "INSERT INTO $table VALUES(1, $qblob)";
64
 
ok ($dbh->do($query));
65
 
 
66
 
#   Now, try SELECT'ing the row out.
67
 
ok ($sth = $dbh->prepare("SELECT * FROM $table WHERE id = 1"));
68
 
 
69
 
ok ($sth->execute);
70
 
 
71
 
ok ($row = $sth->fetchrow_arrayref);
72
 
 
73
 
ok defined($row), "row returned defined";
74
 
 
75
 
is @$row, 2, "records from $table returned 2";
76
 
 
77
 
is $$row[0], 1, 'id set to 1';
78
 
 
79
 
cmp_ok byte_string($$row[1]), 'eq', byte_string($blob), 'blob set equal to blob returned';
80
 
 
81
 
ShowBlob($blob), ShowBlob(defined($$row[1]) ? $$row[1] : "");
82
 
 
83
 
ok ($sth->finish);
84
 
 
85
 
ok $dbh->do("DROP TABLE $table"), "Drop table $table";
86
 
 
87
 
ok $dbh->disconnect;