Commit f741fcc9 authored by Olivier Bertrand's avatar Olivier Bertrand

Handle constant function and argument

  modified:   storage/connect/jsonudf.cpp

Record result of json test
  modified:   storage/connect/mysql-test/connect/r/json.result
parent ffc0f5b3
...@@ -911,10 +911,31 @@ my_bool JSNX::LocateValue(PJVAL jvp) ...@@ -911,10 +911,31 @@ my_bool JSNX::LocateValue(PJVAL jvp)
/* ---------------------------- JSON UDF ----------------------------- */ /* ---------------------------- JSON UDF ----------------------------- */
/***********************************************************************/
/* Program for SubSet re-initialization of the memory pool. */
/***********************************************************************/
static my_bool JsonSubSet(PGLOBAL g)
{
PPOOLHEADER pph = (PPOOLHEADER)g->Sarea;
pph->To_Free = (OFFSET)((g->Createas) ? g->Createas : sizeof(POOLHEADER));
pph->FreeBlk = g->Sarea_Size - pph->To_Free;
return FALSE;
} /* end of JsonSubSet */
/***********************************************************************/
/* Program for saving the status of the memory pools. */
/***********************************************************************/
inline void JsonMemSave(PGLOBAL g)
{
g->Createas = (int)((PPOOLHEADER)g->Sarea)->To_Free;
} /* end of JsonMemSave */
/***********************************************************************/ /***********************************************************************/
/* Allocate and initialise the memory area. */ /* Allocate and initialise the memory area. */
/***********************************************************************/ /***********************************************************************/
static my_bool JsonInit(UDF_INIT *initid, char *message, my_bool mbn, static my_bool JsonInit(UDF_INIT *initid, UDF_ARGS *args,
char *message, my_bool mbn,
unsigned long reslen, unsigned long memlen) unsigned long reslen, unsigned long memlen)
{ {
PGLOBAL g = PlugInit(NULL, memlen); PGLOBAL g = PlugInit(NULL, memlen);
...@@ -929,11 +950,12 @@ static my_bool JsonInit(UDF_INIT *initid, char *message, my_bool mbn, ...@@ -929,11 +950,12 @@ static my_bool JsonInit(UDF_INIT *initid, char *message, my_bool mbn,
} else } else
initid->ptr = (char*)g; initid->ptr = (char*)g;
g->Mrr = (args->arg_count && args->args[0]) ? 1 : 0;
g->Alchecked = (initid->const_item) ? 1 : 0;
initid->maybe_null = mbn; initid->maybe_null = mbn;
initid->const_item = false;
initid->max_length = reslen; initid->max_length = reslen;
return false; return false;
} // end of Json_init } // end of JsonInit
/***********************************************************************/ /***********************************************************************/
/* Check if a path was specified and set jvp according to it. */ /* Check if a path was specified and set jvp according to it. */
...@@ -1135,7 +1157,6 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj, ...@@ -1135,7 +1157,6 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
} // endfor i } // endfor i
reslen = MY_MIN(reslen, 65535); // VARCHAR length limit
return false; return false;
} // end of CalcLen } // end of CalcLen
...@@ -1163,16 +1184,18 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, ...@@ -1163,16 +1184,18 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args,
strcpy(g->Message, errmsg); strcpy(g->Message, errmsg);
g->Sarea_Size = 0; g->Sarea_Size = 0;
return true; return true;
} else } // endif Alloc
g->Sarea_Size = ml;
g->Sarea_Size = ml;
g->Createas = 0;
g->Xchk = NULL;
initid->max_length = rl; initid->max_length = rl;
} // endif Size } // endif Size
break; break;
} // endif IsJson } // endif IsJson
PlugSubSet(g, g->Sarea, g->Sarea_Size); JsonSubSet(g);
return false; return false;
} // end of CheckMemory } // end of CheckMemory
...@@ -1343,7 +1366,7 @@ my_bool Json_Value_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1343,7 +1366,7 @@ my_bool Json_Value_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
return JsonInit(initid, message, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen);
} // end of Json_Value_init } // end of Json_Value_init
char *Json_Value(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Value(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1352,16 +1375,22 @@ char *Json_Value(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1352,16 +1375,22 @@ char *Json_Value(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str; char *str;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, 1, false)) { if (!g->Xchk) {
PJVAL jvp = MakeValue(g, args, 0); if (!CheckMemory(g, initid, args, 1, false)) {
PJVAL jvp = MakeValue(g, args, 0);
if (!(str = Serialize(g, jvp, NULL, 0))) if (!(str = Serialize(g, jvp, NULL, 0)))
str = strcpy(result, g->Message);
} else
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
// Keep result of constant function
g->Xchk = (g->Alchecked) ? str : NULL;
} else } else
str = strcpy(result, g->Message); str = (char*)g->Xchk;
*res_length = strlen(str); *res_length = strlen(str);
return str; return str;
} // end of Json_Value } // end of Json_Value
...@@ -1378,32 +1407,36 @@ my_bool Json_Array_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1378,32 +1407,36 @@ my_bool Json_Array_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
unsigned long reslen, memlen; unsigned long reslen, memlen;
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
return JsonInit(initid, message, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen);
} // end of Json_Array_init } // end of Json_Array_init
char *Json_Array(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Array(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *) unsigned long *res_length, char *, char *)
{ {
char *str; char *str;
uint i;
PJAR arp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!g->Xchk) {
arp = new(g)JARRAY; if (!CheckMemory(g, initid, args, args->arg_count, false)) {
PJAR arp = new(g)JARRAY;
for (i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
arp->AddValue(g, MakeValue(g, args, i)); arp->AddValue(g, MakeValue(g, args, i));
arp->InitArray(g);
arp->InitArray(g); if (!(str = Serialize(g, arp, NULL, 0)))
str = strcpy(result, g->Message);
if (!(str = Serialize(g, arp, NULL, 0))) } else
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
// Keep result of constant function
g->Xchk = (g->Alchecked) ? str : NULL;
} else } else
str = strcpy(result, g->Message); str = (char*)g->Xchk;
*res_length = strlen(str); *res_length = strlen(str);
return str; return str;
} // end of Json_Array } // end of Json_Array
...@@ -1428,8 +1461,8 @@ my_bool Json_Array_Add_Values_init(UDF_INIT *initid, UDF_ARGS *args, char *messa ...@@ -1428,8 +1461,8 @@ my_bool Json_Array_Add_Values_init(UDF_INIT *initid, UDF_ARGS *args, char *messa
} else } else
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Array_Add_init } // end of Json_Array_Add_Values_init
char *Json_Array_Add_Values(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Array_Add_Values(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *) unsigned long *res_length, char *, char *)
...@@ -1437,27 +1470,33 @@ char *Json_Array_Add_Values(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1437,27 +1470,33 @@ char *Json_Array_Add_Values(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!g->Xchk) {
PJAR arp; if (!CheckMemory(g, initid, args, args->arg_count, false)) {
PJVAL jvp = MakeValue(g, args, 0); PJAR arp;
PJVAL jvp = MakeValue(g, args, 0);
if (jvp->GetValType() != TYPE_JAR) {
arp = new(g)JARRAY;
arp->AddValue(g, jvp);
} else
arp = jvp->GetArray();
if (jvp->GetValType() != TYPE_JAR) { for (uint i = 1; i < args->arg_count; i++)
arp = new(g)JARRAY; arp->AddValue(g, MakeValue(g, args, i));
arp->AddValue(g, jvp);
} else
arp = jvp->GetArray();
for (uint i = 1; i < args->arg_count; i++) arp->InitArray(g);
arp->AddValue(g, MakeValue(g, args, i)); str = Serialize(g, arp, NULL, 0);
} // endif CheckMemory
arp->InitArray(g); if (!str) {
str = Serialize(g, arp, NULL, 0); PUSH_WARNING(g->Message);
} // endif CheckMemory str = args->args[0];
} // endif str
if (!str) { // Keep result of constant function
PUSH_WARNING(g->Message); g->Xchk = (g->Alchecked) ? str : NULL;
str = args->args[0]; } else
} // endif str str = (char*)g->Xchk;
*res_length = (str) ? strlen(str) : 0; *res_length = (str) ? strlen(str) : 0;
return str; return str;
...@@ -1484,7 +1523,7 @@ my_bool Json_Array_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1484,7 +1523,7 @@ my_bool Json_Array_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, false, reslen, memlen, true);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Array_Add_init } // end of Json_Array_Add_init
char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1493,12 +1532,22 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1493,12 +1532,22 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->Xchk) {
// This constant function was recalled
str = (char*)g->Xchk;
*res_length = strlen(str);
return str;
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, true)) {
int *x = NULL, n = 2; int *x = NULL, n = 2;
PJSON top; PJSON top;
PJVAL jvp; PJVAL jvp;
PJAR arp; PJAR arp;
jvp = MakeValue(g, args, 0);
top = jvp->GetJson();
if (args->arg_count > 2) { if (args->arg_count > 2) {
if (args->arg_type[2] == INT_RESULT) { if (args->arg_type[2] == INT_RESULT) {
x = (int*)PlugSubAlloc(g, NULL, sizeof(int)); x = (int*)PlugSubAlloc(g, NULL, sizeof(int));
...@@ -1509,9 +1558,6 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1509,9 +1558,6 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif count } // endif count
jvp = MakeValue(g, args, 0);
top = jvp->GetJson();
if (CheckPath(g, args, top, jvp, n)) if (CheckPath(g, args, top, jvp, n))
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
else if (jvp && jvp->GetValType() == TYPE_JAR) { else if (jvp && jvp->GetValType() == TYPE_JAR) {
...@@ -1525,12 +1571,14 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1525,12 +1571,14 @@ char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif CheckMemory } // endif CheckMemory
// In case of error or file, return unchanged argument // In case of error or file, return unchanged argument
if (!str) { if (!str)
str = args->args[0]; str = MakePSZ(g, args, 0);
*res_length = args->lengths[0];
} else
*res_length = strlen(str);
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
*res_length = strlen(str);
return str; return str;
} // end of Json_Array_Add } // end of Json_Array_Add
...@@ -1558,7 +1606,7 @@ my_bool Json_Array_Delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1558,7 +1606,7 @@ my_bool Json_Array_Delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, false, reslen, memlen, true);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Array_Delete_init } // end of Json_Array_Delete_init
char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1567,6 +1615,13 @@ char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1567,6 +1615,13 @@ char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->Xchk) {
// This constant function was recalled
str = (char*)g->Xchk;
*res_length = strlen(str);
return str;
} // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, true)) {
int n; int n;
PJAR arp; PJAR arp;
...@@ -1587,13 +1642,15 @@ char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1587,13 +1642,15 @@ char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif CheckMemory } // endif CheckMemory
// In case of error or file, return unchanged argument // In case of error or file, return unchanged argument
if (!str) { if (!str)
str = args->args[0]; str = MakePSZ(g, args, 0);
*res_length = args->lengths[0];
} else
*res_length = strlen(str);
return str; if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
*res_length = (str) ? strlen(str) : 0;
return str;
} // end of Json_Array_Delete } // end of Json_Array_Delete
void Json_Array_Delete_deinit(UDF_INIT* initid) void Json_Array_Delete_deinit(UDF_INIT* initid)
...@@ -1609,7 +1666,7 @@ my_bool Json_Object_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1609,7 +1666,7 @@ my_bool Json_Object_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
unsigned long reslen, memlen; unsigned long reslen, memlen;
CalcLen(args, true, reslen, memlen); CalcLen(args, true, reslen, memlen);
return JsonInit(initid, message, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen);
} // end of Json_Object_init } // end of Json_Object_init
char *Json_Object(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Object(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1618,17 +1675,23 @@ char *Json_Object(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1618,17 +1675,23 @@ char *Json_Object(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!g->Xchk) {
PJOB objp = new(g)JOBJECT; if (!CheckMemory(g, initid, args, args->arg_count, true)) {
PJOB objp = new(g)JOBJECT;
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i));
str = Serialize(g, objp, NULL, 0); str = Serialize(g, objp, NULL, 0);
} // endif CheckMemory } // endif CheckMemory
if (!str) if (!str)
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
// Keep result of constant function
g->Xchk = (g->Alchecked) ? str : NULL;
} else
str = (char*)g->Xchk;
*res_length = strlen(str); *res_length = strlen(str);
return str; return str;
...@@ -1648,7 +1711,7 @@ my_bool Json_Object_Nonull_init(UDF_INIT *initid, UDF_ARGS *args, ...@@ -1648,7 +1711,7 @@ my_bool Json_Object_Nonull_init(UDF_INIT *initid, UDF_ARGS *args,
unsigned long reslen, memlen; unsigned long reslen, memlen;
CalcLen(args, true, reslen, memlen); CalcLen(args, true, reslen, memlen);
return JsonInit(initid, message, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen);
} // end of Json_Object_Nonull_init } // end of Json_Object_Nonull_init
char *Json_Object_Nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Object_Nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1657,19 +1720,25 @@ char *Json_Object_Nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1657,19 +1720,25 @@ char *Json_Object_Nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str; char *str;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, args->arg_count, true)) { if (!g->Xchk) {
PJVAL jvp; if (!CheckMemory(g, initid, args, args->arg_count, true)) {
PJOB objp = new(g)JOBJECT; PJVAL jvp;
PJOB objp = new(g)JOBJECT;
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
if (!(jvp = MakeValue(g, args, i))->IsNull()) if (!(jvp = MakeValue(g, args, i))->IsNull())
objp->SetValue(g, jvp, MakeKey(g, args, i)); objp->SetValue(g, jvp, MakeKey(g, args, i));
str = Serialize(g, objp, NULL, 0); str = Serialize(g, objp, NULL, 0);
} // endif CheckMemory } // endif CheckMemory
if (!str) if (!str)
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
// Keep result of constant function
g->Xchk = (g->Alchecked) ? str : NULL;
} else
str = (char*)g->Xchk;
*res_length = strlen(str); *res_length = strlen(str);
return str; return str;
...@@ -1696,7 +1765,7 @@ my_bool Json_Object_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1696,7 +1765,7 @@ my_bool Json_Object_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, false, reslen, memlen, true);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Object_Add_init } // end of Json_Object_Add_init
char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1705,6 +1774,13 @@ char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1705,6 +1774,13 @@ char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *key, *str = NULL; char *key, *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->Xchk) {
// This constant function was recalled
str = (char*)g->Xchk;
*res_length = strlen(str);
return str;
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, true)) { if (!CheckMemory(g, initid, args, 2, false, true)) {
PJOB jobp; PJOB jobp;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp = MakeValue(g, args, 0);
...@@ -1724,12 +1800,14 @@ char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1724,12 +1800,14 @@ char *Json_Object_Add(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif CheckMemory } // endif CheckMemory
// In case of error or file, return unchanged argument // In case of error or file, return unchanged argument
if (!str) { if (!str)
str = args->args[0]; str = MakePSZ(g, args, 0);
*res_length = args->lengths[0];
} else
*res_length = strlen(str);
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
*res_length = strlen(str);
return str; return str;
} // end of Json_Object_Add } // end of Json_Object_Add
...@@ -1757,7 +1835,7 @@ my_bool Json_Object_Delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1757,7 +1835,7 @@ my_bool Json_Object_Delete_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen, true); CalcLen(args, false, reslen, memlen, true);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Object_Delete_init } // end of Json_Object_Delete_init
char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1766,6 +1844,13 @@ char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1766,6 +1844,13 @@ char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->Xchk) {
// This constant function was recalled
str = (char*)g->Xchk;
*res_length = strlen(str);
return str;
} // endif Xchk
if (!CheckMemory(g, initid, args, 1, false, true)) { if (!CheckMemory(g, initid, args, 1, false, true)) {
char *key; char *key;
PJOB jobp; PJOB jobp;
...@@ -1785,12 +1870,14 @@ char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1785,12 +1870,14 @@ char *Json_Object_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif CheckMemory } // endif CheckMemory
// In case of error or file, return unchanged argument // In case of error or file, return unchanged argument
if (!str) { if (!str)
str = args->args[0]; str = MakePSZ(g, args, 0);
*res_length = args->lengths[0];
} else
*res_length = strlen(str);
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
*res_length = strlen(str);
return str; return str;
} // end of Json_Object_Delete } // end of Json_Object_Delete
...@@ -1815,7 +1902,7 @@ my_bool Json_Object_List_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1815,7 +1902,7 @@ my_bool Json_Object_List_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Object_List_init } // end of Json_Object_List_init
char *Json_Object_List(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Object_List(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -1824,20 +1911,31 @@ char *Json_Object_List(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1824,20 +1911,31 @@ char *Json_Object_List(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (!CheckMemory(g, initid, args, 1, false)) { if (!g->N) {
PJVAL jvp = MakeValue(g, args, 0); if (!CheckMemory(g, initid, args, 1, false)) {
PJVAL jvp = MakeValue(g, args, 0);
if (jvp && jvp->GetValType() == TYPE_JOB) { if (jvp && jvp->GetValType() == TYPE_JOB) {
PJOB jobp = jvp->GetObject(); PJOB jobp = jvp->GetObject();
PJAR jarp = jobp->GetKeyList(g); PJAR jarp = jobp->GetKeyList(g);
if (!(str = Serialize(g, jarp, NULL, 0))) if (!(str = Serialize(g, jarp, NULL, 0)))
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
} else } else
PUSH_WARNING("First argument is not an object"); PUSH_WARNING("First argument is not an object");
} // endif CheckMemory
} // endif CheckMemory
if (g->Alchecked) {
// Keep result of constant function
g->Xchk = str;
g->N = 1; // str can be NULL
} // endif Alchecked
} else
str = (char*)g->Xchk;
*res_length = (str) ? strlen(str) : 0; *res_length = (str) ? strlen(str) : 0;
return str; return str;
...@@ -1864,7 +1962,7 @@ my_bool Json_Array_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1864,7 +1962,7 @@ my_bool Json_Array_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
reslen *= n; reslen *= n;
memlen += ((memlen - MEMFIX) * (n - 1)); memlen += ((memlen - MEMFIX) * (n - 1));
if (JsonInit(initid, message, false, reslen, memlen)) if (JsonInit(initid, args, message, false, reslen, memlen))
return true; return true;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
...@@ -1934,7 +2032,7 @@ my_bool Json_Object_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -1934,7 +2032,7 @@ my_bool Json_Object_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
reslen *= n; reslen *= n;
memlen += ((memlen - MEMFIX) * (n - 1)); memlen += ((memlen - MEMFIX) * (n - 1));
if (JsonInit(initid, message, false, reslen, memlen)) if (JsonInit(initid, args, message, false, reslen, memlen))
return true; return true;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
...@@ -2005,8 +2103,18 @@ my_bool Json_Get_String_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2005,8 +2103,18 @@ my_bool Json_Get_String_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else } else
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
memlen += 1000; // TODO: calculate this if (IsJson(args, 0) == 2) {
return JsonInit(initid, message, true, reslen, memlen); char fn[_MAX_PATH];
long fl;
memcpy(fn, args->args[0], args->lengths[0]);
fn[args->lengths[0]] = 0;
fl = GetFileLength(fn);
memlen += fl * 3;
} else
memlen += args->lengths[0] * 3;
return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Get_String_init } // end of Json_Get_String_init
char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -2015,21 +2123,38 @@ char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2015,21 +2123,38 @@ char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str = NULL; char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
str = (char*)g->Xchk;
goto fin;
} else if (g->Alchecked)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path; char *p, *path;
PJSON jsp; PJSON jsp;
PJSNX jsx; PJSNX jsx;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp;
if ((p = jvp->GetString())) { if (!g->Xchk) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { jvp = MakeValue(g, args, 0);
PUSH_WARNING(g->Message);
return NULL; if ((p = jvp->GetString())) {
} // endif jsp if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
} // endif jsp
} else
jsp = jvp->GetJson();
if (g->Mrr) { // First argument is a constant
g->Xchk = jsp;
JsonMemSave(g);
} // endif Mrr
} else } else
jsp = jvp->GetJson(); jsp = (PJSON)g->Xchk;
path = MakePSZ(g, args, 1); path = MakePSZ(g, args, 1);
jsx = new(g)JSNX(g, jsp, TYPE_STRING, initid->max_length); jsx = new(g)JSNX(g, jsp, TYPE_STRING, initid->max_length);
...@@ -2044,8 +2169,13 @@ char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2044,8 +2169,13 @@ char *Json_Get_String(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!jsx->GetValue()->IsNull()) if (!jsx->GetValue()->IsNull())
str = jsx->GetValue()->GetCharValue(); str = jsx->GetValue()->GetCharValue();
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
} // endif CheckMemory } // endif CheckMemory
fin:
*res_length = (str) ? strlen(str) : 0; *res_length = (str) ? strlen(str) : 0;
return str; return str;
} // end of Json_Get_String } // end of Json_Get_String
...@@ -2075,7 +2205,7 @@ my_bool Json_Get_Int_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2075,7 +2205,7 @@ my_bool Json_Get_Int_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
memlen += 1000; // TODO: calculate this memlen += 1000; // TODO: calculate this
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Get_Int_init } // end of Json_Get_Int_init
long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result, long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -2083,22 +2213,37 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2083,22 +2213,37 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result,
{ {
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N)
return (g->Xchk) ? *(long long*)g->Xchk : NULL;
else if (g->Alchecked)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, false)) {
long long n;
char *p, *path; char *p, *path;
long long n;
PJSON jsp; PJSON jsp;
PJSNX jsx; PJSNX jsx;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp;
if ((p = jvp->GetString())) { if (!g->Xchk) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { jvp = MakeValue(g, args, 0);
PUSH_WARNING(g->Message);
return NULL; if ((p = jvp->GetString())) {
} // endif jsp if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
} // endif jsp
} else
jsp = jvp->GetJson();
if (g->Mrr) { // First argument is a constant
g->Xchk = jsp;
JsonMemSave(g);
} // endif Mrr
} else } else
jsp = jvp->GetJson(); jsp = (PJSON)g->Xchk;
path = MakePSZ(g, args, 1); path = MakePSZ(g, args, 1);
jsx = new(g)JSNX(g, jsp, TYPE_BIGINT); jsx = new(g)JSNX(g, jsp, TYPE_BIGINT);
...@@ -2106,7 +2251,7 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2106,7 +2251,7 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jsx->SetJpath(g, path)) { if (jsx->SetJpath(g, path)) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
return NULL; return NULL;
} // endif SetJpath } // endif SetJpath
jsx->ReadValue(g); jsx->ReadValue(g);
...@@ -2116,6 +2261,14 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2116,6 +2261,14 @@ long long Json_Get_Int(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif IsNull } // endif IsNull
n = jsx->GetValue()->GetBigintValue(); n = jsx->GetValue()->GetBigintValue();
if (g->Alchecked) {
// Keep result of constant function
long long *np = (long long*)PlugSubAlloc(g, NULL, sizeof(long long));
*np = n;
g->Xchk = np;
} // endif Alchecked
return n; return n;
} else } else
return NULL; return NULL;
...@@ -2155,7 +2308,7 @@ my_bool Json_Get_Real_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2155,7 +2308,7 @@ my_bool Json_Get_Real_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
memlen += 1000; // TODO: calculate this memlen += 1000; // TODO: calculate this
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Get_Real_init } // end of Json_Get_Real_init
double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result, double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -2163,21 +2316,37 @@ double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2163,21 +2316,37 @@ double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result,
{ {
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N)
return (g->Xchk) ? *(double*)g->Xchk : NULL;
else if (g->Alchecked)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path; char *p, *path;
double d; double d;
PJSON jsp; PJSON jsp;
PJSNX jsx; PJSNX jsx;
PJVAL jvp = MakeValue(g, args, 0); PJVAL jvp;
if ((p = jvp->GetString())) { if (!g->Xchk) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { jvp = MakeValue(g, args, 0);
PUSH_WARNING(g->Message);
return NULL; if ((p = jvp->GetString())) {
} // endif jsp if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message);
return NULL;
} // endif jsp
} else
jsp = jvp->GetJson();
if (g->Mrr) { // First argument is a constant
g->Xchk = jsp;
JsonMemSave(g);
} // endif Mrr
} else } else
jsp = jvp->GetJson(); jsp = (PJSON)g->Xchk;
path = MakePSZ(g, args, 1); path = MakePSZ(g, args, 1);
jsx = new(g)JSNX(g, jsp, TYPE_DOUBLE); jsx = new(g)JSNX(g, jsp, TYPE_DOUBLE);
...@@ -2195,6 +2364,14 @@ double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2195,6 +2364,14 @@ double Json_Get_Real(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif IsNull } // endif IsNull
d = jsx->GetValue()->GetFloatValue(); d = jsx->GetValue()->GetFloatValue();
if (g->Alchecked) {
// Keep result of constant function
double *dp = (double*)PlugSubAlloc(g, NULL, sizeof(double));
*dp = d;
g->Xchk = dp;
} // endif Alchecked
return d; return d;
} else } else
return NULL; return NULL;
...@@ -2228,16 +2405,24 @@ my_bool Json_Locate_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2228,16 +2405,24 @@ my_bool Json_Locate_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
memlen += more; // TODO: calculate this memlen += more; // TODO: calculate this
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Locate_init } // end of Json_Locate_init
char *Json_Locate(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Locate(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *) unsigned long *res_length, char *, char *)
{ {
char *path = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
path = (char*)g->Xchk;
*res_length = (path) ? strlen(path) : 0;
return path;
} else if (g->Alchecked)
g->N = 1;
if (!CheckMemory(g, initid, args, 1, false)) { if (!CheckMemory(g, initid, args, 1, false)) {
char *p, *path = NULL; char *p;
int rc; int rc;
PJVAL jvp; PJVAL jvp;
PJSON jsp; PJSON jsp;
...@@ -2254,21 +2439,34 @@ char *Json_Locate(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2254,21 +2439,34 @@ char *Json_Locate(UDF_INIT *initid, UDF_ARGS *args, char *result,
goto err; goto err;
} // endif rc } // endif rc
jvp = MakeValue(g, args, 0); if (!g->Xchk) {
jvp = MakeValue(g, args, 0);
if ((p = jvp->GetString())) { if ((p = jvp->GetString())) {
if (!(jsp = ParseJson(g, p, strlen(p)))) { if (!(jsp = ParseJson(g, p, strlen(p)))) {
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
goto err; goto err;
} // endif jsp } // endif jsp
} else
jsp = jvp->GetJson();
if (g->Mrr) { // First argument is a constant
g->Xchk = jsp;
JsonMemSave(g);
} // endif Mrr
} else } else
jsp = jvp->GetJson(); jsp = (PJSON)g->Xchk;
jsx = new(g)JSNX(g, jsp, TYPE_STRING); jsx = new(g)JSNX(g, jsp, TYPE_STRING);
path = jsx->Locate(g, jsp, args->args[1], args->arg_type[1], args->lengths[1]); path = jsx->Locate(g, jsp, args->args[1], args->arg_type[1], args->lengths[1]);
if (g->Alchecked)
// Keep result of constant function
g->Xchk = path;
err: err:
g->jump_level--; g->jump_level--;
*res_length = (path) ? strlen(path) : 0; *res_length = (path) ? strlen(path) : 0;
...@@ -2288,10 +2486,10 @@ void Json_Locate_deinit(UDF_INIT* initid) ...@@ -2288,10 +2486,10 @@ void Json_Locate_deinit(UDF_INIT* initid)
/***********************************************************************/ /***********************************************************************/
my_bool Json_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message) my_bool Json_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{ {
unsigned long reslen, memlen, more = 1024; unsigned long reslen, memlen, fl, more = 1024;
if (args->arg_count > 4) { if (args->arg_count < 1 || args->arg_count > 4) {
strcpy(message, "Json_File cannot accept more than 4 arguments"); strcpy(message, "Json_File only accepts 1 to 4 arguments");
return true; return true;
} else if (args->arg_type[0] != STRING_RESULT) { } else if (args->arg_type[0] != STRING_RESULT) {
strcpy(message, "Json_File first argument must be a (string) file name"); strcpy(message, "Json_File first argument must be a (string) file name");
...@@ -2313,12 +2511,16 @@ my_bool Json_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2313,12 +2511,16 @@ my_bool Json_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
initid->maybe_null = 1; initid->maybe_null = 1;
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
fl = GetFileLength(args->args[0]);
if (initid->const_item)
more += fl;
if (args->arg_count > 2 && *(longlong*)args->args[2]) if (args->arg_count > 1 && *(longlong*)args->args[1])
more += GetFileLength(args->args[0]) * M; more += fl * M;
memlen += more; memlen += more;
return JsonInit(initid, message, false, reslen, memlen); return JsonInit(initid, args, message, false, reslen, memlen);
} // end of Json_File_init } // end of Json_File_init
char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -2327,6 +2529,12 @@ char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2327,6 +2529,12 @@ char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
char *str, *fn; char *str, *fn;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
str = (char*)g->Xchk;
goto fin;
} else if (g->Alchecked)
g->N = 1;
PlugSubSet(g, g->Sarea, g->Sarea_Size); PlugSubSet(g, g->Sarea, g->Sarea_Size);
fn = MakePSZ(g, args, 0); fn = MakePSZ(g, args, 0);
...@@ -2392,6 +2600,11 @@ char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2392,6 +2600,11 @@ char *Json_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
} else } else
str = GetJsonFile(g, fn); str = GetJsonFile(g, fn);
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
fin:
*res_length = (str) ? strlen(str) : 0; *res_length = (str) ? strlen(str) : 0;
return str; return str;
} // end of Json_File } // end of Json_File
...@@ -2423,7 +2636,7 @@ my_bool Json_Make_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ...@@ -2423,7 +2636,7 @@ my_bool Json_Make_File_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} // endifs } // endifs
CalcLen(args, false, reslen, memlen); CalcLen(args, false, reslen, memlen);
return JsonInit(initid, message, true, reslen, memlen); return JsonInit(initid, args, message, true, reslen, memlen);
} // end of Json_Make_File_init } // end of Json_Make_File_init
char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result, char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
...@@ -2434,8 +2647,25 @@ char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2434,8 +2647,25 @@ char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
PJVAL jvp; PJVAL jvp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
if (g->N) {
str = (char*)g->Xchk;
goto fin;
} else if (g->Alchecked)
g->N = 1;
PlugSubSet(g, g->Sarea, g->Sarea_Size); PlugSubSet(g, g->Sarea, g->Sarea_Size);
jvp = MakeValue(g, args, 0);
if (!g->Xchk) {
jvp = MakeValue(g, args, 0);
if (g->Mrr) { // First argument is a constant
g->Xchk = jvp;
JsonMemSave(g);
} // endif Mrr
} else
jvp = (PJVAL)g->Xchk;
fn = MakePSZ(g, args, 1); fn = MakePSZ(g, args, 1);
pretty = (args->arg_count > 2) ? (int)*(longlong*)args->args[2] : 2; pretty = (args->arg_count > 2) ? (int)*(longlong*)args->args[2] : 2;
...@@ -2443,6 +2673,12 @@ char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2443,6 +2673,12 @@ char *Json_Make_File(UDF_INIT *initid, UDF_ARGS *args, char *result,
PUSH_WARNING(msg); PUSH_WARNING(msg);
str= fn; str= fn;
if (g->Alchecked)
// Keep result of constant function
g->Xchk = str;
fin:
*res_length = (str) ? strlen(str) : 0; *res_length = (str) ? strlen(str) : 0;
return str; return str;
} // end of Json_Make_File } // end of Json_Make_File
......
...@@ -171,6 +171,40 @@ line ...@@ -171,6 +171,40 @@ line
] ]
DROP TABLE t1; DROP TABLE t1;
# #
# Testing a pretty=0 file
#
CREATE TABLE t1
(
ISBN CHAR(15) NOT NULL,
Language CHAR(2) FIELD_FORMAT='LANG',
Subject CHAR(32) FIELD_FORMAT='SUBJECT',
AuthorFN CHAR(128) FIELD_FORMAT='AUTHOR:[X]:FIRSTNAME',
AuthorLN CHAR(128) FIELD_FORMAT='AUTHOR:[X]:LASTNAME',
Title CHAR(32) FIELD_FORMAT='TITLE',
Translation CHAR(32) FIELD_FORMAT='TRANSLATED:PREFIX',
TranslatorFN CHAR(80) FIELD_FORMAT='TRANSLATED:TRANSLATOR:FIRSTNAME',
TranslatorLN CHAR(80) FIELD_FORMAT='TRANSLATED:TRANSLATOR:LASTNAME',
Publisher CHAR(20) FIELD_FORMAT='PUBLISHER:NAME',
Location CHAR(16) FIELD_FORMAT='PUBLISHER:PLACE',
Year int(4) FIELD_FORMAT='DATEPUB',
INDEX IX(ISBN)
)
ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bib0.json' LRECL=320 OPTION_LIST='Pretty=0';
SHOW INDEX FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 IX 1 ISBN A NULL NULL NULL XINDEX
SELECT * FROM t1;
ISBN Language Subject AuthorFN AuthorLN Title Translation TranslatorFN TranslatorLN Publisher Location Year
9782212090819 fr applications Jean-Michel Bernadac Construire une application XML NULL NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Franois Knab Construire une application XML NULL NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 2001
DESCRIBE SELECT * FROM t1 WHERE ISBN = '9782212090819';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref IX IX 15 const 1 Using where
UPDATE t1 SET AuthorFN = 'Philippe' WHERE ISBN = '9782212090819';
ERROR HY000: Got error 122 'Cannot write expanded column when Pretty is not 2' from CONNECT
DROP TABLE t1;
#
# A file with 2 arrays # A file with 2 arrays
# #
CREATE TABLE t1 ( CREATE TABLE t1 (
......
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