From e027f5e8d5d966f11d7f38825a8e316ff9d4dd79 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Tue, 24 Feb 2015 23:18:04 +0100 Subject: - 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 --- storage/connect/json.cpp | 82 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 16 deletions(-) (limited to 'storage/connect/json.cpp') diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index 8031ba51b19..7356a86d53c 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -881,27 +881,26 @@ PJVAL JOBJECT::GetValue(const char* key) /***********************************************************************/ /* Return the text corresponding to all keys (XML like). */ /***********************************************************************/ -PSZ JOBJECT::GetText(PGLOBAL g) +PSZ JOBJECT::GetText(PGLOBAL g, PSZ text) { - char *p, *text = (char*)PlugSubAlloc(g, NULL, 0); - bool b = true; + int n; - if (!First) - return NULL; - else for (PJPR jp = First; jp; jp = jp->Next) { - if (!(p = jp->Val->GetString())) - p = "???"; + if (!text) { + text = (char*)PlugSubAlloc(g, NULL, 0); + text[0] = 0; + n = 1; + } else + n = 0; - if (b) { - strcpy(text, p); - b = false; - } else - strcat(strcat(text, " "), p); + if (!First && n) + return NULL; + else for (PJPR jp = First; jp; jp = jp->Next) + jp->Val->GetText(g, text); - } // endfor jp + if (n) + PlugSubAlloc(g, NULL, strlen(text) + 1); - PlugSubAlloc(g, NULL, strlen(text) + 1); - return text; + return text + n; } // end of GetValue; /***********************************************************************/ @@ -924,6 +923,18 @@ void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PSZ key) } // end of SetValue +/***********************************************************************/ +/* True if void or if all members are nulls. */ +/***********************************************************************/ +bool JOBJECT::IsNull(void) +{ + for (PJPR jp = First; jp; jp = jp->Next) + if (!jp->Val->IsNull()) + return false; + + return true; +} // end of IsNull + /* -------------------------- Class JARRAY --------------------------- */ /***********************************************************************/ @@ -1012,6 +1023,18 @@ bool JARRAY::DeleteValue(int n) } // end of DeleteValue +/***********************************************************************/ +/* True if void or if all members are nulls. */ +/***********************************************************************/ +bool JARRAY::IsNull(void) +{ + for (int i = 0; i < Size; i++) + if (!Mvals[i]->IsNull()) + return false; + + return true; +} // end of IsNull + /* -------------------------- Class JVALUE- -------------------------- */ /***********************************************************************/ @@ -1086,6 +1109,25 @@ PSZ JVALUE::GetString(void) return (Value) ? Value->GetCharString(buf) : NULL; } // end of GetString +/***********************************************************************/ +/* Return the Value's String value. */ +/***********************************************************************/ +PSZ JVALUE::GetText(PGLOBAL g, PSZ text) +{ + if (Jsp && Jsp->GetType() == TYPE_JOB) + return Jsp->GetText(g, text); + + char buf[32]; + PSZ s = (Value) ? Value->GetCharString(buf) : NULL; + + if (s) + strcat(strcat(text, " "), s); + else + strcat(text, " ???"); + + return text; +} // end of GetText + /***********************************************************************/ /* Set the Value's value as the given integer. */ /***********************************************************************/ @@ -1110,3 +1152,11 @@ void JVALUE::SetString(PGLOBAL g, PSZ s) Value = AllocateValue(g, s, TYPE_STRING); } // end of AddFloat +/***********************************************************************/ +/* True when its JSON or normal value is null. */ +/***********************************************************************/ +bool JVALUE::IsNull(void) +{ + return (Jsp) ? Jsp->IsNull() : (Value) ? Value->IsNull() : true; +} // end of IsNull + -- cgit v1.2.1