diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2016-01-25 18:44:51 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2016-01-25 18:44:51 +0100 |
commit | 62a5e56c01f120d2be6a837c8b9bd76950d6ef4e (patch) | |
tree | db3cbdbdcb6042ad7f50242c52d85d8156521e63 /storage | |
parent | 0891ae2fbb77c96a7fbeeb2ce9973d22da596f2a (diff) | |
download | mariadb-git-62a5e56c01f120d2be6a837c8b9bd76950d6ef4e.tar.gz |
- Change SQL_NTS to 0 when the string is NULL
modified: storage/connect/odbconn.cpp
- Fix to MDEV-9446 (using Json UDFs when CONNECT is not installed)
modified: storage/connect/ha_connect.cc
modified: storage/connect/jsonudf.cpp
modified: storage/connect/jsonudf.h
modified: storage/connect/mysql-test/connect/r/json_udf.result
modified: storage/connect/mysql-test/connect/t/json_udf.inc
modified: storage/connect/mysql-test/connect/t/json_udf.test
modified: storage/connect/mysql-test/connect/t/json_udf2.inc
Diffstat (limited to 'storage')
-rw-r--r-- | storage/connect/ha_connect.cc | 21 | ||||
-rw-r--r-- | storage/connect/jsonudf.cpp | 57 | ||||
-rw-r--r-- | storage/connect/jsonudf.h | 6 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/r/json_udf.result | 4 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/json_udf.inc | 2 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/json_udf.test | 3 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/json_udf2.inc | 2 | ||||
-rw-r--r-- | storage/connect/odbconn.cpp | 4 |
8 files changed, 82 insertions, 17 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 457e494159e..2994ad99d72 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1,4 +1,4 @@ -/* Copyright (C) Olivier Bertrand 2004 - 2015 +/* Copyright (C) Olivier Bertrand 2004 - 2016 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -169,7 +169,7 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.04.0005 December 11, 2015"; + char version[]= "Version 1.04.0005 January 24, 2016"; #if defined(__WIN__) char compver[]= "Version 1.04.0005 " __DATE__ " " __TIME__; char slash= '\\'; @@ -340,14 +340,21 @@ static MYSQL_THDVAR_ENUM( #endif // XMSG || NEWMSG /***********************************************************************/ +/* The CONNECT handlerton object. */ +/***********************************************************************/ +handlerton *connect_hton= NULL; + +/***********************************************************************/ /* Function to export session variable values to other source files. */ /***********************************************************************/ -extern "C" int GetTraceValue(void) {return THDVAR(current_thd, xtrace);} +extern "C" int GetTraceValue(void) + {return connect_hton ? THDVAR(current_thd, xtrace) : 0;} bool ExactInfo(void) {return THDVAR(current_thd, exact_info);} USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);} int GetConvSize(void) {return THDVAR(current_thd, conv_size);} TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);} -uint GetJsonGrpSize(void) {return THDVAR(current_thd, json_grp_size);} +uint GetJsonGrpSize(void) + {return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;} uint GetWorkSize(void) {return THDVAR(current_thd, work_size);} void SetWorkSize(uint) { @@ -442,11 +449,6 @@ static int check_msg_path (MYSQL_THD thd, struct st_mysql_sys_var *var, } // end of check_msg_path #endif // 0 -/***********************************************************************/ -/* The CONNECT handlerton object. */ -/***********************************************************************/ -handlerton *connect_hton; - /** CREATE TABLE option list (table options) @@ -687,6 +689,7 @@ static int connect_done_func(void *) delete pc; } // endfor pc + connect_hton= NULL; DBUG_RETURN(error); } // end of connect_done_func diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 40685ae0f0e..eae872b81cc 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -31,6 +31,8 @@ uint GetJsonGrpSize(void); static int IsJson(UDF_ARGS *args, uint i); static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i); +static uint JsonGrpSize = 10; + /* ----------------------------------- JSNX ------------------------------------ */ /*********************************************************************************/ @@ -1040,6 +1042,14 @@ static void SetChanged(PBSON bsp) } /* end of SetChanged */ /*********************************************************************************/ +/* Replaces GetJsonGrpSize not usable when CONNECT is not installed. */ +/*********************************************************************************/ +static uint GetJsonGroupSize(void) +{ + return (JsonGrpSize) ? JsonGrpSize : GetJsonGrpSize(); +} // end of GetJsonGroupSize + +/*********************************************************************************/ /* Program for SubSet re-initialization of the memory pool. */ /*********************************************************************************/ static my_bool JsonSubSet(PGLOBAL g) @@ -2394,11 +2404,50 @@ void json_object_list_deinit(UDF_INIT* initid) } // end of json_object_list_deinit /*********************************************************************************/ +/* Set the value of JsonGrpSize. */ +/*********************************************************************************/ +my_bool jsonset_grp_size_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) { + strcpy(message, "This function must have 1 integer argument"); + return true; + } else + return false; + +} // end of jsonset_grp_size_init + +long long jsonset_grp_size(UDF_INIT *initid, UDF_ARGS *args, char *, char *) +{ + long long n = *(long long*)args->args[0]; + + JsonGrpSize = (uint)n; + return (long long)GetJsonGroupSize(); +} // end of jsonset_grp_size + +/*********************************************************************************/ +/* Get the value of JsonGrpSize. */ +/*********************************************************************************/ +my_bool jsonget_grp_size_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count != 0) { + strcpy(message, "This function must have no arguments"); + return true; + } else + return false; + +} // end of jsonget_grp_size_init + +long long jsonget_grp_size(UDF_INIT *initid, UDF_ARGS *args, char *, char *) +{ + return (long long)GetJsonGroupSize(); +} // end of jsonget_grp_size + +/*********************************************************************************/ /* Make a Json array from values coming from rows. */ /*********************************************************************************/ my_bool json_array_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { - unsigned long reslen, memlen, n = GetJsonGrpSize(); + unsigned long reslen, memlen, n = GetJsonGroupSize(); if (args->arg_count != 1) { strcpy(message, "This function can only accept 1 argument"); @@ -2458,7 +2507,7 @@ void json_array_grp_clear(UDF_INIT *initid, char*, char*) PlugSubSet(g, g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)new(g) JARRAY; - g->N = GetJsonGrpSize(); + g->N = GetJsonGroupSize(); } // end of json_array_grp_clear void json_array_grp_deinit(UDF_INIT* initid) @@ -2471,7 +2520,7 @@ void json_array_grp_deinit(UDF_INIT* initid) /*********************************************************************************/ my_bool json_object_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { - unsigned long reslen, memlen, n = GetJsonGrpSize(); + unsigned long reslen, memlen, n = GetJsonGroupSize(); if (args->arg_count != 2) { strcpy(message, "This function requires 2 arguments (key, value)"); @@ -2529,7 +2578,7 @@ void json_object_grp_clear(UDF_INIT *initid, char*, char*) PlugSubSet(g, g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)new(g) JOBJECT; - g->N = GetJsonGrpSize(); + g->N = GetJsonGroupSize(); } // end of json_object_grp_clear void json_object_grp_deinit(UDF_INIT* initid) diff --git a/storage/connect/jsonudf.h b/storage/connect/jsonudf.h index ecbbb778214..b7e9b8ecabb 100644 --- a/storage/connect/jsonudf.h +++ b/storage/connect/jsonudf.h @@ -77,6 +77,12 @@ extern "C" { DllExport char *json_object_list(UDF_EXEC_ARGS); DllExport void json_object_list_deinit(UDF_INIT*); + DllExport my_bool jsonset_grp_size_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport long long jsonset_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*); + + DllExport my_bool jsonget_grp_size_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport long long jsonget_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*); + DllExport my_bool json_array_grp_init(UDF_INIT*, UDF_ARGS*, char*); DllExport void json_array_grp_add(UDF_INIT *, UDF_ARGS *, char *, char *); DllExport char *json_array_grp(UDF_EXEC_ARGS); diff --git a/storage/connect/mysql-test/connect/r/json_udf.result b/storage/connect/mysql-test/connect/r/json_udf.result index 5089022c5ea..1e83834cb8f 100644 --- a/storage/connect/mysql-test/connect/r/json_udf.result +++ b/storage/connect/mysql-test/connect/r/json_udf.result @@ -217,7 +217,9 @@ DEPARTMENT Json_Array_Grp(NAME) 2452 ["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"] Warnings: Warning 1105 Result truncated to json_grp_size values -SET connect_json_grp_size=30; +SELECT JsonSet_Grp_Size(30); +JsonSet_Grp_Size(30) +30 SELECT Json_Object(title, Json_Array_Grp(name) `json_names`) from t3 GROUP BY title; Json_Object(title, Json_Array_Grp(name) `json_names`) {"title":"ADMINISTRATOR","names":["GOOSEPEN","FUNNIGUY","SHRINKY"]} diff --git a/storage/connect/mysql-test/connect/t/json_udf.inc b/storage/connect/mysql-test/connect/t/json_udf.inc index f17d59832f3..2ade7ad02fe 100644 --- a/storage/connect/mysql-test/connect/t/json_udf.inc +++ b/storage/connect/mysql-test/connect/t/json_udf.inc @@ -20,6 +20,8 @@ if (!$HA_CONNECT_SO) { --eval CREATE FUNCTION json_object_delete RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION json_object_list RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION jsonvalue RETURNS STRING SONAME '$HA_CONNECT_SO'; +--eval CREATE FUNCTION jsonset_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO'; +--eval CREATE FUNCTION jsonget_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO'; --eval CREATE AGGREGATE FUNCTION json_array_grp RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE AGGREGATE FUNCTION json_object_grp RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION jsonget_string RETURNS STRING SONAME '$HA_CONNECT_SO'; diff --git a/storage/connect/mysql-test/connect/t/json_udf.test b/storage/connect/mysql-test/connect/t/json_udf.test index cfd1fdae258..d11e2fd7cf6 100644 --- a/storage/connect/mysql-test/connect/t/json_udf.test +++ b/storage/connect/mysql-test/connect/t/json_udf.test @@ -108,7 +108,8 @@ CREATE TABLE t3 ( SELECT Json_Object(SERIALNO, NAME, TITLE, SALARY) FROM t3 WHERE NAME = 'MERCHANT'; SELECT DEPARTMENT, Json_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT; -SET connect_json_grp_size=30; +#SET connect_json_grp_size=30; Deprecated +SELECT JsonSet_Grp_Size(30); SELECT Json_Object(title, Json_Array_Grp(name) `json_names`) from t3 GROUP BY title; SELECT Json_Array(DEPARTMENT, Json_Array_Grp(NAME)) FROM t3 GROUP BY DEPARTMENT; SELECT Json_Object(DEPARTMENT, Json_Array_Grp(NAME) json_NAMES) FROM t3 GROUP BY DEPARTMENT; diff --git a/storage/connect/mysql-test/connect/t/json_udf2.inc b/storage/connect/mysql-test/connect/t/json_udf2.inc index f62b178b003..4c74e2c11f2 100644 --- a/storage/connect/mysql-test/connect/t/json_udf2.inc +++ b/storage/connect/mysql-test/connect/t/json_udf2.inc @@ -11,6 +11,8 @@ DROP FUNCTION json_object_add; DROP FUNCTION json_object_delete; DROP FUNCTION json_object_list; DROP FUNCTION jsonvalue; +DROP FUNCTION jsonset_grp_size; +DROP FUNCTION jsonget_grp_size; DROP FUNCTION json_array_grp; DROP FUNCTION json_object_grp; DROP FUNCTION jsonget_string; diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 1ccdf231970..3dbbcc845dc 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -2249,7 +2249,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) rc = SQLTables(hstmt, name.ptr(2), name.length(2), name.ptr(1), name.length(1), name.ptr(0), name.length(0), - cap->Pat, SQL_NTS); + cap->Pat, cap->Pat ? SQL_NTS : 0); break; case CAT_COL: // rc = SQLSetStmtAttr(hstmt, SQL_ATTR_METADATA_ID, @@ -2258,7 +2258,7 @@ int ODBConn::GetCatInfo(CATPARM *cap) rc = SQLColumns(hstmt, name.ptr(2), name.length(2), name.ptr(1), name.length(1), name.ptr(0), name.length(0), - cap->Pat, SQL_NTS); + cap->Pat, cap->Pat ? SQL_NTS : 0); break; case CAT_KEY: fnc = "SQLPrimaryKeys"; |