summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-07-24 09:18:50 +0200
committerSergei Golubchik <serg@mariadb.org>2021-07-24 10:14:30 +0200
commiteaae13059f413647f8a406b52f212d70dca69661 (patch)
tree8ac8efb616e240431175f962b305d3c7166bcfe8
parent9fde2bbacf79557aa7f0a959a77aa4f6226dc8d9 (diff)
downloadmariadb-git-eaae13059f413647f8a406b52f212d70dca69661.tar.gz
MDEV-25808 PREPARE/EXECUTE makes signed integer out of unsigned
Closes #1844
-rw-r--r--mysql-test/main/prepare.result14
-rw-r--r--mysql-test/main/prepare.test12
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item.h4
4 files changed, 33 insertions, 5 deletions
diff --git a/mysql-test/main/prepare.result b/mysql-test/main/prepare.result
index c1a2969212b..cfe6603dbbe 100644
--- a/mysql-test/main/prepare.result
+++ b/mysql-test/main/prepare.result
@@ -50,3 +50,17 @@ t1_first
deallocate prepare stmt1;
deallocate prepare stmt2;
drop table t1;
+#
+# MDEV-25808 PREPARE/EXECUTE makes signed integer out of unsigned
+#
+prepare p1 from 'select concat(?)';
+execute p1 using 17864960750176564435;
+concat(?)
+17864960750176564435
+prepare p1 from 'select SQRT(?) is not null';
+execute p1 using 17864960750176564435;
+SQRT(?) is not null
+1
+#
+# End of 10.3 tests
+#
diff --git a/mysql-test/main/prepare.test b/mysql-test/main/prepare.test
index eaab376a5a2..4d1573eb0c8 100644
--- a/mysql-test/main/prepare.test
+++ b/mysql-test/main/prepare.test
@@ -40,3 +40,15 @@ execute stmt2;
deallocate prepare stmt1;
deallocate prepare stmt2;
drop table t1;
+
+--echo #
+--echo # MDEV-25808 PREPARE/EXECUTE makes signed integer out of unsigned
+--echo #
+prepare p1 from 'select concat(?)';
+execute p1 using 17864960750176564435;
+prepare p1 from 'select SQRT(?) is not null';
+execute p1 using 17864960750176564435;
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
diff --git a/sql/item.cc b/sql/item.cc
index f91705bfaff..7f00cd2bdc6 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4592,13 +4592,15 @@ bool Item_param::get_date(MYSQL_TIME *res, ulonglong fuzzydate)
}
-double Item_param::PValue::val_real() const
+double Item_param::PValue::val_real(const Type_std_attributes *attr) const
{
switch (type_handler()->cmp_type()) {
case REAL_RESULT:
return real;
case INT_RESULT:
- return (double) integer;
+ return attr->unsigned_flag
+ ? (double) (ulonglong) integer
+ : (double) integer;
case DECIMAL_RESULT:
{
double result;
@@ -4680,7 +4682,7 @@ String *Item_param::PValue::val_str(String *str,
str->set_real(real, NOT_FIXED_DEC, &my_charset_bin);
return str;
case INT_RESULT:
- str->set(integer, &my_charset_bin);
+ str->set_int(integer, attr->unsigned_flag, &my_charset_bin);
return str;
case DECIMAL_RESULT:
if (my_decimal2string(E_DEC_FATAL_ERROR, &m_decimal, 0, 0, 0, str) <= 1)
diff --git a/sql/item.h b/sql/item.h
index ebea56217a8..4c78ed0ea3d 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -3565,7 +3565,7 @@ class Item_param :public Item_basic_value,
m_string.swap(other.m_string);
m_string_ptr.swap(other.m_string_ptr);
}
- double val_real() const;
+ double val_real(const Type_std_attributes *attr) const;
longlong val_int(const Type_std_attributes *attr) const;
my_decimal *val_decimal(my_decimal *dec, const Type_std_attributes *attr);
String *val_str(String *str, const Type_std_attributes *attr);
@@ -3619,7 +3619,7 @@ public:
double val_real()
{
- return can_return_value() ? value.val_real() : 0e0;
+ return can_return_value() ? value.val_real(this) : 0e0;
}
longlong val_int()
{