From baf1c89e3d66bd4d66555b3662d522adbabca505 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Nov 2004 18:20:40 +0400 Subject: [PATCH 1/4] A fix (bug #6564: QUOTE(NULL) returns NULL, not the string 'NULL') --- mysql-test/r/func_str.result | 5 ++++- mysql-test/t/func_str.test | 6 ++++++ sql/item_strfunc.cc | 14 +++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index b4d1be5bd54..d38a2edfa1a 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -167,6 +167,9 @@ length(quote(concat(char(0),"test"))) select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))); hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))) 27E0E3E6E7E8EAEB27 +select concat('a', quote(NULL)); +concat('a', quote(NULL)) +aNULL select reverse(""); reverse("") @@ -278,7 +281,7 @@ insert into t1 values ('one'),(NULL),('two'),('four'); select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1; a quote(a) isnull(quote(a)) quote(a) is null ifnull(quote(a), 'n') one 'one' 0 0 'one' -NULL NULL 1 1 n +NULL NULL 0 0 NULL two 'two' 0 0 'two' four 'four' 0 0 'four' drop table t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index ba6a8b55236..1ae4db3a42a 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -69,6 +69,12 @@ select quote(1/0), quote('\0\Z'); select length(quote(concat(char(0),"test"))); select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))); +# +# Bug #6564: QUOTE(NULL +# + +select concat('a', quote(NULL)); + # # Wrong usage of functions # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9248cbc0217..53a9d3fe219 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2142,9 +2142,12 @@ String* Item_func_inet_ntoa::val_str(String* str) This function is very useful when you want to generate SQL statements - RETURN VALUES + NOTE + QUOTE(NULL) returns the string 'NULL' (4 letters, without quotes). + + RETURN VALUES str Quoted string - NULL Argument to QUOTE() was NULL or out of memory. + NULL Out of memory. */ #define get_esc_bit(mask, num) (1 & (*((mask) + ((num) >> 3))) >> ((num) & 7)) @@ -2168,7 +2171,12 @@ String *Item_func_quote::val_str(String *str) String *arg= args[0]->val_str(str); uint arg_length, new_length; if (!arg) // Null argument - goto null; + { + str->copy("NULL", 4); // Return the string 'NULL' + null_value= 0; + return str; + } + arg_length= arg->length(); new_length= arg_length+2; /* for beginning and ending ' signs */ From c7b66f9ddefb95050c21a9938578a0f56d9dd0d0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Nov 2004 19:22:58 +0200 Subject: [PATCH 2/4] Removed an unneccessary for() and variable. --- mysys/default.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mysys/default.c b/mysys/default.c index 16e166a3ca5..364b2037f67 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -120,7 +120,7 @@ int load_defaults(const char *conf_file, const char **groups, uint args_used=0; int error= 0; MEM_ROOT alloc; - char *ptr, **res, **ext; + char *ptr, **res; DBUG_ENTER("load_defaults"); @@ -176,10 +176,9 @@ int load_defaults(const char *conf_file, const char **groups, } else if (dirname_length(conf_file)) { - for (ext= (char**) f_extensions; *ext; *ext++) - if ((error= search_default_file(&args, &alloc, NullS, conf_file, - &group)) < 0) - goto err; + if ((error= search_default_file(&args, &alloc, NullS, conf_file, + &group)) < 0) + goto err; } else { From d605d887978b185fa8a9f09836978443f9fd02db Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Nov 2004 19:54:25 +0200 Subject: [PATCH 3/4] Code cleanup and some optimizations. --- tests/client_test.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/client_test.c b/tests/client_test.c index 89034012d5b..2f28da6d00d 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -11494,11 +11494,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), return 0; } -static void get_options(int argc, char **argv) +static void get_options(int *argc, char ***argv) { int ho_error; - if ((ho_error= handle_options(&argc, &argv, client_test_long_options, + if ((ho_error= handle_options(argc, argv, client_test_long_options, get_one_option))) exit(ho_error); @@ -11541,7 +11541,7 @@ int main(int argc, char **argv) load_defaults("my", client_test_load_default_groups, &argc, &argv); defaults_argv= argv; - get_options(argc, argv); + get_options(&argc, &argv); client_connect(); /* connect to server */ @@ -11552,30 +11552,28 @@ int main(int argc, char **argv) test_count= 1; start_time= time((time_t *)0); - int i, name_ok; - if (!argv[1]) + if (!argc) { for (fptr= my_tests; fptr->name; fptr++) (*fptr->function)(); } else { - for (i= 1; argv[i]; i++) + for ( ; *argv ; argv++) { - name_ok= 0; for (fptr= my_tests; fptr->name; fptr++) { - if (!strcmp(fptr->name, argv[i])) + if (!strcmp(fptr->name, *argv)) { - name_ok= 1; (*fptr->function)(); + break; } } - if (!name_ok) + if (!fptr->name) { - printf("\n\nGiven test not found: '%s'\n", argv[i]); - printf("See legal test names with %s -T\n\nAborting!\n", - my_progname); + fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); + fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", + my_progname); client_disconnect(); free_defaults(defaults_argv); exit(1); From c77cb0a3210106772e59e78059461a4eb4d69e54 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Nov 2004 20:47:41 +0200 Subject: [PATCH 4/4] Fixed a function call. --- sql/item_strfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 3f659964a6c..5a23eec5a1b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2593,7 +2593,7 @@ String *Item_func_quote::val_str(String *str) uint arg_length, new_length; if (!arg) // Null argument { - str->copy("NULL", 4); // Return the string 'NULL' + str->copy("NULL", 4, collation.collation); // Return the string 'NULL' null_value= 0; return str; }