diff --git a/dbcon/mysql/ha_mcs_client_udfs.cpp b/dbcon/mysql/ha_mcs_client_udfs.cpp index 2981c41cd..7581b67df 100644 --- a/dbcon/mysql/ha_mcs_client_udfs.cpp +++ b/dbcon/mysql/ha_mcs_client_udfs.cpp @@ -66,6 +66,49 @@ extern "C" return str; } + my_bool setparms_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT) + { + sprintf(message, "%s() requires two string arguments", funcname); + return 1; + } + + initid->max_length = MAXSTRINGLENGTH; + + char valuestr[MAXSTRINGLENGTH]; + size_t vlen = args->lengths[1]; + + memcpy(valuestr, args->args[1], vlen--); + + for (size_t i = 0; i < vlen; ++i) + if (!isdigit(valuestr[i])) + { + sprintf(message, "%s() second argument must be numeric or end in G, M or K", funcname); + return 1; + } + + if (!isdigit(valuestr[vlen])) + { + switch (valuestr[vlen]) + { + case 'G': + case 'g': + case 'M': + case 'm': + case 'K': + case 'k': + case '\0': break; + + default: + sprintf(message, "%s() second argument must be numeric or end in G, M or K", funcname); + return 1; + } + } + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -135,50 +178,13 @@ extern "C" return result; } + #ifdef _MSC_VER __declspec(dllexport) #endif my_bool mcssetparms_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT) - { - strcpy(message, "MCSSETPARMS() requires two string arguments"); - return 1; - } - - initid->max_length = MAXSTRINGLENGTH; - - char valuestr[MAXSTRINGLENGTH]; - size_t vlen = args->lengths[1]; - - memcpy(valuestr, args->args[1], vlen--); - - for (size_t i = 0; i < vlen; ++i) - if (!isdigit(valuestr[i])) - { - strcpy(message, "MCSSETPARMS() second argument must be numeric or end in G, M or K"); - return 1; - } - - if (!isdigit(valuestr[vlen])) - { - switch (valuestr[vlen]) - { - case 'G': - case 'g': - case 'M': - case 'm': - case 'K': - case 'k': - case '\0': break; - - default: - strcpy(message, "MCSSETPARMS() second argument must be numeric or end in G, M or K"); - return 1; - } - } - - return 0; + return setparms_init(initid, args, message, "MCSSETPARMS"); } #ifdef _MSC_VER @@ -188,6 +194,7 @@ extern "C" { } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -202,45 +209,7 @@ extern "C" #endif my_bool calsetparms_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 2 || args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT) - { - strcpy(message, "CALSETPARMS() requires two string arguments"); - return 1; - } - - initid->max_length = MAXSTRINGLENGTH; - - char valuestr[MAXSTRINGLENGTH]; - size_t vlen = args->lengths[1]; - - memcpy(valuestr, args->args[1], vlen--); - - for (size_t i = 0; i < vlen; ++i) - if (!isdigit(valuestr[i])) - { - strcpy(message, "CALSETPARMS() second argument must be numeric or end in G, M or K"); - return 1; - } - - if (!isdigit(valuestr[vlen])) - { - switch (valuestr[vlen]) - { - case 'G': - case 'g': - case 'M': - case 'm': - case 'K': - case 'k': - case '\0': break; - - default: - strcpy(message, "CALSETPARMS() second argument must be numeric or end in G, M or K"); - return 1; - } - } - - return 0; + return setparms_init(initid, args, message, "CALSETPARMS"); } #ifdef _MSC_VER @@ -250,6 +219,20 @@ extern "C" { } + my_bool getstats_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 0) + { + sprintf(message, "%s() takes no arguments", funcname); + return 1; + } + + initid->maybe_null = 1; + initid->max_length = 255; + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -277,21 +260,13 @@ extern "C" return result; } + #ifdef _MSC_VER __declspec(dllexport) #endif my_bool mcsgetstats_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "MCSGETSTATS() takes no arguments"); - return 1; - } - - initid->maybe_null = 1; - initid->max_length = 255; - - return 0; + return getstats_init(initid, args, message, "MCSGETSTATS"); } #ifdef _MSC_VER @@ -315,16 +290,7 @@ extern "C" #endif my_bool calgetstats_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "CALGETSTATS() takes no arguments"); - return 1; - } - - initid->maybe_null = 1; - initid->max_length = 255; - - return 0; + return getstats_init(initid, args, message, "CALGETSTATS"); } #ifdef _MSC_VER @@ -334,6 +300,17 @@ extern "C" { } + my_bool settrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) + { + sprintf(message, "%s() requires one INTEGER argument", funcname); + return 1; + } + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -357,13 +334,7 @@ extern "C" #endif my_bool mcssettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) - { - strcpy(message, "MCSSETTRACE() requires one INTEGER argument"); - return 1; - } - - return 0; + return settrace_init(initid, args, message, "MCSSETTRACE"); } #ifdef _MSC_VER @@ -386,13 +357,7 @@ extern "C" #endif my_bool calsettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) - { - strcpy(message, "CALSETTRACE() requires one INTEGER argument"); - return 1; - } - - return 0; + return settrace_init(initid, args, message, "CALSETTRACE"); } #ifdef _MSC_VER @@ -538,29 +503,26 @@ extern "C" { } -#ifdef _MSC_VER - __declspec(dllexport) -#endif - my_bool mcsviewtablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + my_bool viewtablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) { if (args->arg_count == 2 && (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) { - strcpy(message, "MCSVIEWTABLELOCK() requires two string arguments"); + sprintf(message, "%s() requires two string arguments", funcname); return 1; } else if ((args->arg_count == 1) && (args->arg_type[0] != STRING_RESULT)) { - strcpy(message, "MCSVIEWTABLELOCK() requires one string argument"); + sprintf(message, "%s() requires one string argument", funcname); return 1; } else if (args->arg_count > 2) { - strcpy(message, "MCSVIEWTABLELOCK() takes one or two arguments only"); + sprintf(message, "%s() takes one or two arguments only", funcname); return 1; } else if (args->arg_count == 0) { - strcpy(message, "MCSVIEWTABLELOCK() requires at least one argument"); + sprintf(message, "%s() requires at least one argument", funcname); return 1; } @@ -570,6 +532,14 @@ extern "C" return 0; } +#ifdef _MSC_VER + __declspec(dllexport) +#endif + my_bool mcsviewtablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + { + return viewtablelock_init(initid, args, message, "MCSVIEWTABLELOCK"); + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -637,31 +607,7 @@ extern "C" #endif my_bool calviewtablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count == 2 && (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) - { - strcpy(message, "CALVIEWTABLELOCK() requires two string arguments"); - return 1; - } - else if ((args->arg_count == 1) && (args->arg_type[0] != STRING_RESULT)) - { - strcpy(message, "CALVIEWTABLELOCK() requires one string argument"); - return 1; - } - else if (args->arg_count > 2) - { - strcpy(message, "CALVIEWTABLELOCK() takes one or two arguments only"); - return 1; - } - else if (args->arg_count == 0) - { - strcpy(message, "CALVIEWTABLELOCK() requires at least one argument"); - return 1; - } - - initid->maybe_null = 1; - initid->max_length = 255; - - return 0; + return viewtablelock_init(initid, args, message, "CALVIEWTABLELOCK"); } #ifdef _MSC_VER @@ -670,7 +616,7 @@ extern "C" const char* calviewtablelock(UDF_INIT* initid, UDF_ARGS* args, char* result, unsigned long* length, char* is_null, char* error) { - return mcsviewtablelock(initid, args, result, length, is_null, error); + return mcsviewtablelock(initid, args, result, length, is_null, error); } #ifdef _MSC_VER @@ -680,14 +626,11 @@ extern "C" { } -#ifdef _MSC_VER - __declspec(dllexport) -#endif - my_bool mcscleartablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + my_bool cleartablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) { if ((args->arg_count != 1) || (args->arg_type[0] != INT_RESULT)) { - strcpy(message, "MCSCLEARTABLELOCK() requires one integer argument (the lockID)"); + sprintf(message, "%s() requires one integer argument (the lockID)", funcname); return 1; } @@ -697,6 +640,15 @@ extern "C" return 0; } + +#ifdef _MSC_VER + __declspec(dllexport) +#endif + my_bool mcscleartablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + { + return cleartablelock_init(initid, args, message, "MCSCLEARTABLELOCK"); + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -736,16 +688,7 @@ extern "C" #endif my_bool calcleartablelock_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if ((args->arg_count != 1) || (args->arg_type[0] != INT_RESULT)) - { - strcpy(message, "CALCLEARTABLELOCK() requires one integer argument (the lockID)"); - return 1; - } - - initid->maybe_null = 1; - initid->max_length = 255; - - return 0; + return cleartablelock_init(initid, args, message, "CALCLEARTABLELOCK"); } #ifdef _MSC_VER @@ -764,29 +707,26 @@ extern "C" { } -#ifdef _MSC_VER - __declspec(dllexport) -#endif - my_bool mcslastinsertid_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + my_bool lastinsertid_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) { if (args->arg_count == 2 && (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) { - strcpy(message, "MCSLASTINSRTID() requires two string arguments"); + sprintf(message, "%s() requires two string arguments", funcname); return 1; } else if ((args->arg_count == 1) && (args->arg_type[0] != STRING_RESULT)) { - strcpy(message, "MCSLASTINSERTID() requires one string argument"); + sprintf(message, "%s() requires one string argument", funcname); return 1; } else if (args->arg_count > 2) { - strcpy(message, "MCSLASTINSERTID() takes one or two arguments only"); + sprintf(message, "%s() takes one or two arguments only", funcname); return 1; } else if (args->arg_count == 0) { - strcpy(message, "MCSLASTINSERTID() requires at least one argument"); + sprintf(message, "%s() requires at least one argument", funcname); return 1; } @@ -796,6 +736,15 @@ extern "C" return 0; } + +#ifdef _MSC_VER + __declspec(dllexport) +#endif + my_bool mcslastinsertid_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + { + return lastinsertid_init(initid, args, message, "MCSLASTINSERTID"); + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -873,31 +822,7 @@ extern "C" #endif my_bool callastinsertid_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count == 2 && (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) - { - strcpy(message, "CALLASTINSRTID() requires two string arguments"); - return 1; - } - else if ((args->arg_count == 1) && (args->arg_type[0] != STRING_RESULT)) - { - strcpy(message, "CALLASTINSERTID() requires one string argument"); - return 1; - } - else if (args->arg_count > 2) - { - strcpy(message, "CALLASTINSERTID() takes one or two arguments only"); - return 1; - } - else if (args->arg_count == 0) - { - strcpy(message, "CALLASTINSERTID() requires at least one argument"); - return 1; - } - - initid->maybe_null = 1; - initid->max_length = 255; - - return 0; + return lastinsertid_init(initid, args, message, "CALLASTINSERTID"); } #ifdef _MSC_VER @@ -915,6 +840,17 @@ extern "C" { } + my_bool flushcache_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 0) + { + sprintf(message, "%s() takes no arguments", funcname); + return 1; + } + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -935,13 +871,7 @@ extern "C" #endif my_bool mcsflushcache_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "MCSFLUSHCACHE() takes no arguments"); - return 1; - } - - return 0; + return flushcache_init(initid, args, message, "MCSFLUSHCACHE"); } #ifdef _MSC_VER @@ -964,13 +894,7 @@ extern "C" #endif my_bool calflushcache_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "CALFLUSHCACHE() takes no arguments"); - return 1; - } - - return 0; + return flushcache_init(initid, args, message, "CALFLUSHCACHE"); } static const unsigned long TraceSize = 16 * 1024; @@ -1022,16 +946,13 @@ extern "C" return msgp->c_str(); } -#ifdef _MSC_VER - __declspec(dllexport) -#endif - my_bool mcsgettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + my_bool gettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) { #if 0 if (args->arg_count != 0) { - strcpy(message, "MCSGETTRACE() takes no arguments"); + sprintf(message, "%s() takes no arguments", funcname); return 1; } @@ -1042,6 +963,14 @@ extern "C" return 0; } +#ifdef _MSC_VER + __declspec(dllexport) +#endif + my_bool mcsgettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message) + { + return gettrace_init(initid, args, message, "MCSGETTRACE"); + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -1063,19 +992,7 @@ extern "C" #endif my_bool calgettrace_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { -#if 0 - - if (args->arg_count != 0) - { - strcpy(message, "CALGETTRACE() takes no arguments"); - return 1; - } - -#endif - initid->maybe_null = 1; - initid->max_length = TraceSize; - - return 0; + return gettrace_init(initid, args, message, "CALGETTRACE"); } #ifdef _MSC_VER @@ -1085,6 +1002,17 @@ extern "C" { } + my_bool getversion_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 0) + { + sprintf(message, "%s() takes no arguments", funcname); + return 1; + } + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -1102,13 +1030,7 @@ extern "C" #endif my_bool mcsgetversion_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "MCSGETVERSION() takes no arguments"); - return 1; - } - - return 0; + return getversion_init(initid, args, message, "MCSGETVERSION"); } #ifdef _MSC_VER @@ -1132,13 +1054,7 @@ extern "C" #endif my_bool calgetversion_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "CALGETVERSION() takes no arguments"); - return 1; - } - - return 0; + return getversion_init(initid, args, message, "CALGETVERSION"); } #ifdef _MSC_VER @@ -1148,6 +1064,17 @@ extern "C" { } + my_bool getsqlcount_init(UDF_INIT* initid, UDF_ARGS* args, char* message, const char* funcname) + { + if (args->arg_count != 0) + { + sprintf(message, "%s() takes no arguments", funcname); + return 1; + } + + return 0; + } + #ifdef _MSC_VER __declspec(dllexport) #endif @@ -1195,13 +1122,7 @@ extern "C" #endif my_bool mcsgetsqlcount_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "MCSGETSQLCOUNT() takes no arguments"); - return 1; - } - - return 0; + return getstats_init(initid, args, message, "MCSGETSQLCOUNT"); } #ifdef _MSC_VER @@ -1225,13 +1146,7 @@ extern "C" #endif my_bool calgetsqlcount_init(UDF_INIT* initid, UDF_ARGS* args, char* message) { - if (args->arg_count != 0) - { - strcpy(message, "CALGETSQLCOUNT() takes no arguments"); - return 1; - } - - return 0; + return getstats_init(initid, args, message, "CALGETSQLCOUNT"); } #ifdef _MSC_VER diff --git a/mysql-test/columnstore/basic/r/cal_named_udfs.result b/mysql-test/columnstore/basic/r/cal_named_udfs.result index 8a96f7c62..26b20fb8b 100644 --- a/mysql-test/columnstore/basic/r/cal_named_udfs.result +++ b/mysql-test/columnstore/basic/r/cal_named_udfs.result @@ -14,9 +14,9 @@ Updated pmmaxmemorysmallside 2048000000 select calgettrace(); calgettrace() NULL -select calgetversion(); -calgetversion() -8.1.1 +select calgetversion()=mcsgetversion(); +calgetversion()=mcsgetversion() +1 select calviewtablelock("t1"); calviewtablelock("t1") Table cal_test_db.t1 is not locked by any process. diff --git a/mysql-test/columnstore/basic/r/mcs_named_udfs.result b/mysql-test/columnstore/basic/r/mcs_named_udfs.result index 6f79cbe75..4a09eb41d 100644 --- a/mysql-test/columnstore/basic/r/mcs_named_udfs.result +++ b/mysql-test/columnstore/basic/r/mcs_named_udfs.result @@ -14,9 +14,9 @@ Updated pmmaxmemorysmallside 2048000000 select mcsgettrace(); mcsgettrace() NULL -select mcsgetversion(); -mcsgetversion() -8.1.1 +select mcsgetversion()=calgetversion(); +mcsgetversion()=calgetversion() +1 select mcsviewtablelock("t1"); mcsviewtablelock("t1") Table cal_test_db.t1 is not locked by any process. diff --git a/mysql-test/columnstore/basic/t/cal_named_udfs.test b/mysql-test/columnstore/basic/t/cal_named_udfs.test index c60cd946a..f127716d2 100644 --- a/mysql-test/columnstore/basic/t/cal_named_udfs.test +++ b/mysql-test/columnstore/basic/t/cal_named_udfs.test @@ -13,7 +13,7 @@ select calflushcache(); select calsettrace(0); select calsetparms("pmmaxmemorysmallside","2048000000"); select calgettrace(); -select calgetversion(); +select calgetversion()=mcsgetversion(); select calviewtablelock("t1"); diff --git a/mysql-test/columnstore/basic/t/mcs_named_udfs.test b/mysql-test/columnstore/basic/t/mcs_named_udfs.test index eda419676..980c3fc69 100644 --- a/mysql-test/columnstore/basic/t/mcs_named_udfs.test +++ b/mysql-test/columnstore/basic/t/mcs_named_udfs.test @@ -13,8 +13,7 @@ select mcsflushcache(); select mcssettrace(0); select mcssetparms("pmmaxmemorysmallside","2048000000"); select mcsgettrace(); -select mcsgetversion(); - +select mcsgetversion()=calgetversion(); select mcsviewtablelock("t1"); select mcscleartablelock(0);