summaryrefslogtreecommitdiff
path: root/sql/item_cmpfunc.cc
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2004-08-11 23:08:20 +0400
committerunknown <sergefp@mysql.com>2004-08-11 23:08:20 +0400
commitb37a73611024d78de35145c5f6cb394a7c3f225c (patch)
tree4773c593bb7d7e615217ae75cc62fdda42923650 /sql/item_cmpfunc.cc
parentcffa34d9fba41ca853e7f11c88e5962382b6219c (diff)
downloadmariadb-git-b37a73611024d78de35145c5f6cb394a7c3f225c.tar.gz
Fix for BUG#4488: first portion: sign aware '<' and '>' comparisons.
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r--sql/item_cmpfunc.cc87
1 files changed, 87 insertions, 0 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 14c0d996360..e7531e17d34 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -315,6 +315,17 @@ int Arg_comparator::set_compare_func(Item_bool_func2 *item, Item_result type)
func= &Arg_comparator::compare_e_binary_string;
}
}
+ else if (type == INT_RESULT)
+ {
+ if (func == &Arg_comparator::compare_int)
+ {
+ if ((*a)->unsigned_flag)
+ func= ((*b)->unsigned_flag)? &Arg_comparator::compare_int_unsigned :
+ &Arg_comparator::compare_int_unsigned_signed;
+ else if ((*b)->unsigned_flag)
+ func= &Arg_comparator::compare_int_signed_unsigned;
+ }
+ }
return 0;
}
@@ -434,6 +445,82 @@ int Arg_comparator::compare_int()
return -1;
}
+
+/*
+ Compare values as BIGINT UNSIGNED.
+*/
+
+int Arg_comparator::compare_int_unsigned()
+{
+ ulonglong val1= (*a)->val_int();
+ if (!(*a)->null_value)
+ {
+ ulonglong val2= (*b)->val_int();
+ if (!(*b)->null_value)
+ {
+ owner->null_value= 0;
+ if (val1 < val2) return -1;
+ if (val1 == val2) return 0;
+ return 1;
+ }
+ }
+ owner->null_value= 1;
+ return -1;
+}
+
+
+/*
+ Compare signed (*a) with unsigned (*B)
+*/
+
+int Arg_comparator::compare_int_signed_unsigned()
+{
+ longlong sval1= (*a)->val_int();
+ if (!(*a)->null_value)
+ {
+ ulonglong uval2= (ulonglong)(*b)->val_int();
+ if (!(*b)->null_value)
+ {
+ owner->null_value= 0;
+ if (sval1 < 0 || (ulonglong)sval1 < uval2)
+ return -1;
+ if ((ulonglong)sval1 == uval2)
+ return 0;
+ return 1;
+ }
+ }
+ owner->null_value= 1;
+ return -1;
+}
+
+
+/*
+ Compare unsigned (*a) with signed (*B)
+*/
+
+int Arg_comparator::compare_int_unsigned_signed()
+{
+ ulonglong uval1= (ulonglong)(*a)->val_int();
+ if (!(*a)->null_value)
+ {
+ longlong sval2= (*b)->val_int();
+ if (!(*b)->null_value)
+ {
+ owner->null_value= 0;
+ if (sval2 < 0)
+ return 1;
+ if (uval1 < (ulonglong)sval2)
+ return -1;
+ if (uval1 == (ulonglong)sval2)
+ return 0;
+ return 1;
+ }
+ }
+ owner->null_value= 1;
+ return -1;
+}
+
+
int Arg_comparator::compare_e_int()
{
longlong val1= (*a)->val_int();