Skip to content

Commit e027f5e

Browse files
committed
- Fix MDEV-7616 by adding SQLCOM_SET_OPTION to the accepted command list.
modified: storage/connect/ha_connect.cc - Add new JSON UDF functions and JSON functionalities. modified: storage/connect/json.cpp storage/connect/json.h storage/connect/jsonudf.cpp storage/connect/tabjson.cpp
1 parent a736e63 commit e027f5e

File tree

5 files changed

+120
-20
lines changed

5 files changed

+120
-20
lines changed

storage/connect/ha_connect.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
41124112
case SQLCOM_UPDATE_MULTI:
41134113
case SQLCOM_SELECT:
41144114
case SQLCOM_OPTIMIZE:
4115+
case SQLCOM_SET_OPTION:
41154116
break;
41164117
case SQLCOM_LOCK_TABLES:
41174118
locked= 1;

storage/connect/json.cpp

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -881,27 +881,26 @@ PJVAL JOBJECT::GetValue(const char* key)
881881
/***********************************************************************/
882882
/* Return the text corresponding to all keys (XML like). */
883883
/***********************************************************************/
884-
PSZ JOBJECT::GetText(PGLOBAL g)
884+
PSZ JOBJECT::GetText(PGLOBAL g, PSZ text)
885885
{
886-
char *p, *text = (char*)PlugSubAlloc(g, NULL, 0);
887-
bool b = true;
886+
int n;
888887

889-
if (!First)
890-
return NULL;
891-
else for (PJPR jp = First; jp; jp = jp->Next) {
892-
if (!(p = jp->Val->GetString()))
893-
p = "???";
888+
if (!text) {
889+
text = (char*)PlugSubAlloc(g, NULL, 0);
890+
text[0] = 0;
891+
n = 1;
892+
} else
893+
n = 0;
894894

895-
if (b) {
896-
strcpy(text, p);
897-
b = false;
898-
} else
899-
strcat(strcat(text, " "), p);
895+
if (!First && n)
896+
return NULL;
897+
else for (PJPR jp = First; jp; jp = jp->Next)
898+
jp->Val->GetText(g, text);
900899

901-
} // endfor jp
900+
if (n)
901+
PlugSubAlloc(g, NULL, strlen(text) + 1);
902902

903-
PlugSubAlloc(g, NULL, strlen(text) + 1);
904-
return text;
903+
return text + n;
905904
} // end of GetValue;
906905

907906
/***********************************************************************/
@@ -924,6 +923,18 @@ void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PSZ key)
924923

925924
} // end of SetValue
926925

926+
/***********************************************************************/
927+
/* True if void or if all members are nulls. */
928+
/***********************************************************************/
929+
bool JOBJECT::IsNull(void)
930+
{
931+
for (PJPR jp = First; jp; jp = jp->Next)
932+
if (!jp->Val->IsNull())
933+
return false;
934+
935+
return true;
936+
} // end of IsNull
937+
927938
/* -------------------------- Class JARRAY --------------------------- */
928939

929940
/***********************************************************************/
@@ -1012,6 +1023,18 @@ bool JARRAY::DeleteValue(int n)
10121023

10131024
} // end of DeleteValue
10141025

1026+
/***********************************************************************/
1027+
/* True if void or if all members are nulls. */
1028+
/***********************************************************************/
1029+
bool JARRAY::IsNull(void)
1030+
{
1031+
for (int i = 0; i < Size; i++)
1032+
if (!Mvals[i]->IsNull())
1033+
return false;
1034+
1035+
return true;
1036+
} // end of IsNull
1037+
10151038
/* -------------------------- Class JVALUE- -------------------------- */
10161039

10171040
/***********************************************************************/
@@ -1086,6 +1109,25 @@ PSZ JVALUE::GetString(void)
10861109
return (Value) ? Value->GetCharString(buf) : NULL;
10871110
} // end of GetString
10881111

1112+
/***********************************************************************/
1113+
/* Return the Value's String value. */
1114+
/***********************************************************************/
1115+
PSZ JVALUE::GetText(PGLOBAL g, PSZ text)
1116+
{
1117+
if (Jsp && Jsp->GetType() == TYPE_JOB)
1118+
return Jsp->GetText(g, text);
1119+
1120+
char buf[32];
1121+
PSZ s = (Value) ? Value->GetCharString(buf) : NULL;
1122+
1123+
if (s)
1124+
strcat(strcat(text, " "), s);
1125+
else
1126+
strcat(text, " ???");
1127+
1128+
return text;
1129+
} // end of GetText
1130+
10891131
/***********************************************************************/
10901132
/* Set the Value's value as the given integer. */
10911133
/***********************************************************************/
@@ -1110,3 +1152,11 @@ void JVALUE::SetString(PGLOBAL g, PSZ s)
11101152
Value = AllocateValue(g, s, TYPE_STRING);
11111153
} // end of AddFloat
11121154

1155+
/***********************************************************************/
1156+
/* True when its JSON or normal value is null. */
1157+
/***********************************************************************/
1158+
bool JVALUE::IsNull(void)
1159+
{
1160+
return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsNull() : true;
1161+
} // end of IsNull
1162+

