Skip to content

Commit

Permalink
Add test for large text values
Browse files Browse the repository at this point in the history
  • Loading branch information
rbt committed Jun 1, 2020
1 parent 17e9659 commit 0de9dc0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions t/24-mysql-large-value.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use v6;
use Test;
use DBIish;

plan 21;
my %con-parms = :database<dbdishtest>, :user<testuser>, :password<testpass>;
my $dbh;

# Test buffer size scaling

try {
$dbh = DBIish.connect('mysql', |%con-parms);
CATCH {
when X::DBIish::LibraryMissing | X::DBDish::ConnectionFailed {
diag "$_\nCan't continue.";
}
default { .throw; }
}
}
without $dbh {
skip-rest 'prerequisites failed';
exit;
}

ok $dbh, 'Connected';
lives-ok {
$dbh.do(qq|
CREATE TEMPORARY TABLE test_long_string (
col1 varchar(16383)
)|)
}, 'Table created';

my @string-lengths = 100, 8191, 8192, 8193, 10_000, 16383;
my @long-strings;
for @string-lengths -> $length {
@long-strings.push('x' x $length);
}

my $sth = $dbh.prepare('INSERT INTO test_long_string (col1) VALUES(?)');
for @long-strings -> $string {
lives-ok {
$sth.execute($string);
}, 'Add value: %d chars'.sprintf($string.chars);
}
$sth.dispose;

$sth = $dbh.prepare('SELECT col1 FROM test_long_string ORDER BY length(col1)');

is $sth.execute, @long-strings.elems, '%d row'.sprintf(@long-strings.elems);

# Compare both source and DB long strings in order by length.
for @long-strings -> $string {
my ($col1) = $sth.row;

isa-ok $col1, Str;
is $col1, $string, 'Value: %d chars'.sprintf($string.chars) ;
}



0 comments on commit 0de9dc0

Please sign in to comment.