File: rt76506.t

package info (click to toggle)
libdbd-firebird-perl 1.24-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 728 kB
  • sloc: perl: 4,419; ansic: 2,367; makefile: 12
file content (81 lines) | stat: -rw-r--r-- 1,557 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

use strict;
use warnings;
use utf8;
BEGIN {
    binmode(STDERR, ':utf8');
    binmode(STDOUT, ':utf8');
};

use Test::More;
use lib 't','.';

use TestFirebird;
my $T = TestFirebird->new;

my ($dbh, $error_str) = $T->connect_to_database;

if ($error_str) {
    BAIL_OUT("Unknown: $error_str!");
}

unless ( $dbh->isa('DBI::db') ) {
    plan skip_all => 'Connection to database failed, cannot continue testing';
}
else {
    plan tests => 12;
}

ok($dbh, 'Connected to the database');

# ------- TESTS ------------------------------------------------------------- #

#
#   Find new table name
#
my $table = find_new_table($dbh);
ok($table, qq{Table is '$table'});

#
#   Create a new table
#
my $def =<<"DEF";
CREATE TABLE $table (
    CHAR_TEST   CHAR(10) CHARACTER SET UTF8
)
DEF
ok( $dbh->do($def), qq{CREATE TABLE '$table'} );

#
# Prepare insert
#

my $stmt =<<"END_OF_QUERY";
INSERT INTO $table (CHAR_TEST) VALUES (?)
END_OF_QUERY

ok(my $cursor = $dbh->prepare($stmt), 'PREPARE INSERT');
ok($cursor->execute('TEST'), "INSERT in $table");

ok( my $cursor2 = $dbh->prepare(
        "SELECT CHAR_TEST FROM $table",
    ),
    'PREPARE SELECT'
);
ok($cursor2->execute, 'SELECT');
ok(my $hash_ref = $cursor2->fetchrow_hashref, 'FETCHALL hashref');
my $char_test = $hash_ref->{CHAR_TEST};
is(length $char_test, 10, 'Match length');
diag(">>$char_test<<");
ok($cursor2->finish, 'FINISH');

#
#  Drop the test table
#
ok($dbh->do("DROP TABLE $table"), "DROP TABLE '$table'");

#
#   Finally disconnect.
#
ok($dbh->disconnect(), 'DISCONNECT');