storage/connect/json.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class JSON : public BLOCK {
152152
virtual int GetInteger(void) {X return 0;}
153153
virtual double GetFloat() {X return 0.0;}
154154
virtual PSZ GetString() {X return NULL;}
155-
virtual PSZ GetText(PGLOBAL g) {X return NULL;}
155+
virtual PSZ GetText(PGLOBAL g, PSZ text) {X return NULL;}
156156
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) {X return true;}
157157
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key) {X}
158158
virtual void SetValue(PVAL valp) {X}
@@ -161,6 +161,7 @@ class JSON : public BLOCK {
161161
virtual void SetInteger(PGLOBAL g, int n) {X}
162162
virtual void SetFloat(PGLOBAL g, double f) {X}
163163
virtual bool DeleteValue(int i) {X return true;}
164+
virtual bool IsNull(void) {X return true;}
164165

165166
protected:
166167
int Size;
@@ -182,8 +183,9 @@ class JOBJECT : public JSON {
182183
virtual PJPR AddPair(PGLOBAL g, PSZ key);
183184
virtual PJOB GetObject(void) {return this;}
184185
virtual PJVAL GetValue(const char* key);
185-
virtual PSZ GetText(PGLOBAL g);
186+
virtual PSZ GetText(PGLOBAL g, PSZ text);
186187
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key);
188+
virtual bool IsNull(void);
187189

188190
protected:
189191
PJPR First;
@@ -208,6 +210,7 @@ class JARRAY : public JSON {
208210
virtual PJVAL GetValue(int i);
209211
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
210212
virtual bool DeleteValue(int n);
213+
virtual bool IsNull(void);
211214

212215
protected:
213216
// Members
@@ -244,11 +247,13 @@ class JVALUE : public JSON {
244247
virtual int GetInteger(void);
245248
virtual double GetFloat(void);
246249
virtual PSZ GetString(void);
250+
virtual PSZ GetText(PGLOBAL g, PSZ text);
247251
virtual void SetValue(PVAL valp) {Value = valp;}
248252
virtual void SetValue(PJSON jsp) {Jsp = jsp;}
249253
virtual void SetString(PGLOBAL g, PSZ s);
250254
virtual void SetInteger(PGLOBAL g, int n);
251255
virtual void SetFloat(PGLOBAL g, double f);
256+
virtual bool IsNull(void);
252257

253258
protected:
254259
PJSON Jsp; // To the json value

storage/connect/jsonudf.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ DllExport my_bool Json_Object_init(UDF_INIT*, UDF_ARGS*, char*);
3737
DllExport char *Json_Object(UDF_INIT*, UDF_ARGS*, char*,
3838
unsigned long*, char *, char *);
3939
DllExport void Json_Object_deinit(UDF_INIT*);
40+
DllExport my_bool Json_Object_Nonull_init(UDF_INIT*, UDF_ARGS*, char*);
41+
DllExport char *Json_Object_Nonull(UDF_INIT*, UDF_ARGS*, char*,
42+
unsigned long*, char *, char *);
43+
DllExport void Json_Object_Nonull_deinit(UDF_INIT*);
4044
DllExport my_bool Json_Array_Grp_init(UDF_INIT*, UDF_ARGS*, char*);
4145
DllExport void Json_Array_Grp_add(UDF_INIT *, UDF_ARGS *, char *, char *);
4246
DllExport char *Json_Array_Grp(UDF_INIT*, UDF_ARGS*, char*,
@@ -437,6 +441,46 @@ void Json_Object_deinit(UDF_INIT* initid)
437441
PlugExit((PGLOBAL)initid->ptr);
438442
} // end of Json_Object_deinit
439443

444+
/***********************************************************************/
445+
/* Make a Json Oject containing all not null parameters. */
446+
/***********************************************************************/
447+
my_bool Json_Object_Nonull_init(UDF_INIT *initid, UDF_ARGS *args,
448+
char *message)
449+
{
450+
unsigned long reslen, memlen;
451+
452+
CalcLen(args, true, reslen, memlen);
453+
return JsonInit(initid, message, reslen, memlen);
454+
} // end of Json_Object_Nonull_init
455+
456+
char *Json_Object_Nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
457+
unsigned long *res_length, char *is_null, char *error)
458+
{
459+
char *str;
460+
uint i;
461+
PJOB objp;
462+
PJVAL jvp;
463+
PGLOBAL g = (PGLOBAL)initid->ptr;
464+
465+
PlugSubSet(g, g->Sarea, g->Sarea_Size);
466+
objp = new(g) JOBJECT;
467+
468+
for (i = 0; i < args->arg_count; i++)
469+
if (!(jvp = MakeValue(g, args, i))->IsNull())
470+
objp->SetValue(g, jvp, MakeKey(g, args, i));
471+
472+
if (!(str = Serialize(g, objp, NULL, 0)))
473+
str = strcpy(result, g->Message);
474+
475+
*res_length = strlen(str);
476+
return str;
477+
} // end of Json_Object_Nonull
478+
479+
void Json_Object_Nonull_deinit(UDF_INIT* initid)
480+
{
481+
PlugExit((PGLOBAL)initid->ptr);
482+
} // end of Json_Object_nonull_deinit
483+
440484
/***********************************************************************/
441485
/* Make a Json array from values comming from rows. */
442486
/***********************************************************************/

storage/connect/tabjson.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm)
493493
if (!IsTypeChar(Buf_Type))
494494
jnp->Valp = AllocateValue(g, Buf_Type, 0, GetPrecision());
495495
else
496-
jnp->Valp = AllocateValue(g, TYPE_DOUBLE);
496+
jnp->Valp = AllocateValue(g, TYPE_DOUBLE, 0, 2);
497497

498498
break;
499499
case OP_MIN:
@@ -610,7 +610,7 @@ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
610610
break;
611611
case TYPE_JOB:
612612
// if (!vp->IsTypeNum() || !Strict) {
613-
vp->SetValue_psz(val->GetObject()->GetText(g));
613+
vp->SetValue_psz(val->GetObject()->GetText(g, NULL));
614614
break;
615615
// } // endif Type
616616

0 commit comments

Comments
 (0)