$sth->{TYPE} returning different values than DBD::mysql
ysth opened this issue · 8 comments
Using DBD::MariaDB 1.00 and mariadb 10.0.36-MariaDB-0ubuntu0.16.04.1 on ubuntu 16.04, I am seeing differences in the TYPE attribute of a statement handle than DBD::mysql 4.033 reported. This is my test table:
CREATE TABLE `bar` (
`bigint` bigint(20) DEFAULT NULL,
`bit` bit(6) DEFAULT NULL,
`decimal` decimal(10,0) DEFAULT NULL,
`double` double DEFAULT NULL,
`float` float DEFAULT NULL,
`int` int(11) DEFAULT NULL,
`smallint` smallint(6) DEFAULT NULL,
`tinyint` tinyint(4) DEFAULT NULL,
`date` date DEFAULT NULL,
`time` time DEFAULT NULL,
`datetime` datetime DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`mediumint` mediumint(9) DEFAULT NULL,
`year` year(4) DEFAULT NULL,
`char` char(1) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`varchar` varchar(1) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`binary` binary(1) DEFAULT NULL,
`varbinary` varbinary(1) DEFAULT NULL,
`enum` enum('1') COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`set` set('1') COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`tinyblob` tinyblob,
`tinytext` tinytext COLLATE utf8mb4_unicode_520_ci,
`blob` blob,
`text` text COLLATE utf8mb4_unicode_520_ci,
`mediumblob` mediumblob,
`mediumtext` mediumtext COLLATE utf8mb4_unicode_520_ci,
`longblob` longblob,
`longtext` longtext COLLATE utf8mb4_unicode_520_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
and these are the TYPE values returned for the mariadb and mysql clients:
{
"bigint" : {
"maria" : 18446744073709551611,
"mysql" : -5
},
"binary" : {
"maria" : 1,
"mysql" : 1
},
"bit" : {
"maria" : 18446744073709551609,
"mysql" : 12
},
"blob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"char" : {
"maria" : 1,
"mysql" : 1
},
"date" : {
"maria" : 9,
"mysql" : 9
},
"datetime" : {
"maria" : 11,
"mysql" : 11
},
"decimal" : {
"maria" : 3,
"mysql" : 3
},
"double" : {
"maria" : 8,
"mysql" : 8
},
"enum" : {
"maria" : 1,
"mysql" : 1
},
"float" : {
"maria" : 6,
"mysql" : 7
},
"int" : {
"maria" : 4,
"mysql" : 4
},
"longblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"longtext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"mediumblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"mediumint" : {
"maria" : 4,
"mysql" : 4
},
"mediumtext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"set" : {
"maria" : 1,
"mysql" : 1
},
"smallint" : {
"maria" : 5,
"mysql" : 5
},
"text" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"time" : {
"maria" : 10,
"mysql" : 10
},
"timestamp" : {
"maria" : 11,
"mysql" : 11
},
"tinyblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"tinyint" : {
"maria" : 18446744073709551610,
"mysql" : -6
},
"tinytext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
"varbinary" : {
"maria" : 12,
"mysql" : 12
},
"varchar" : {
"maria" : 12,
"mysql" : 12
},
"year" : {
"maria" : 5,
"mysql" : 5
}
}
If it makes a difference,
DBD::mysql is linked to libmysqlclient.so.20 5.7.23,
DBD::MariaBD is linked to libmariadb.so.2 2.0.0
Thanks for report!
Problems with negative numbers was introduced by 156d826 - TYPE
is signed, so it should not be treated as unsigned (using newSVuv
).
Value 12 for bit
for mysql
looks like problem in DBD::mysql
- is should be -7 (12 is varchar
).
Hi @ysth! As @janchochol pointed, the main problem is with negative numbers. They are reported in (64bit) two's complement... This is bug in DBD::MariaDB and I will fix it.
Numbers belongs to DBI SQL types and they correspond to standard ANSI/ODBC SQL types. See file where are DBI SQL types defined: https://metacpan.org/source/TIMB/DBI-1.642/dbi_sql.h
Below are comments for mysql/maria differences:
"bigint" : {
"maria" : 18446744073709551611,
"mysql" : -5
},
18446744073709551611-2^64 = -5, so same
"bit" : {
"maria" : 18446744073709551609,
"mysql" : 12
},
18446744073709551609-2^64 = -7
12 - SQL_VARCHAR
-7 - SQL_BIT
Therefore this looks like DBD::mysql bug. bit should be of SQL_BIT type, not SQL_VARCHAR.
"blob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"float" : {
"maria" : 6,
"mysql" : 7
},
6 - SQL_FLOAT
7 - SQL_REAL
Again possible bug in DBD::mysql. Float should be SQL_FLOAT.
"longblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"longtext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"mediumblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"mediumtext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"text" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"tinyblob" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
"tinyint" : {
"maria" : 18446744073709551610,
"mysql" : -6
},
18446744073709551610-2^64 = -6
"tinytext" : {
"maria" : 18446744073709551612,
"mysql" : -4
},
18446744073709551612-2^64 = -4
Thanks @pali! I see there's been a lot of work since 1.00; will there be a 1.01 release soon?
Yes! We are going to release a new version soon.
@pali yes, it fixes the issue. Thanks! We're starting a new round of tests of switching drivers and converting databases to utf8mb4 on Wednesday (morning pacific time). If you would be able to push out a beta release to cpan or at least bump the version number in github, that would be appreciated; I'm reluctant to use code that says it is version 1.00 when it isn't or to make up my own version number.
@ysth New version 1.10 is now on CPAN: https://metacpan.org/release/PALI/DBD-MariaDB-1.10