Below is the list of changes that have just been committed into a local
5.0 repository of dkatz. When dkatz does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-08-03 16:12:23-04:00, dkatz@stripped +4 -0
Bug #29804 UDF parameters don't contain correct string length
Previously, UDF *_init functions were passed constant strings with erroneous lengths.
The length came from the containing variable's size, not the length of the value itself.
Now the *_init functions get the constant as a null terminated string with the correct
length supplied.
mysql-test/r/udf.result@stripped, 2007-08-03 16:12:20-04:00,
dkatz@stripped +24 -0
Test case to check constants passed UDFs.
mysql-test/t/udf.test@stripped, 2007-08-03 16:12:20-04:00, dkatz@stripped
+36 -0
Test case to check constants passed UDFs.
sql/item_func.cc@stripped, 2007-08-03 16:12:20-04:00, dkatz@stripped +2
-1
UDF _init functions are now passed the length of the constants, rather than the max
length of the var containing the constant.
sql/udf_example.c@stripped, 2007-08-03 16:12:21-04:00, dkatz@stripped +35
-0
Added check_const_len functions. The check_const_len_init functions checks that the
lengths of constants are correctly passed.
diff -Nrup a/mysql-test/r/udf.result b/mysql-test/r/udf.result
--- a/mysql-test/r/udf.result 2007-06-18 17:55:07 -04:00
+++ b/mysql-test/r/udf.result 2007-08-03 16:12:20 -04:00
@@ -296,4 +296,28 @@ Qcache_queries_in_cache 0
drop table t1;
drop function metaphon;
set GLOBAL query_cache_size=default;
+CREATE TABLE const_len_bug (
+str_const varchar(4000),
+result1 varchar(4000),
+result2 varchar(4000)
+);
+CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN
+set NEW.str_const = 'bar';
+set NEW.result2 = check_const_len(NEW.str_const);
+END |
+CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000))
+BEGIN
+DECLARE result VARCHAR(4000);
+SET result = check_const_len(str_const);
+insert into const_len_bug values(str_const, result, "");
+END |
+CREATE FUNCTION check_const_len RETURNS string SONAME "UDF_EXAMPLE_LIB";
+CALL check_const_len_sp("foo");
+SELECT * from const_len_bug;
+str_const result1 result2
+bar Correct length Correct length
+DROP FUNCTION check_const_len;
+DROP PROCEDURE check_const_len_sp;
+DROP TRIGGER check_const_len_trigger;
+DROP TABLE const_len_bug;
End of 5.0 tests.
diff -Nrup a/mysql-test/t/udf.test b/mysql-test/t/udf.test
--- a/mysql-test/t/udf.test 2007-06-18 17:55:07 -04:00
+++ b/mysql-test/t/udf.test 2007-08-03 16:12:20 -04:00
@@ -312,4 +312,40 @@ drop function metaphon;
set GLOBAL query_cache_size=default;
+#
+# Bug #29804 UDF parameters don't contain correct string length
+#
+
+CREATE TABLE const_len_bug (
+ str_const varchar(4000),
+ result1 varchar(4000),
+ result2 varchar(4000)
+);
+
+DELIMITER |;
+CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN
+ set NEW.str_const = 'bar';
+ set NEW.result2 = check_const_len(NEW.str_const);
+END |
+
+CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000))
+BEGIN
+DECLARE result VARCHAR(4000);
+SET result = check_const_len(str_const);
+insert into const_len_bug values(str_const, result, "");
+END |
+DELIMITER ;|
+
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION check_const_len RETURNS string SONAME "$UDF_EXAMPLE_LIB";
+
+CALL check_const_len_sp("foo");
+
+SELECT * from const_len_bug;
+
+DROP FUNCTION check_const_len;
+DROP PROCEDURE check_const_len_sp;
+DROP TRIGGER check_const_len_trigger;
+DROP TABLE const_len_bug;
+
--echo End of 5.0 tests.
diff -Nrup a/sql/item_func.cc b/sql/item_func.cc
--- a/sql/item_func.cc 2007-08-02 05:51:00 -04:00
+++ b/sql/item_func.cc 2007-08-03 16:12:20 -04:00
@@ -2924,7 +2924,8 @@ udf_handler::fix_fields(THD *thd, Item_r
String *res= arguments[i]->val_str(&buffers[i]);
if (arguments[i]->null_value)
continue;
- f_args.args[i]= (char*) res->ptr();
+ f_args.args[i]= (char*) res->c_ptr();
+ f_args.lengths[i]= res->length();
break;
}
case INT_RESULT:
diff -Nrup a/sql/udf_example.c b/sql/udf_example.c
--- a/sql/udf_example.c 2007-05-31 08:22:19 -04:00
+++ b/sql/udf_example.c 2007-08-03 16:12:21 -04:00
@@ -1106,4 +1106,39 @@ char * is_const(UDF_INIT *initid, UDF_AR
}
+
+my_bool check_const_len_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+ if (args->arg_count != 1)
+ {
+ strmov(message, "IS_CONST accepts only one argument");
+ return 1;
+ }
+ if (args->args[0] == 0)
+ {
+ initid->ptr= "Not constant";
+ }
+ else if(strlen(args->args[0]) == args->lengths[0])
+ {
+ initid->ptr= "Correct length";
+ }
+ else
+ {
+ initid->ptr= "Wrong length";
+ }
+ initid->max_length = 100;
+ return 0;
+}
+
+char * check_const_len(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
+ char *result, unsigned long *length,
+ char *is_null, char *error __attribute__((unused)))
+{
+ strmov(result, initid->ptr);
+ *length= strlen(result);
+ *is_null= 0;
+ return result;
+}
+
+
#endif /* HAVE_DLOPEN */
| Thread |
|---|
| • bk commit into 5.0 tree (dkatz:1.2502) BUG#29804 | damien | 3 Aug |