mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Make user variable prefix recognized by IsArgJson and IsJson
modified: storage/connect/bsonudf.cpp modified: storage/connect/jsonudf.cpp - Stringify option is now a ; separated list of columns modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/mongo.h modified: storage/connect/tabbson.cpp modified: storage/connect/tabcmg.cpp modified: storage/connect/tabcmg.h modified: storage/connect/tabjmg.cpp modified: storage/connect/tabjmg.h modified: storage/connect/tabjson.cpp - PrepareColist not a static function anymore (+ typo) modified: storage/connect/taboccur.cpp - JDVC: Recognize schema (database) from a wrapper server modified: storage/connect/tabjdbc.cpp
This commit is contained in:
@@ -1889,24 +1889,31 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n)
|
||||
/*********************************************************************************/
|
||||
int IsArgJson(UDF_ARGS *args, uint i)
|
||||
{
|
||||
char *pat = args->attributes[i];
|
||||
int n = 0;
|
||||
|
||||
if (*pat == '@') {
|
||||
pat++;
|
||||
|
||||
if (*pat == '\'' || *pat == '"')
|
||||
pat++;
|
||||
|
||||
} // endif pat
|
||||
|
||||
if (i >= args->arg_count || args->arg_type[i] != STRING_RESULT) {
|
||||
} else if (!strnicmp(args->attributes[i], "Bson_", 5) ||
|
||||
!strnicmp(args->attributes[i], "Json_", 5)) {
|
||||
} else if (!strnicmp(pat, "Bson_", 5) || !strnicmp(pat, "Json_", 5)) {
|
||||
if (!args->args[i] || strchr("[{ \t\r\n", *args->args[i]))
|
||||
n = 1; // arg should be is a json item
|
||||
// else
|
||||
// n = 2; // A file name may have been returned
|
||||
|
||||
} else if (!strnicmp(args->attributes[i], "Bbin_", 5)) {
|
||||
} else if (!strnicmp(pat, "Bbin_", 5)) {
|
||||
if (args->lengths[i] == sizeof(BSON))
|
||||
n = 3; // arg is a binary json item
|
||||
// else
|
||||
// n = 2; // A file name may have been returned
|
||||
|
||||
} else if (!strnicmp(args->attributes[i], "Bfile_", 6) ||
|
||||
!strnicmp(args->attributes[i], "Jfile_", 6)) {
|
||||
} else if (!strnicmp(pat, "Bfile_", 6) || !strnicmp(pat, "Jfile_", 6)) {
|
||||
n = 2; // arg is a json file name
|
||||
#if 0
|
||||
} else if (args->lengths[i]) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*************** json CPP Declares Source Code File (.H) ***************/
|
||||
/* Name: json.cpp Version 1.5 */
|
||||
/* Name: json.cpp Version 1.6 */
|
||||
/* */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2020 */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2021 */
|
||||
/* */
|
||||
/* This file contains the JSON classes functions. */
|
||||
/***********************************************************************/
|
||||
@@ -55,6 +55,7 @@ char *GetExceptionDesc(PGLOBAL g, unsigned int e);
|
||||
|
||||
char *GetJsonNull(void);
|
||||
int GetDefaultPrec(void);
|
||||
int PrepareColist(char*);
|
||||
|
||||
/***********************************************************************/
|
||||
/* IsNum: check whether this string is all digits. */
|
||||
@@ -111,6 +112,27 @@ char* NextChr(PSZ s, char sep)
|
||||
return p2;
|
||||
} // end of NextChr
|
||||
|
||||
/***********************************************************************/
|
||||
/* Stringified: check that this column is in the stringified list. */
|
||||
/***********************************************************************/
|
||||
bool Stringified(PCSZ strfy, char *colname)
|
||||
{
|
||||
if (strfy) {
|
||||
char *p, colist[512];
|
||||
int n;
|
||||
|
||||
strncpy(colist, strfy, sizeof(colist) - 1);
|
||||
n = PrepareColist(colist);
|
||||
|
||||
for (p = colist; n && p; p += (strlen(p) + 1), n--)
|
||||
if (!stricmp(p, colname))
|
||||
return true;
|
||||
|
||||
} // endif strfy
|
||||
|
||||
return false;
|
||||
} // end of Stringified
|
||||
|
||||
#if 0
|
||||
/***********************************************************************/
|
||||
/* Allocate a VAL structure, make sure common field and Nd are zeroed. */
|
||||
|
@@ -67,6 +67,7 @@ PJSON ParseJson(PGLOBAL g, char* s, size_t n, int* prty = NULL, bool* b = NULL);
|
||||
PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty);
|
||||
DllExport bool IsNum(PSZ s);
|
||||
bool IsArray(PSZ s);
|
||||
bool Stringified(PCSZ strfy, char *colname);
|
||||
|
||||
/***********************************************************************/
|
||||
/* Class JDOC. The class for parsing and serializing json documents. */
|
||||
|
@@ -1524,22 +1524,31 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n)
|
||||
/*********************************************************************************/
|
||||
int IsJson(UDF_ARGS *args, uint i, bool b)
|
||||
{
|
||||
char *pat = args->attributes[i];
|
||||
int n = 0;
|
||||
|
||||
if (*pat == '@') {
|
||||
pat++;
|
||||
|
||||
if (*pat == '\'' || *pat == '"')
|
||||
pat++;
|
||||
|
||||
} // endif pat
|
||||
|
||||
if (i >= args->arg_count || args->arg_type[i] != STRING_RESULT) {
|
||||
} else if (!strnicmp(args->attributes[i], "Json_", 5)) {
|
||||
} else if (!strnicmp(pat, "Json_", 5)) {
|
||||
if (!args->args[i] || strchr("[{ \t\r\n", *args->args[i]))
|
||||
n = 1; // arg should be is a json item
|
||||
else
|
||||
n = 2; // A file name may have been returned
|
||||
|
||||
} else if (!strnicmp(args->attributes[i], "Jbin_", 5)) {
|
||||
} else if (!strnicmp(pat, "Jbin_", 5)) {
|
||||
if (args->lengths[i] == sizeof(BSON))
|
||||
n = 3; // arg is a binary json item
|
||||
else
|
||||
n = 2; // A file name may have been returned
|
||||
|
||||
} else if (!strnicmp(args->attributes[i], "Jfile_", 6)) {
|
||||
} else if (!strnicmp(pat, "Jfile_", 6)) {
|
||||
n = 2; // arg is a json file name
|
||||
} else if (b) {
|
||||
char *sap;
|
||||
|
@@ -82,7 +82,7 @@ protected:
|
||||
PSZ Wrapname; /* Java wrapper name */
|
||||
PCSZ Colist; /* Options list */
|
||||
PCSZ Filter; /* Filtering query */
|
||||
PCSZ Strfy; /* Stringify column */
|
||||
PCSZ Strfy; /* The stringify columns */
|
||||
int Base; /* The array index base */
|
||||
int Version; /* The Java driver version */
|
||||
bool Pipe; /* True is Colist is a pipeline */
|
||||
|
@@ -53,6 +53,7 @@ USETEMP UseTemp(void);
|
||||
bool JsonAllPath(void);
|
||||
int GetDefaultDepth(void);
|
||||
char *GetJsonNull(void);
|
||||
bool Stringified(PCSZ, char*);
|
||||
|
||||
/***********************************************************************/
|
||||
/* BSONColumns: construct the result blocks containing the description */
|
||||
@@ -436,7 +437,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
|
||||
jcol.Type = TYPE_UNKNOWN;
|
||||
jcol.Len = jcol.Scale = 0;
|
||||
jcol.Cbn = true;
|
||||
} else if (j < lvl && !(strfy && !stricmp(strfy, colname))) {
|
||||
} else if (j < lvl && !Stringified(strfy, colname)) {
|
||||
if (!fmt[bf])
|
||||
strcat(fmt, colname);
|
||||
|
||||
@@ -507,7 +508,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
|
||||
} // endswitch Type
|
||||
|
||||
} else if (lvl >= 0) {
|
||||
if (strfy && !stricmp(strfy, colname)) {
|
||||
if (Stringified(strfy, colname)) {
|
||||
if (!fmt[bf])
|
||||
strcat(fmt, colname);
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "filter.h"
|
||||
|
||||
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info);
|
||||
bool Stringified(PCSZ, char*);
|
||||
|
||||
/* -------------------------- Class CMGDISC -------------------------- */
|
||||
|
||||
@@ -397,7 +398,7 @@ MGOCOL::MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
|
||||
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
|
||||
{
|
||||
Tmgp = (PTDBCMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
|
||||
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));
|
||||
Sgfy = Stringified(Tmgp->Strfy, Name);
|
||||
|
||||
if ((Jpath = cdp->GetFmt())) {
|
||||
int n = strlen(Jpath) - 1;
|
||||
|
@@ -75,7 +75,7 @@ protected:
|
||||
CMgoConn *Cmgp; // Points to a C Mongo connection class
|
||||
CMGOPARM Pcg; // Parms passed to Cmgp
|
||||
const Item *Cnd; // The first condition
|
||||
PCSZ Strfy; // The stringified column
|
||||
PCSZ Strfy; // The stringified columns
|
||||
int Fpos; // The current row index
|
||||
int N; // The current Rownum
|
||||
int B; // Array index base
|
||||
|
@@ -188,6 +188,9 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
|
||||
} else // host is a URL
|
||||
Url = PlugDup(g, server->host);
|
||||
|
||||
if (!Tabschema && server->db)
|
||||
Tabschema = PlugDup(g, server->db);
|
||||
|
||||
if (!Username && server->username)
|
||||
Username = PlugDup(g, server->username);
|
||||
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#define nullptr 0
|
||||
|
||||
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info);
|
||||
bool Stringified(PCSZ, char*);
|
||||
|
||||
/* -------------------------- Class JMGDISC -------------------------- */
|
||||
|
||||
@@ -423,15 +424,19 @@ JMGCOL::JMGCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i)
|
||||
: EXTCOL(cdp, tdbp, cprec, i, "MGO")
|
||||
{
|
||||
Tmgp = (PTDBJMG)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp);
|
||||
Sgfy = (Tmgp->Strfy && !stricmp(Tmgp->Strfy, Name));
|
||||
Sgfy = Stringified(Tmgp->Strfy, Name);
|
||||
|
||||
if ((Jpath = cdp->GetFmt())) {
|
||||
int n = strlen(Jpath) - 1;
|
||||
int n = strlen(Jpath);
|
||||
|
||||
if (Jpath[n] == '*') {
|
||||
if (n && Jpath[n - 1] == '*') {
|
||||
Jpath = PlugDup(g, cdp->GetFmt());
|
||||
|
||||
if (--n) {
|
||||
if (Jpath[n - 1] == '.') n--;
|
||||
Jpath[n] = 0;
|
||||
} // endif n
|
||||
|
||||
Sgfy = true;
|
||||
} // endif Jpath
|
||||
|
||||
|
@@ -83,7 +83,7 @@ protected:
|
||||
PCSZ Coll_name;
|
||||
PCSZ Options; // The MongoDB options
|
||||
PCSZ Filter; // The filtering query
|
||||
PCSZ Strfy; // The stringified column
|
||||
PCSZ Strfy; // The stringified columns
|
||||
PSZ Wrapname; // Java wrapper name
|
||||
int Fpos; // The current row index
|
||||
int N; // The current Rownum
|
||||
|
@@ -58,6 +58,7 @@ USETEMP UseTemp(void);
|
||||
bool JsonAllPath(void);
|
||||
int GetDefaultDepth(void);
|
||||
char *GetJsonNull(void);
|
||||
bool Stringified(PCSZ, char*);
|
||||
|
||||
/***********************************************************************/
|
||||
/* JSONColumns: construct the result blocks containing the description */
|
||||
@@ -447,7 +448,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
|
||||
jcol.Type = TYPE_UNKNOWN;
|
||||
jcol.Len = jcol.Scale = 0;
|
||||
jcol.Cbn = true;
|
||||
} else if (j < lvl && !(strfy && !stricmp(strfy, colname))) {
|
||||
} else if (j < lvl && !Stringified(strfy, colname)) {
|
||||
if (!fmt[bf])
|
||||
strcat(fmt, colname);
|
||||
|
||||
@@ -517,7 +518,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
|
||||
} // endswitch Type
|
||||
|
||||
} else if (lvl >= 0) {
|
||||
if (strfy && !stricmp(strfy, colname)) {
|
||||
if (Stringified(strfy, colname)) {
|
||||
if (!fmt[bf])
|
||||
strcat(fmt, colname);
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/************ TabOccur CPP Declares Source Code File (.CPP) ************/
|
||||
/* Name: TABOCCUR.CPP Version 1.2 */
|
||||
/* */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2013 - 2017 */
|
||||
/* (C) Copyright to the author Olivier BERTRAND 2013 - 2021 */
|
||||
/* */
|
||||
/* OCCUR: Table that provides a view of a source table where the */
|
||||
/* contain of several columns of the source table is placed in only */
|
||||
@@ -52,7 +52,7 @@
|
||||
/***********************************************************************/
|
||||
/* Prepare and count columns in the column list. */
|
||||
/***********************************************************************/
|
||||
static int PrepareColist(char *colist)
|
||||
int PrepareColist(char *colist)
|
||||
{
|
||||
char *p, *pn;
|
||||
int n = 0;
|
||||
|
Reference in New Issue
Block a user