summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <dkatz@damien-katzs-computer.local>2007-09-05 15:06:10 -0400
committerunknown <dkatz@damien-katzs-computer.local>2007-09-05 15:06:10 -0400
commit0a28cac0b627a0a4990c8cb942ade39261fb1007 (patch)
tree40d64f8c92a6bd938bafcb55e01986312ad4a73c /sql
parent3e7b724c69b26d976d91312d4264d4c42deccde5 (diff)
downloadmariadb-git-0a28cac0b627a0a4990c8cb942ade39261fb1007.tar.gz
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 too. mysql-test/r/udf.result: Test case to check constants passed UDFs. mysql-test/t/udf.test: Test case to check constants passed UDFs. sql/item_func.cc: 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: Added check_const_len functions. The check_const_len_init functions checks that the lengths of constants are correctly passed. sql/udf_example.def: Add new example functions to windows dll export list.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/udf_example.c35
-rw-r--r--sql/udf_example.def2
3 files changed, 39 insertions, 1 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index c70cfa1ce2a..21579763635 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2924,7 +2924,8 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func,
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 --git a/sql/udf_example.c b/sql/udf_example.c
index 0f28c2a14b0..df3a69755ad 100644
--- a/sql/udf_example.c
+++ b/sql/udf_example.c
@@ -1106,4 +1106,39 @@ char * is_const(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
}
+
+my_bool check_const_len_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+ if (args->arg_count != 1)
+ {
+ strmov(message, "CHECK_CONST_LEN accepts only one argument");
+ return 1;
+ }
+ if (args->args[0] == 0)
+ {
+ initid->ptr= (char*)"Not constant";
+ }
+ else if(strlen(args->args[0]) == args->lengths[0])
+ {
+ initid->ptr= (char*)"Correct length";
+ }
+ else
+ {
+ initid->ptr= (char*)"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 */
diff --git a/sql/udf_example.def b/sql/udf_example.def
index 7a87147d7b6..3d569941cc8 100644
--- a/sql/udf_example.def
+++ b/sql/udf_example.def
@@ -23,3 +23,5 @@ EXPORTS
avgcost
is_const
is_const_init
+ check_const_len
+ check_const_len_init