Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle Num and Rat as MYSQL_TYPE_DOUBLE
This matches the behaviour of the perl DBD::mysql driver. The test confirms that the fields are created as "double", and that strings which look like numbers remain a string.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use v6; | ||
use Test; | ||
use DBIish::CommonTesting; | ||
|
||
plan 1; | ||
my %con-parms = :database<dbdishtest>, :user<testuser>, :password<testpass>; | ||
%con-parms<host> = %*ENV<MYSQL_HOST> if %*ENV<MYSQL_HOST>; | ||
my $dbh = DBIish::CommonTesting.connect-or-skip('mysql', |%con-parms); | ||
|
||
subtest 'Num and Rat are numbers' => { | ||
$dbh.execute('CREATE TEMPORARY TABLE tmp_num_test AS SELECT ? as num, ? as rat, ? as unspecified, ? as str', | ||
2.0.Num, 2.0.Rat, 2.0, '2.0'); | ||
my $sth = $dbh.execute('SELECT * FROM tmp_num_test'); | ||
my ($num, $rat, $unspecified, $string) = $sth.row; | ||
is $num, 2.0.Num, 'Num value roundtriped'; | ||
is $rat, 2.0.Rat, 'Rat value roundtriped'; | ||
is $unspecified, 2.0.Num, 'Unspecified was treated as Num'; | ||
is $string, '2.0', 'Str value roundtriped'; | ||
|
||
$sth = $dbh.execute('describe tmp_num_test'); | ||
while my $row = $sth.row { | ||
my ($col-name, $datatype-buf) = $row; | ||
my $datatype = $datatype-buf.decode; | ||
my $expected-type = $col-name eq 'str' ?? 'varchar(3)' !! 'double'; | ||
is $datatype, $expected-type, "$col-name type is $expected-type"; | ||
} | ||
} |