Commit f4fe1383 authored by Olivier Bertrand's avatar Olivier Bertrand

Fix assert error for where clause with UDF's

    was fixed in HA_CONNECT::CondFilter moving res= pval->val_str(&tmp)
    but this was wrong. Now res is only used for strings.
Change version number
  modified:   storage/connect/ha_connect.cc

Add some new UDF's
  modified:   storage/connect/json.cpp
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h

Fix change in tests json_udf
  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
parent 8a154ecd
......@@ -169,9 +169,9 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.04.0001 June 29, 2015";
char version[]= "Version 1.04.0003 September 15, 2015";
#if defined(__WIN__)
char compver[]= "Version 1.04.0001 " __DATE__ " " __TIME__;
char compver[]= "Version 1.04.0003 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
......@@ -2544,11 +2544,9 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
if (!i && (ismul))
return NULL;
if ((res= pval->val_str(&tmp)) == NULL)
return NULL; // To be clarified
switch (args[i]->real_type()) {
case COND::STRING_ITEM:
res= pval->val_str(&tmp);
pp->Value= PlugSubAllocStr(g, NULL, res->ptr(), res->length());
pp->Type= (pp->Value) ? TYPE_STRING : TYPE_ERROR;
break;
......@@ -2579,7 +2577,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
} // endswitch type
if (trace)
htrc("Value=%.*s\n", res->length(), res->ptr());
htrc("Value type=%hd\n", pp->Type);
// Append the value to the argument list
if (pprec)
......@@ -6722,7 +6720,7 @@ maria_declare_plugin(connect)
0x0104, /* version number (1.04) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.04.0001", /* string version */
"1.04.0003", /* string version */
MariaDB_PLUGIN_MATURITY_BETA /* maturity */
}
maria_declare_plugin_end;
......@@ -942,6 +942,24 @@ PSZ JOBJECT::GetText(PGLOBAL g, PSZ text)
return text + n;
} // end of GetValue;
/***********************************************************************/
/* Merge two objects. */
/***********************************************************************/
bool JOBJECT::Merge(PGLOBAL g, PJSON jsp)
{
if (jsp->GetType() != TYPE_JOB) {
strcpy(g->Message, "Second argument is not an object");
return true;
} // endif Type
PJOB jobp = (PJOB)jsp;
for (PJPR jpp = jobp->First; jpp; jpp = jpp->Next)
SetValue(g, jpp->GetVal(), jpp->GetKey());
return false;
} // end of Marge;
/***********************************************************************/
/* Set or add a value corresponding to the given key. */
/***********************************************************************/
......@@ -1063,6 +1081,25 @@ PJVAL JARRAY::AddValue(PGLOBAL g, PJVAL jvp, int *x)
return jvp;
} // end of AddValue
/***********************************************************************/
/* Merge two arrays. */
/***********************************************************************/
bool JARRAY::Merge(PGLOBAL g, PJSON jsp)
{
if (jsp->GetType() != TYPE_JAR) {
strcpy(g->Message, "Second argument is not an array");
return true;
} // endif Type
PJAR arp = (PJAR)jsp;
for (int i = 0; i < jsp->size(); i++)
AddValue(g, arp->GetValue(i));
InitArray(g);
return false;
} // end of Merge
/***********************************************************************/
/* Set the nth Value of the Array Value list. */
/***********************************************************************/
......
......@@ -162,7 +162,8 @@ class JSON : public BLOCK {
virtual double GetFloat() {X return 0.0;}
virtual PSZ GetString() {X return NULL;}
virtual PSZ GetText(PGLOBAL g, PSZ text) {X return NULL;}
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) {X return true;}
virtual bool Merge(PGLOBAL g, PJSON jsp) { X return true; }
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) { X return true; }
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key) {X}
virtual void SetValue(PVAL valp) {X}
virtual void SetValue(PJSON jsp) {X}
......@@ -197,6 +198,7 @@ class JOBJECT : public JSON {
virtual PJVAL GetValue(const char* key);
virtual PJAR GetKeyList(PGLOBAL g);
virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key);
virtual void DeleteKey(char *k);
virtual bool IsNull(void);
......@@ -222,6 +224,7 @@ class JARRAY : public JSON {
virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL);
virtual void InitArray(PGLOBAL g);
virtual PJVAL GetValue(int i);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
virtual bool DeleteValue(int n);
virtual bool IsNull(void);
......
This diff is collapsed.
/******************** tabjson H Declares Source Code File (.H) *******************/
/* Name: jsonudf.h Version 1.1 */
/* Name: jsonudf.h Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2015 */
/* */
......@@ -33,9 +33,9 @@ typedef class JOUTPATH *PJTP;
typedef class JOUTALL *PJTA;
extern "C" {
DllExport my_bool Json_Value_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Json_Value(UDF_EXEC_ARGS);
DllExport void Json_Value_deinit(UDF_INIT*);
DllExport my_bool JsonValue_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *JsonValue(UDF_EXEC_ARGS);
DllExport void JsonValue_deinit(UDF_INIT*);
DllExport my_bool Json_Array_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Json_Array(UDF_EXEC_ARGS);
......@@ -89,6 +89,10 @@ extern "C" {
DllExport char *Json_Get_Item(UDF_EXEC_ARGS);
DllExport void Json_Get_Item_deinit(UDF_INIT*);
DllExport my_bool Json_Item_Merge_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Json_Item_Merge(UDF_EXEC_ARGS);
DllExport void Json_Item_Merge_deinit(UDF_INIT*);
DllExport my_bool JsonGetString_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *JsonGetString(UDF_EXEC_ARGS);
DllExport void JsonGetString_deinit(UDF_INIT*);
......@@ -117,17 +121,57 @@ extern "C" {
DllExport char *Jfile_Make(UDF_EXEC_ARGS);
DllExport void Jfile_Make_deinit(UDF_INIT*);
DllExport my_bool Bson_Array_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Bson_Array(UDF_EXEC_ARGS);
DllExport void Bson_Array_deinit(UDF_INIT*);
DllExport my_bool Jbin_Array_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Array(UDF_EXEC_ARGS);
DllExport void Jbin_Array_deinit(UDF_INIT*);
DllExport my_bool Jbin_Array_Add_Values_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Array_Add_Values(UDF_EXEC_ARGS);
DllExport void Jbin_Array_Add_Values_deinit(UDF_INIT*);
DllExport my_bool Jbin_Array_Add_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Array_Add(UDF_EXEC_ARGS);
DllExport void Jbin_Array_Add_deinit(UDF_INIT*);
DllExport my_bool Jbin_Array_Delete_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Array_Delete(UDF_EXEC_ARGS);
DllExport void Jbin_Array_Delete_deinit(UDF_INIT*);
DllExport my_bool Jbin_Object_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Object(UDF_EXEC_ARGS);
DllExport void Jbin_Object_deinit(UDF_INIT*);
DllExport my_bool Jbin_Object_Nonull_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Object_Nonull(UDF_EXEC_ARGS);
DllExport void Jbin_Object_Nonull_deinit(UDF_INIT*);
DllExport my_bool Jbin_Object_Add_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Object_Add(UDF_EXEC_ARGS);
DllExport void Jbin_Object_Add_deinit(UDF_INIT*);
DllExport my_bool Jbin_Object_Delete_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Object_Delete(UDF_EXEC_ARGS);
DllExport void Jbin_Object_Delete_deinit(UDF_INIT*);
DllExport my_bool Jbin_Object_List_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Object_List(UDF_EXEC_ARGS);
DllExport void Jbin_Object_List_deinit(UDF_INIT*);
DllExport my_bool Jbin_Get_Item_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Get_Item(UDF_EXEC_ARGS);
DllExport void Jbin_Get_Item_deinit(UDF_INIT*);
DllExport my_bool Jbin_Item_Merge_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_Item_Merge(UDF_EXEC_ARGS);
DllExport void Jbin_Item_Merge_deinit(UDF_INIT*);
DllExport my_bool Bson_Object_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Bson_Object(UDF_EXEC_ARGS);
DllExport void Bson_Object_deinit(UDF_INIT*);
DllExport my_bool Jbin_File_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Jbin_File(UDF_EXEC_ARGS);
DllExport void Jbin_File_deinit(UDF_INIT*);
DllExport my_bool Bson_File_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Bson_File(UDF_EXEC_ARGS);
DllExport void Bson_File_deinit(UDF_INIT*);
DllExport my_bool Json_Serialize_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *Json_Serialize(UDF_EXEC_ARGS);
DllExport void Json_Serialize_deinit(UDF_INIT*);
} // extern "C"
/*********************************************************************************/
......@@ -155,6 +199,7 @@ public:
my_bool SetJpath(PGLOBAL g, char *path, my_bool jb = false);
my_bool ParseJpath(PGLOBAL g);
void ReadValue(PGLOBAL g);
PJVAL GetValue(PGLOBAL g, PJSON row, int i, my_bool b = true);
PJVAL GetJson(PGLOBAL g);
char *Locate(PGLOBAL g, PJSON jsp, PJVAL jvp, int k = 1);
char *LocateAll(PGLOBAL g, PJSON jsp, PJVAL jvp, int mx = 10);
......@@ -162,7 +207,6 @@ public:
protected:
my_bool SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm);
PVAL GetColumnValue(PGLOBAL g, PJSON row, int i);
PJVAL GetValue(PGLOBAL g, PJSON row, int i);
PVAL ExpandArray(PGLOBAL g, PJAR arp, int n);
PVAL CalculateArray(PGLOBAL g, PJAR arp, int n);
PVAL MakeJson(PGLOBAL g, PJSON jsp);
......
......@@ -18,32 +18,30 @@ ERROR HY000: Can't initialize function 'Json_Array_Add'; Json_Array_Add must hav
SELECT Json_Array_Add(Json_Array(56,3.1416,'foo',NULL),'One more') Array;
Array
[56,3.141600,"foo",null,"One more"]
SELECT Json_Array_Add(Json_Value('one value'),'One more');
Json_Array_Add(Json_Value('one value'),'One more')
NULL
Warnings:
Warning 1105 First argument is not an array
SELECT Json_Array_Add(JsonValue('one value'),'One more');
ERROR HY000: Can't initialize function 'Json_Array_Add'; Json_Array_Add first argument must be a json item
SELECT Json_Array_Add('one value','One more');
ERROR HY000: Can't initialize function 'Json_Array_Add'; Json_Array_Add first argument must be a json item
SELECT Json_Array_Add('one value' json_,'One more');
Json_Array_Add('one value' json_,'One more')
NULL
Warnings:
Warning 1105 Unexpected character 'o' near one value
Warning 1105 Error 2 opening one value
Warning 1105 Void JSON object
Warning 1105 First argument is not an array
SELECT Json_Value(56,3.1416,'foo',NULL);
ERROR HY000: Can't initialize function 'Json_Value'; Json_Value cannot accept more than 1 argument
SELECT Json_Value(3.1416);
Json_Value(3.1416)
SELECT JsonValue(56,3.1416,'foo',NULL);
ERROR HY000: Can't initialize function 'JsonValue'; JsonValue cannot accept more than 1 argument
SELECT JsonValue(3.1416);
JsonValue(3.1416)
3.141600
SELECT Json_Value('foo');
Json_Value('foo')
SELECT JsonValue('foo');
JsonValue('foo')
"foo"
SELECT Json_Value(NULL);
Json_Value(NULL)
SELECT JsonValue(NULL);
JsonValue(NULL)
null
SELECT Json_Value();
Json_Value()
SELECT JsonValue();
JsonValue()
null
SELECT Json_Object();
Json_Object()
......@@ -165,6 +163,6 @@ DROP FUNCTION Json_Array;
DROP FUNCTION Json_Array_Add;
DROP FUNCTION Json_Object;
DROP FUNCTION Json_Object_Nonull;
DROP FUNCTION Json_Value;
DROP FUNCTION JsonValue;
DROP FUNCTION Json_Array_Grp;
DROP FUNCTION Json_Object_Grp;
......@@ -9,28 +9,13 @@ if (!$HA_CONNECT_SO) {
--skip Needs a dynamically built ha_connect.so
}
let $is_win = `select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows")`;
CREATE FUNCTION Json_Array RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION Json_Array_Add RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION Json_Object RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION Json_Object_Nonull RETURNS STRING SONAME 'ha_connect';
CREATE FUNCTION JsonValue RETURNS STRING SONAME 'ha_connect';
CREATE AGGREGATE FUNCTION Json_Array_Grp RETURNS STRING SONAME 'ha_connect';
CREATE AGGREGATE FUNCTION Json_Object_Grp RETURNS STRING SONAME 'ha_connect';
if ($is_win)
{
--eval CREATE FUNCTION Json_Array RETURNS STRING SONAME 'ha_connect.dll';
--eval CREATE FUNCTION Json_Array_Add RETURNS STRING SONAME 'ha_connect.dll';
--eval CREATE FUNCTION Json_Object RETURNS STRING SONAME 'ha_connect.dll';
--eval CREATE FUNCTION Json_Object_Nonull RETURNS STRING SONAME 'ha_connect.dll';
--eval CREATE FUNCTION Json_Value returns STRING SONAME 'ha_connect.dll';
--eval CREATE AGGREGATE FUNCTION Json_Array_Grp RETURNS STRING SONAME 'ha_connect.dll';
--eval CREATE AGGREGATE FUNCTION Json_Object_Grp RETURNS STRING SONAME 'ha_connect.dll';
}
if (!$is_win)
{
--eval CREATE FUNCTION Json_Array RETURNS STRING SONAME 'ha_connect.so';
--eval CREATE FUNCTION Json_Array_Add RETURNS STRING SONAME 'ha_connect.so';
--eval CREATE FUNCTION Json_Object RETURNS STRING SONAME 'ha_connect.so';
--eval CREATE FUNCTION Json_Object_Nonull RETURNS STRING SONAME 'ha_connect.so';
--eval CREATE FUNCTION Json_Value returns STRING 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';
}
--enable_query_log
......@@ -15,16 +15,17 @@ SELECT Json_Array(56,3.1416,'My name is "Foo"',NULL);
--error ER_CANT_INITIALIZE_UDF
SELECT Json_Array_Add(Json_Array(56,3.1416,'foo',NULL)) Array;
SELECT Json_Array_Add(Json_Array(56,3.1416,'foo',NULL),'One more') Array;
SELECT Json_Array_Add(Json_Value('one value'),'One more');
--error ER_CANT_INITIALIZE_UDF
SELECT Json_Array_Add(JsonValue('one value'),'One more');
--error ER_CANT_INITIALIZE_UDF
SELECT Json_Array_Add('one value','One more');
SELECT Json_Array_Add('one value' json_,'One more');
--error ER_CANT_INITIALIZE_UDF
SELECT Json_Value(56,3.1416,'foo',NULL);
SELECT Json_Value(3.1416);
SELECT Json_Value('foo');
SELECT Json_Value(NULL);
SELECT Json_Value();
SELECT JsonValue(56,3.1416,'foo',NULL);
SELECT JsonValue(3.1416);
SELECT JsonValue('foo');
SELECT JsonValue(NULL);
SELECT JsonValue();
SELECT Json_Object();
SELECT Json_Object(Json_Array(56,3.1416,'foo'),NULL);
SELECT Json_Array(Json_Array(56,3.1416,'foo'),NULL);
......@@ -82,7 +83,7 @@ DROP FUNCTION Json_Array;
DROP FUNCTION Json_Array_Add;
DROP FUNCTION Json_Object;
DROP FUNCTION Json_Object_Nonull;
DROP FUNCTION Json_Value;
DROP FUNCTION JsonValue;
DROP FUNCTION Json_Array_Grp;
DROP FUNCTION Json_Object_Grp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment