Skip to content

Commit

Permalink
Put custom column type test into a subtest
Browse files Browse the repository at this point in the history
This makes space for future tests.
  • Loading branch information
rbt committed Nov 28, 2022
1 parent 9bba803 commit 6403173
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions t/34-pg-types.t
Expand Up @@ -2,45 +2,49 @@ use v6;
use Test;
use DBIish::CommonTesting;

plan 9;
plan 2;

my %con-parms;
# If env var set, no parameter needed.
%con-parms<database> = 'dbdishtest' unless %*ENV<PGDATABASE>;
%con-parms<user> = 'postgres' unless %*ENV<PGUSER>;
my $dbh = DBIish::CommonTesting.connect-or-skip('Pg', |%con-parms);

ok $dbh, 'Connected';
ok $dbh, 'Connected';

# Be less verbose;
$dbh.execute('SET client_min_messages TO WARNING');
lives-ok {
$dbh.execute(q|
CREATE TEMPORARY TABLE test_types (
col1 text
)|)
}, 'Table created';
subtest 'Test changing column type' => {
# Be less verbose;
$dbh.execute('SET client_min_messages TO WARNING');
lives-ok {
$dbh.execute(q|
CREATE TEMPORARY TABLE test_types (
col1 text
)|)
}, 'Table created';

my $sth = $dbh.prepare('INSERT INTO test_types (col1) VALUES(?)');
lives-ok {
$sth.execute('test');
}, 'Insert Perl6 values';
$sth.dispose;
$sth = $dbh.prepare('SELECT col1 FROM test_types');
my @coltype = $sth.column-types;
ok @coltype eqv [Str], 'Column-types';
my $sth = $dbh.prepare('INSERT INTO test_types (col1) VALUES(?)');
lives-ok {
$sth.execute('test');
}, 'Insert Perl6 values';
$sth.dispose;
$sth = $dbh.prepare('SELECT col1 FROM test_types');
my @coltype = $sth.column-types;
ok @coltype eqv [Str], 'Column-types';

$sth.execute;
is $sth.rows, 1, '1 row';
my ($col1) = $sth.row;
isa-ok $col1, Str;
is $col1, 'test', 'Test';
$sth.execute;
is $sth.rows, 1, '1 row';
my ($col1) = $sth.row;
isa-ok $col1, Str;
is $col1, 'test', 'Test';

# Change the type conversion and start a new statement handle. Type conversions are fixed
# after the statement handle is prepared.
$dbh.Converter{Str} = sub ($) { 'changed' };
$sth = $dbh.prepare('SELECT col1 FROM test_types');
$sth.execute;
is $sth.rows, 1, '1 row';
($col1) = $sth.row;
is $col1, 'changed', 'Changed';
# Change the type conversion and start a new statement handle. Type conversions are fixed
# after the statement handle is prepared.
$dbh.Converter{Str} = sub ($) {
'changed'
};
$sth = $dbh.prepare('SELECT col1 FROM test_types');
$sth.execute;
is $sth.rows, 1, '1 row';
($col1) = $sth.row;
is $col1, 'changed', 'Changed';
}

0 comments on commit 6403173

Please sign in to comment.