mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- All this concern Json or Mongo tables based on MongoDB collections.
- Limit decimals of doubles printed from MongoDB Done in function Mini for Mongo C Driver and Java Driver Done in function SerializeValue for Java tables using the J Driver modified: storage/connect/cmgoconn.cpp modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/tabjmg.cpp - Fix crash when using BSON_TYPE_DECIMAL128 modified: storage/connect/cmgoconn.cpp - Collection name default to table name Fix it when creating tables via discovery modified: storage/connect/ha_connect.cc modified: storage/connect/tabbson.cpp modified: storage/connect/tabjson.cpp
This commit is contained in:
@@ -26,6 +26,7 @@ bool CMgoConn::IsInit = false;
|
||||
|
||||
bool IsArray(PSZ s);
|
||||
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
|
||||
int GetDefaultPrec(void);
|
||||
|
||||
/* --------------------------- Class INCOL --------------------------- */
|
||||
|
||||
@@ -563,7 +564,7 @@ void CMgoConn::ShowDocument(bson_iter_t *iter, const bson_t *doc, const char *k)
|
||||
htrc("%s.%s=%s\n", k, key, str);
|
||||
} break;
|
||||
case BSON_TYPE_DECIMAL128: {
|
||||
char* str = NULL;
|
||||
char str[BSON_DECIMAL128_STRING];
|
||||
bson_decimal128_t dec;
|
||||
|
||||
bson_iter_decimal128(iter, &dec);
|
||||
@@ -807,21 +808,49 @@ char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
|
||||
{
|
||||
char *s, *str = NULL;
|
||||
char *Mbuf = (char*)PlugSubAlloc(g, NULL, (size_t)colp->GetLength() + 1);
|
||||
int i, k = 0;
|
||||
bool ok = true;
|
||||
int i, j = 0, k = 0, n = 0, m = GetDefaultPrec();
|
||||
bool ok = true, dbl = false;
|
||||
double d;
|
||||
size_t len;
|
||||
|
||||
if (b)
|
||||
s = str = bson_array_as_json(bson, NULL);
|
||||
s = str = bson_array_as_json(bson, &len);
|
||||
else
|
||||
s = str = bson_as_json(bson, NULL);
|
||||
s = str = bson_as_json(bson, &len);
|
||||
|
||||
if (len > (size_t)colp->GetLength()) {
|
||||
sprintf(g->Message, "Value too long for column %s", colp->GetName());
|
||||
bson_free(str);
|
||||
throw (int)TYPE_AM_MGO;
|
||||
} // endif len
|
||||
|
||||
for (i = 0; i < colp->GetLength() && s[i]; i++) {
|
||||
switch (s[i]) {
|
||||
case ' ':
|
||||
if (ok) continue;
|
||||
break;
|
||||
case '"':
|
||||
ok = !ok;
|
||||
break;
|
||||
case '.':
|
||||
if (j) dbl = true;
|
||||
break;
|
||||
default:
|
||||
if (ok) {
|
||||
if (isdigit(s[i])) {
|
||||
if (!j) j = k;
|
||||
if (dbl) n++;
|
||||
} else if (dbl && n > m) {
|
||||
Mbuf[k] = 0;
|
||||
d = atof(Mbuf + j);
|
||||
n = sprintf(Mbuf + j, "%.*f", m, d);
|
||||
k = j + n;
|
||||
j = n = 0;
|
||||
} else if (j)
|
||||
j = n = 0;
|
||||
|
||||
} // endif ok
|
||||
|
||||
break;
|
||||
} // endswitch s[i]
|
||||
|
||||
@@ -830,11 +859,6 @@ char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
|
||||
|
||||
bson_free(str);
|
||||
|
||||
if (i >= colp->GetLength()) {
|
||||
sprintf(g->Message, "Value too long for column %s", colp->GetName());
|
||||
throw (int)TYPE_AM_MGO;
|
||||
} // endif i
|
||||
|
||||
Mbuf[k] = 0;
|
||||
return Mbuf;
|
||||
} // end of Mini
|
||||
@@ -926,13 +950,13 @@ void CMgoConn::GetColumnValue(PGLOBAL g, PCOL colp)
|
||||
value->SetNull(true);
|
||||
break;
|
||||
case BSON_TYPE_DECIMAL128: {
|
||||
char* str = NULL;
|
||||
char str[BSON_DECIMAL128_STRING];
|
||||
bson_decimal128_t dec;
|
||||
|
||||
bson_iter_decimal128(&Desc, &dec);
|
||||
bson_decimal128_to_string(&dec, str);
|
||||
value->SetValue_psz(str);
|
||||
bson_free(str);
|
||||
// bson_free(str);
|
||||
} break;
|
||||
default:
|
||||
value->Reset();
|
||||
@@ -956,10 +980,10 @@ bool CMgoConn::AddValue(PGLOBAL g, PCOL colp, bson_t *doc, char *key, bool upd)
|
||||
PVAL value = colp->GetValue();
|
||||
|
||||
if (value->IsNull()) {
|
||||
if (upd)
|
||||
// if (upd)
|
||||
rc = BSON_APPEND_NULL(doc, key);
|
||||
else
|
||||
return false;
|
||||
// else
|
||||
// return false;
|
||||
|
||||
} else switch (colp->GetResultType()) {
|
||||
case TYPE_STRING:
|
||||
|
@@ -170,7 +170,7 @@
|
||||
#define JSONMAX 10 // JSON Default max grp size
|
||||
|
||||
extern "C" {
|
||||
char version[]= "Version 1.07.0003 April 02, 2021";
|
||||
char version[]= "Version 1.07.0003 May 02, 2021";
|
||||
#if defined(__WIN__)
|
||||
char compver[]= "Version 1.07.0003 " __DATE__ " " __TIME__;
|
||||
char slash= '\\';
|
||||
@@ -5940,9 +5940,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
|
||||
|
||||
if (!fn && !zfn && !mul && !dsn)
|
||||
sprintf(g->Message, "Missing %s file name", topt->type);
|
||||
else
|
||||
ok= true;
|
||||
else if (dsn && !topt->tabname)
|
||||
topt->tabname= tab;
|
||||
|
||||
ok= true;
|
||||
break;
|
||||
#if defined(JAVA_SUPPORT)
|
||||
case TAB_MONGO:
|
||||
|
@@ -245,6 +245,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char* fn, int pretty) {
|
||||
|
||||
try {
|
||||
jdp = new(g) JDOC; // MUST BE ALLOCATED BEFORE jp !!!!!
|
||||
jdp->dfp = GetDefaultPrec();
|
||||
|
||||
if (!jsp) {
|
||||
strcpy(g->Message, "Null json tree");
|
||||
@@ -1005,8 +1006,8 @@ bool JDOC::SerializeValue(PJVAL jvp)
|
||||
case TYPE_BINT:
|
||||
sprintf(buf, "%lld", jvp->LLn);
|
||||
return js->WriteStr(buf);
|
||||
case TYPE_DBL:
|
||||
sprintf(buf, "%.*lf", jvp->Nd, jvp->F);
|
||||
case TYPE_DBL: // dfp to limit to the default number of decimals
|
||||
sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
|
||||
return js->WriteStr(buf);
|
||||
case TYPE_NULL:
|
||||
return js->WriteStr("null");
|
||||
|
@@ -75,7 +75,7 @@ class JDOC: public BLOCK {
|
||||
friend PJSON ParseJson(PGLOBAL, char*, size_t, int*, bool*);
|
||||
friend PSZ Serialize(PGLOBAL, PJSON, char*, int);
|
||||
public:
|
||||
JDOC(void) : js(NULL), s(NULL), len(0), pty(NULL) {}
|
||||
JDOC(void) : js(NULL), s(NULL), len(0), dfp(0), pty(NULL) {}
|
||||
|
||||
void SetJp(JOUT* jp) { js = jp; }
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
private:
|
||||
JOUT* js;
|
||||
char *s;
|
||||
int len;
|
||||
int len, dfp;
|
||||
bool *pty;
|
||||
}; // end of class JDOC
|
||||
|
||||
|
@@ -218,8 +218,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
|
||||
|
||||
if (tdp->Uri) {
|
||||
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
|
||||
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
||||
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
||||
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
|
||||
|
@@ -505,6 +505,7 @@ char *JMGCOL::Mini(PGLOBAL g, const bson_t *bson, bool b)
|
||||
switch (s[i]) {
|
||||
case ' ':
|
||||
if (ok) continue;
|
||||
break;
|
||||
case '"':
|
||||
ok = !ok;
|
||||
default:
|
||||
|
@@ -222,8 +222,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
|
||||
|
||||
if (tdp->Uri) {
|
||||
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
|
||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
|
||||
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
||||
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
||||
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
|
||||
|
Reference in New Issue
Block a user