diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2017-07-18 13:16:55 +0200 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2017-07-18 13:16:55 +0200 |
commit | f590296c28ec54007692181e010d7064c1071ff2 (patch) | |
tree | 8ca5932a93f59bb60abfb0928ef483e96ed999d6 /storage/connect/json.cpp | |
parent | a9d32010d0ba36cc9b9d7fb58eeace687bb13f7a (diff) | |
download | mariadb-git-f590296c28ec54007692181e010d7064c1071ff2.tar.gz |
-- Finalize work on MongoDB access
Implement discovery for the MongoDB Java Driver
Create classes to minimize code and avoid dupicates
Rearrange and rename implied files
modified: storage/connect/CMakeLists.txt
renamed: storage/connect/mongofam.cpp -> storage/connect/cmgfam.cpp
renamed: storage/connect/mongofam.h -> storage/connect/cmgfam.h
modified: storage/connect/cmgoconn.h
modified: storage/connect/javaconn.h
modified: storage/connect/jdbconn.cpp
modified: storage/connect/jmgoconn.cpp
modified: storage/connect/jmgoconn.h
modified: storage/connect/mongo.cpp
modified: storage/connect/mongo.h
renamed: storage/connect/tabmgo.cpp -> storage/connect/tabcmg.cpp
renamed: storage/connect/tabmgo.h -> storage/connect/tabcmg.h
modified: storage/connect/tabjmg.cpp
modified: storage/connect/tabjmg.h
modified: storage/connect/tabjson.cpp
modified: storage/connect/tabjson.h
-- Trace Sarea allocation and freeing
modified: storage/connect/connect.cc
modified: storage/connect/plugutil.cpp
modified: storage/connect/user_connect.cc
-- Null Json values where not mark as null in JSNX::SetJsonValue
This was added in TYPE_NULL (declared as TYPE_VOID)
modified: storage/connect/json.cpp
modified: storage/connect/json.h
modified: storage/connect/jsonudf.cpp
-- Null JValues are ignored in JSNX::CalculateArray
Also done in tabjson.cpp for JSONCOL::CalculateArray
modified: storage/connect/json.h
modified: storage/connect/jsonudf.cpp
modified: storage/connect/tabjson.cpp
-- Null JSON values now represented by connect_json_null session variable
modified: storage/connect/json.cpp
modified: storage/connect/json.h
modified: storage/connect/jsonudf.cpp
modified: storage/connect/tabjson.cpp
-- JVALUE has size = 1
modified: storage/connect/json.h
-- Fix by vuvova because Debian compilation failure.
modified: storage/connect/value.cpp
Diffstat (limited to 'storage/connect/json.cpp')
-rw-r--r-- | storage/connect/json.cpp | 94 |
1 files changed, 79 insertions, 15 deletions
diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index 44758e7b0ad..da94d4e227c 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -1,5 +1,5 @@ /*************** json CPP Declares Source Code File (.H) ***************/ -/* Name: json.cpp Version 1.3 */ +/* Name: json.cpp Version 1.4 */ /* */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ /* */ @@ -53,6 +53,8 @@ void trans_func(unsigned int u, _EXCEPTION_POINTERS* pExp) char *GetExceptionDesc(PGLOBAL g, unsigned int e); #endif // SE_CATCH +char *GetJsonNull(void); + /***********************************************************************/ /* IsNum: check whether this string is all digits. */ /***********************************************************************/ @@ -537,7 +539,7 @@ PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src) if (!has_e) goto err; - // passthru + // fall through case '-': if (found_digit) goto err; @@ -827,7 +829,7 @@ bool JOUTSTR::Escape(const char *s) case '\r': case '\b': case '\f': WriteChr('\\'); - // passthru + // fall through default: WriteChr(s[i]); break; @@ -964,6 +966,25 @@ return false; /* -------------------------- Class JOBJECT -------------------------- */ /***********************************************************************/ +/* Return the number of pairs in this object. */ +/***********************************************************************/ +int JOBJECT::GetSize(bool b) +{ + if (b) { + // Return only non null pairs + int n = 0; + + for (PJPR jpp = First; jpp; jpp = jpp->Next) + if (jpp->Val && !jpp->Val->IsNull()) + n++; + + return n; + } else + return Size; + +} // end of GetSize + +/***********************************************************************/ /* Add a new pair to an Object. */ /***********************************************************************/ PJPR JOBJECT::AddPair(PGLOBAL g, PCSZ key) @@ -1046,7 +1067,7 @@ PSZ JOBJECT::GetText(PGLOBAL g, PSZ text) PlugSubAlloc(g, NULL, strlen(text) + 1); return text + n; -} // end of GetValue; +} // end of GetText; /***********************************************************************/ /* Merge two objects. */ @@ -1087,7 +1108,7 @@ void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PCSZ key) } // end of SetValue /***********************************************************************/ -/* Delete a value corresponding to the given key. */ +/* Delete a value corresponding to the given key. */ /***********************************************************************/ void JOBJECT::DeleteKey(PCSZ key) { @@ -1118,6 +1139,25 @@ bool JOBJECT::IsNull(void) /* -------------------------- Class JARRAY --------------------------- */ /***********************************************************************/ +/* Return the number of values in this object. */ +/***********************************************************************/ +int JARRAY::GetSize(bool b) +{ + if (b) { + // Return only non null values + int n = 0; + + for (PJVAL jvp = First; jvp; jvp = jvp->Next) + if (!jvp->IsNull()) + n++; + + return n; + } else + return Size; + +} // end of GetSize + +/***********************************************************************/ /* Make the array of values from the values list. */ /***********************************************************************/ void JARRAY::InitArray(PGLOBAL g) @@ -1226,17 +1266,41 @@ bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n) } // end of SetValue /***********************************************************************/ +/* Return the text corresponding to all values. */ +/***********************************************************************/ +PSZ JARRAY::GetText(PGLOBAL g, PSZ text) +{ + int n; + PJVAL jp; + + if (!text) { + text = (char*)PlugSubAlloc(g, NULL, 0); + text[0] = 0; + n = 1; + } else + n = 0; + + for (jp = First; jp; jp = jp->Next) + jp->GetText(g, text); + + if (n) + PlugSubAlloc(g, NULL, strlen(text) + 1); + + return text + n; +} // end of GetText; + +/***********************************************************************/ /* Delete a Value from the Arrays Value list. */ /***********************************************************************/ bool JARRAY::DeleteValue(int n) { - PJVAL jvp = GetValue(n); + PJVAL jvp = GetValue(n); - if (jvp) { - jvp->Del = true; - return false; - } else - return true; + if (jvp) { + jvp->Del = true; + return false; + } else + return true; } // end of DeleteValue @@ -1286,7 +1350,7 @@ JTYP JVALUE::GetValType(void) else if (Value) return (JTYP)Value->GetType(); else - return (JTYP)TYPE_VOID; + return TYPE_NULL; } // end of GetValType @@ -1350,7 +1414,7 @@ PSZ JVALUE::GetString(void) /***********************************************************************/ PSZ JVALUE::GetText(PGLOBAL g, PSZ text) { - if (Jsp && Jsp->GetType() == TYPE_JOB) + if (Jsp) return Jsp->GetText(g, text); char buf[32]; @@ -1358,8 +1422,8 @@ PSZ JVALUE::GetText(PGLOBAL g, PSZ text) if (s) strcat(strcat(text, " "), s); - else - strcat(text, " <null>"); + else if (GetJsonNull()) + strcat(strcat(text, " "), GetJsonNull()); return text; } // end of GetText |