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 IsArray(PSZ s);
|
||||||
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
|
bool MakeSelector(PGLOBAL g, PFIL fp, PSTRG s);
|
||||||
|
int GetDefaultPrec(void);
|
||||||
|
|
||||||
/* --------------------------- Class INCOL --------------------------- */
|
/* --------------------------- 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);
|
htrc("%s.%s=%s\n", k, key, str);
|
||||||
} break;
|
} break;
|
||||||
case BSON_TYPE_DECIMAL128: {
|
case BSON_TYPE_DECIMAL128: {
|
||||||
char* str = NULL;
|
char str[BSON_DECIMAL128_STRING];
|
||||||
bson_decimal128_t dec;
|
bson_decimal128_t dec;
|
||||||
|
|
||||||
bson_iter_decimal128(iter, &dec);
|
bson_iter_decimal128(iter, &dec);
|
||||||
@@ -805,23 +806,51 @@ void CMgoConn::Close(void)
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
|
char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
|
||||||
{
|
{
|
||||||
char *s, *str = NULL;
|
char *s, *str = NULL;
|
||||||
char *Mbuf = (char*)PlugSubAlloc(g, NULL, (size_t)colp->GetLength() + 1);
|
char *Mbuf = (char*)PlugSubAlloc(g, NULL, (size_t)colp->GetLength() + 1);
|
||||||
int i, k = 0;
|
int i, j = 0, k = 0, n = 0, m = GetDefaultPrec();
|
||||||
bool ok = true;
|
bool ok = true, dbl = false;
|
||||||
|
double d;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (b)
|
if (b)
|
||||||
s = str = bson_array_as_json(bson, NULL);
|
s = str = bson_array_as_json(bson, &len);
|
||||||
else
|
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++) {
|
for (i = 0; i < colp->GetLength() && s[i]; i++) {
|
||||||
switch (s[i]) {
|
switch (s[i]) {
|
||||||
case ' ':
|
case ' ':
|
||||||
if (ok) continue;
|
if (ok) continue;
|
||||||
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
ok = !ok;
|
ok = !ok;
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
if (j) dbl = true;
|
||||||
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
} // endswitch s[i]
|
} // endswitch s[i]
|
||||||
|
|
||||||
@@ -830,11 +859,6 @@ char *CMgoConn::Mini(PGLOBAL g, PCOL colp, const bson_t *bson, bool b)
|
|||||||
|
|
||||||
bson_free(str);
|
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;
|
Mbuf[k] = 0;
|
||||||
return Mbuf;
|
return Mbuf;
|
||||||
} // end of Mini
|
} // end of Mini
|
||||||
@@ -926,13 +950,13 @@ void CMgoConn::GetColumnValue(PGLOBAL g, PCOL colp)
|
|||||||
value->SetNull(true);
|
value->SetNull(true);
|
||||||
break;
|
break;
|
||||||
case BSON_TYPE_DECIMAL128: {
|
case BSON_TYPE_DECIMAL128: {
|
||||||
char* str = NULL;
|
char str[BSON_DECIMAL128_STRING];
|
||||||
bson_decimal128_t dec;
|
bson_decimal128_t dec;
|
||||||
|
|
||||||
bson_iter_decimal128(&Desc, &dec);
|
bson_iter_decimal128(&Desc, &dec);
|
||||||
bson_decimal128_to_string(&dec, str);
|
bson_decimal128_to_string(&dec, str);
|
||||||
value->SetValue_psz(str);
|
value->SetValue_psz(str);
|
||||||
bson_free(str);
|
// bson_free(str);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
value->Reset();
|
value->Reset();
|
||||||
@@ -956,10 +980,10 @@ bool CMgoConn::AddValue(PGLOBAL g, PCOL colp, bson_t *doc, char *key, bool upd)
|
|||||||
PVAL value = colp->GetValue();
|
PVAL value = colp->GetValue();
|
||||||
|
|
||||||
if (value->IsNull()) {
|
if (value->IsNull()) {
|
||||||
if (upd)
|
// if (upd)
|
||||||
rc = BSON_APPEND_NULL(doc, key);
|
rc = BSON_APPEND_NULL(doc, key);
|
||||||
else
|
// else
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
} else switch (colp->GetResultType()) {
|
} else switch (colp->GetResultType()) {
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
|
@@ -170,7 +170,7 @@
|
|||||||
#define JSONMAX 10 // JSON Default max grp size
|
#define JSONMAX 10 // JSON Default max grp size
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
char version[]= "Version 1.07.0003 April 02, 2021";
|
char version[]= "Version 1.07.0003 May 02, 2021";
|
||||||
#if defined(__WIN__)
|
#if defined(__WIN__)
|
||||||
char compver[]= "Version 1.07.0003 " __DATE__ " " __TIME__;
|
char compver[]= "Version 1.07.0003 " __DATE__ " " __TIME__;
|
||||||
char slash= '\\';
|
char slash= '\\';
|
||||||
@@ -5940,9 +5940,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
|
|||||||
|
|
||||||
if (!fn && !zfn && !mul && !dsn)
|
if (!fn && !zfn && !mul && !dsn)
|
||||||
sprintf(g->Message, "Missing %s file name", topt->type);
|
sprintf(g->Message, "Missing %s file name", topt->type);
|
||||||
else
|
else if (dsn && !topt->tabname)
|
||||||
ok= true;
|
topt->tabname= tab;
|
||||||
|
|
||||||
|
ok= true;
|
||||||
break;
|
break;
|
||||||
#if defined(JAVA_SUPPORT)
|
#if defined(JAVA_SUPPORT)
|
||||||
case TAB_MONGO:
|
case TAB_MONGO:
|
||||||
|
@@ -245,6 +245,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char* fn, int pretty) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
jdp = new(g) JDOC; // MUST BE ALLOCATED BEFORE jp !!!!!
|
jdp = new(g) JDOC; // MUST BE ALLOCATED BEFORE jp !!!!!
|
||||||
|
jdp->dfp = GetDefaultPrec();
|
||||||
|
|
||||||
if (!jsp) {
|
if (!jsp) {
|
||||||
strcpy(g->Message, "Null json tree");
|
strcpy(g->Message, "Null json tree");
|
||||||
@@ -1005,8 +1006,8 @@ bool JDOC::SerializeValue(PJVAL jvp)
|
|||||||
case TYPE_BINT:
|
case TYPE_BINT:
|
||||||
sprintf(buf, "%lld", jvp->LLn);
|
sprintf(buf, "%lld", jvp->LLn);
|
||||||
return js->WriteStr(buf);
|
return js->WriteStr(buf);
|
||||||
case TYPE_DBL:
|
case TYPE_DBL: // dfp to limit to the default number of decimals
|
||||||
sprintf(buf, "%.*lf", jvp->Nd, jvp->F);
|
sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
|
||||||
return js->WriteStr(buf);
|
return js->WriteStr(buf);
|
||||||
case TYPE_NULL:
|
case TYPE_NULL:
|
||||||
return js->WriteStr("null");
|
return js->WriteStr("null");
|
||||||
|
@@ -75,7 +75,7 @@ class JDOC: public BLOCK {
|
|||||||
friend PJSON ParseJson(PGLOBAL, char*, size_t, int*, bool*);
|
friend PJSON ParseJson(PGLOBAL, char*, size_t, int*, bool*);
|
||||||
friend PSZ Serialize(PGLOBAL, PJSON, char*, int);
|
friend PSZ Serialize(PGLOBAL, PJSON, char*, int);
|
||||||
public:
|
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; }
|
void SetJp(JOUT* jp) { js = jp; }
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
JOUT* js;
|
JOUT* js;
|
||||||
char *s;
|
char *s;
|
||||||
int len;
|
int len, dfp;
|
||||||
bool *pty;
|
bool *pty;
|
||||||
}; // end of class JDOC
|
}; // end of class JDOC
|
||||||
|
|
||||||
|
@@ -218,8 +218,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
|
|||||||
|
|
||||||
if (tdp->Uri) {
|
if (tdp->Uri) {
|
||||||
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
||||||
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
|
tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
|
||||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
|
|
||||||
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
||||||
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
||||||
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
|
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]) {
|
switch (s[i]) {
|
||||||
case ' ':
|
case ' ':
|
||||||
if (ok) continue;
|
if (ok) continue;
|
||||||
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
ok = !ok;
|
ok = !ok;
|
||||||
default:
|
default:
|
||||||
|
@@ -222,8 +222,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
|
|||||||
|
|
||||||
if (tdp->Uri) {
|
if (tdp->Uri) {
|
||||||
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
||||||
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
|
tdp->Collname = GetStringTableOption(g, topt, "Tabname", NULL);
|
||||||
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
|
|
||||||
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
|
||||||
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
|
||||||
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
|
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
|
||||||
|
Reference in New Issue
Block a user