Skip to content

Commit

Permalink
- Make user variable prefix recognized by IsArgJson and IsJson
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
Buggynours committed Jul 24, 2021
1 parent 1c4b917 commit 0f18135
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 61 deletions.
19 changes: 13 additions & 6 deletions storage/connect/bsonudf.cpp
Expand Up @@ -1889,24 +1889,31 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n)
/*********************************************************************************/
int IsArgJson(UDF_ARGS *args, uint i)
{
int n = 0;
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]) {
Expand Down
26 changes: 24 additions & 2 deletions storage/connect/json.cpp
@@ -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. */
/***********************************************************************/
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions storage/connect/json.h
Expand Up @@ -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. */
Expand Down
17 changes: 13 additions & 4 deletions storage/connect/jsonudf.cpp
Expand Up @@ -1524,22 +1524,31 @@ static int *GetIntArgPtr(PGLOBAL g, UDF_ARGS *args, uint& n)
/*********************************************************************************/
int IsJson(UDF_ARGS *args, uint i, bool b)
{
int n = 0;
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;
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/mongo.h
Expand Up @@ -82,7 +82,7 @@ class DllExport MGODEF : public EXTDEF { /* Table description */
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 */
Expand Down
5 changes: 3 additions & 2 deletions storage/connect/tabbson.cpp
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion storage/connect/tabcmg.cpp
Expand Up @@ -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 -------------------------- */

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/tabcmg.h
Expand Up @@ -75,7 +75,7 @@ class DllExport TDBCMG : public TDBEXT {
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
Expand Down
3 changes: 3 additions & 0 deletions storage/connect/tabjdbc.cpp
Expand Up @@ -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);

Expand Down
15 changes: 10 additions & 5 deletions storage/connect/tabjmg.cpp
Expand Up @@ -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 -------------------------- */

Expand Down Expand Up @@ -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 (Jpath[n - 1] == '.') n--;
Jpath[n] = 0;

if (--n) {
if (Jpath[n - 1] == '.') n--;
Jpath[n] = 0;
} // endif n

Sgfy = true;
} // endif Jpath

Expand Down
2 changes: 1 addition & 1 deletion storage/connect/tabjmg.h
Expand Up @@ -83,7 +83,7 @@ class DllExport TDBJMG : public TDBEXT {
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
Expand Down
5 changes: 3 additions & 2 deletions storage/connect/tabjson.cpp
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0f18135

Please sign in to comment.