Commit e3b3e225 authored by Olivier Bertrand's avatar Olivier Bertrand

Merge branch 'ob-10.1' into 10.1

parents faa1d149 261e9a8a
...@@ -23,7 +23,7 @@ id msg ...@@ -23,7 +23,7 @@ id msg
CREATE TABLE xt3 ( CREATE TABLE xt3 (
id INT KEY NOT NULL, id INT KEY NOT NULL,
msg VARCHAR(32)) msg VARCHAR(32))
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=10; ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
Warnings: Warnings:
Warning 1105 No file name. Table will use xt3.csv Warning 1105 No file name. Table will use xt3.csv
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
...@@ -92,7 +92,7 @@ id msg ...@@ -92,7 +92,7 @@ id msg
EXPLAIN PARTITIONS EXPLAIN PARTITIONS
SELECT * FROM t1 WHERE id = 81; SELECT * FROM t1 WHERE id = 81;
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 3 ALL NULL NULL NULL NULL 4 Using where 1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where
DELETE FROM t1; DELETE FROM t1;
Warnings: Warnings:
Note 1105 xt1: 4 affected rows Note 1105 xt1: 4 affected rows
......
...@@ -22,7 +22,7 @@ SELECT * FROM xt2; ...@@ -22,7 +22,7 @@ SELECT * FROM xt2;
CREATE TABLE xt3 ( CREATE TABLE xt3 (
id INT KEY NOT NULL, id INT KEY NOT NULL,
msg VARCHAR(32)) msg VARCHAR(32))
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=10; ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
SELECT * FROM xt3; SELECT * FROM xt3;
......
/************* tabjson C++ Program Source Code File (.CPP) *************/ /************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.5 */ /* PROGRAM NAME: tabjson Version 1.6 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */
/* This program are the JSON class DB execution routines. */ /* This program are the JSON class DB execution routines. */
/***********************************************************************/ /***********************************************************************/
...@@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg) ...@@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg)
int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
{ {
char filename[_MAX_PATH];
bool mgo = (GetTypeID(topt->type) == TAB_MONGO); bool mgo = (GetTypeID(topt->type) == TAB_MONGO);
PCSZ level = GetStringTableOption(g, topt, "Level", NULL); PCSZ level = GetStringTableOption(g, topt, "Level", NULL);
...@@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
return 0; return 0;
} // endif Fn } // endif Fn
if (tdp->Fn) {
// We used the file name relative to recorded datapath
PlugSetPath(filename, tdp->Fn, tdp->GetPath());
tdp->Fn = PlugDup(g, filename);
} // endif Fn
if (trace(1)) if (trace(1))
htrc("File %s objname=%s pretty=%d lvl=%d\n", htrc("File %s objname=%s pretty=%d lvl=%d\n",
tdp->Fn, tdp->Objname, tdp->Pretty, lvl); tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
...@@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
strncpy(colname, jpp->GetKey(), 64); strncpy(colname, jpp->GetKey(), 64);
fmt[bf] = 0; fmt[bf] = 0;
if (Find(g, jpp->GetVal(), MY_MIN(lvl, 0))) if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0)))
goto err; goto err;
} // endfor jpp } // endfor jpp
...@@ -385,7 +392,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) ...@@ -385,7 +392,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
return 0; return 0;
} // end of GetColumns } // end of GetColumns
bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
{ {
char *p, *pc = colname + strlen(colname); char *p, *pc = colname + strlen(colname);
int ars; int ars;
...@@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) ...@@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
job = (PJOB)jsp; job = (PJOB)jsp;
for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) { for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) {
if (*jrp->GetKey() != '$') { PCSZ k = jrp->GetKey();
strncat(strncat(fmt, sep, 128), jrp->GetKey(), 128);
strncat(strncat(colname, "_", 64), jrp->GetKey(), 64); if (*k != '$') {
strncat(strncat(fmt, sep, 128), k, 128);
strncat(strncat(colname, "_", 64), k, 64);
} // endif Key } // endif Key
if (Find(g, jrp->GetVal(), j + 1)) if (Find(g, jrp->GetVal(), k, j + 1))
return true; return true;
*p = *pc = 0; *p = *pc = 0;
...@@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) ...@@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
case TYPE_JAR: case TYPE_JAR:
jar = (PJAR)jsp; jar = (PJAR)jsp;
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, colname))) if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key)))
ars = jar->GetSize(false); ars = jar->GetSize(false);
else else
ars = MY_MIN(jar->GetSize(false), 1); ars = MY_MIN(jar->GetSize(false), 1);
for (int k = 0; k < ars; k++) { for (int k = 0; k < ars; k++) {
if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) { if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
sprintf(buf, "%d", k); sprintf(buf, "%d", k);
if (tdp->Uri) if (tdp->Uri)
...@@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) ...@@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
} else } else
strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); strncat(fmt, (tdp->Uri ? sep : "[*]"), 128);
if (Find(g, jar->GetValue(k), j)) if (Find(g, jar->GetValue(k), "", j))
return true; return true;
*p = *pc = 0; *p = *pc = 0;
...@@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g) ...@@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g)
n++; n++;
} // endif jcp } // endif jcp
if (jcp)
pjcp = jcp; pjcp = jcp;
} // end of AddColumn } // end of AddColumn
...@@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void) ...@@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void)
/***********************************************************************/ /***********************************************************************/
/* DefineAM: define specific AM block values. */ /* DefineAM: define specific AM block values. */
/***********************************************************************/ /***********************************************************************/
bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{ {
Schema = GetStringCatInfo(g, "DBname", Schema); Schema = GetStringCatInfo(g, "DBname", Schema);
Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT); Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT);
...@@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) ...@@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Sep = *GetStringCatInfo(g, "Separator", "."); Sep = *GetStringCatInfo(g, "Separator", ".");
Accept = GetBoolCatInfo("Accept", false); Accept = GetBoolCatInfo("Accept", false);
if (Uri = GetStringCatInfo(g, "Connect", NULL)) { // Don't use url as uri when called from REST OEM module
if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) {
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
Collname = GetStringCatInfo(g, "Name", Collname = GetStringCatInfo(g, "Name",
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
......
...@@ -52,7 +52,7 @@ class JSONDISC : public BLOCK { ...@@ -52,7 +52,7 @@ class JSONDISC : public BLOCK {
// Functions // Functions
int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt); int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt);
bool Find(PGLOBAL g, PJVAL jvp, int j); bool Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j);
void AddColumn(PGLOBAL g); void AddColumn(PGLOBAL g);
// Members // Members
......
...@@ -163,8 +163,11 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -163,8 +163,11 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
return NULL; return NULL;
tdp->Tabname = tab; tdp->Tabname = tab;
tdp->Tabname = (char*)GetStringTableOption(g, topt, "Tabname", tab);
tdp->Rowname = (char*)GetStringTableOption(g, topt, "Rownode", NULL);
tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false); tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL); tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
tdp->Skip = GetBooleanTableOption(g, topt, "Skipnull", false);
if (!(op = GetStringTableOption(g, topt, "Xmlsup", NULL))) if (!(op = GetStringTableOption(g, topt, "Xmlsup", NULL)))
#if defined(__WIN__) #if defined(__WIN__)
...@@ -280,7 +283,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -280,7 +283,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
if (!vp->atp) if (!vp->atp)
node = vp->nl->GetItem(g, vp->k++, tdp->Usedom ? node : NULL); node = vp->nl->GetItem(g, vp->k++, tdp->Usedom ? node : NULL);
if (!j)
strncat(fmt, colname, XLEN(fmt)); strncat(fmt, colname, XLEN(fmt));
strncat(fmt, "/", XLEN(fmt)); strncat(fmt, "/", XLEN(fmt));
strncat(xcol->Name, "_", XLEN(xcol->Name)); strncat(xcol->Name, "_", XLEN(xcol->Name));
j++; j++;
...@@ -302,6 +307,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -302,6 +307,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
case RC_INFO: case RC_INFO:
PushWarning(g, txmp); PushWarning(g, txmp);
case RC_OK: case RC_OK:
xcol->Cbn = !strlen(buf);
break; break;
default: default:
goto err; goto err;
...@@ -327,9 +333,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -327,9 +333,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
xcp->Len = MY_MAX(xcp->Len, xcol->Len); xcp->Len = MY_MAX(xcp->Len, xcol->Len);
xcp->Scale = MY_MAX(xcp->Scale, xcol->Scale); xcp->Scale = MY_MAX(xcp->Scale, xcol->Scale);
xcp->Cbn |= xcol->Cbn; xcp->Cbn |= (xcol->Cbn || !xcol->Len);
xcp->Found = true; xcp->Found = true;
} else { } else if(xcol->Len || !tdp->Skip) {
// New column // New column
xcp = new(g) XMCOL(g, xcol, fmt, i); xcp = new(g) XMCOL(g, xcol, fmt, i);
length[0] = MY_MAX(length[0], strlen(xcol->Name)); length[0] = MY_MAX(length[0], strlen(xcol->Name));
...@@ -344,6 +350,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -344,6 +350,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
n++; n++;
} // endif xcp } // endif xcp
if (xcp)
pxcp = xcp; pxcp = xcp;
if (vp->atp) if (vp->atp)
...@@ -445,6 +452,7 @@ XMLDEF::XMLDEF(void) ...@@ -445,6 +452,7 @@ XMLDEF::XMLDEF(void)
Usedom = false; Usedom = false;
Zipped = false; Zipped = false;
Mulentries = false; Mulentries = false;
Skip = false;
} // end of XMLDEF constructor } // end of XMLDEF constructor
/***********************************************************************/ /***********************************************************************/
...@@ -871,8 +879,10 @@ bool TDBXML::Initialize(PGLOBAL g) ...@@ -871,8 +879,10 @@ bool TDBXML::Initialize(PGLOBAL g)
} // endif TabNode } // endif TabNode
DBnode->AddText(g, "\n"); DBnode->AddText(g, "\n");
} else } else {
TabNode = Root; // Try this ? TabNode = Root; // Try this ?
Tabname = TabNode->GetName(g);
} // endif's
} else if (rc == RC_NF || rc == RC_EF) { } else if (rc == RC_NF || rc == RC_EF) {
// The XML file does not exist or is void // The XML file does not exist or is void
...@@ -926,15 +936,27 @@ bool TDBXML::Initialize(PGLOBAL g) ...@@ -926,15 +936,27 @@ bool TDBXML::Initialize(PGLOBAL g)
} else // (rc == RC_FX) } else // (rc == RC_FX)
goto error; goto error;
if (!Rowname) {
for (PXNODE n = TabNode->GetChild(g); n; n = n->GetNext(g))
if (n->GetType() == XML_ELEMENT_NODE) {
Rowname = n->GetName(g);
break;
} // endif Type
if (!Rowname)
Rowname = TabNode->GetName(g);
} // endif Rowname
// Get row node list // Get row node list
if (Rowname) if (strcmp(Rowname, Tabname))
Nlist = TabNode->SelectNodes(g, Rowname); Nlist = TabNode->SelectNodes(g, Rowname);
else else
Nlist = TabNode->GetChildElements(g); Nrow = 1;
Docp->SetNofree(true); // For libxml2 Docp->SetNofree(true); // For libxml2
#if defined(__WIN__) #if defined(__WIN__)
} catch(_com_error e) { } catch (_com_error e) {
// We come here if a DOM command threw an error // We come here if a DOM command threw an error
char buf[128]; char buf[128];
...@@ -1221,11 +1243,15 @@ int TDBXML::ReadDB(PGLOBAL g) ...@@ -1221,11 +1243,15 @@ int TDBXML::ReadDB(PGLOBAL g)
htrc("TDBXML ReadDB: Irow=%d RowNode=%p\n", Irow, RowNode); htrc("TDBXML ReadDB: Irow=%d RowNode=%p\n", Irow, RowNode);
// Get the new row node // Get the new row node
if (Nlist) {
if ((RowNode = Nlist->GetItem(g, Irow, RowNode)) == NULL) { if ((RowNode = Nlist->GetItem(g, Irow, RowNode)) == NULL) {
sprintf(g->Message, MSG(MISSING_ROWNODE), Irow); sprintf(g->Message, MSG(MISSING_ROWNODE), Irow);
return RC_FX; return RC_FX;
} // endif RowNode } // endif RowNode
} else
RowNode = TabNode;
if (Colname && Coltype == 2) if (Colname && Coltype == 2)
Clist = RowNode->SelectNodes(g, Colname, Clist); Clist = RowNode->SelectNodes(g, Colname, Clist);
...@@ -1279,6 +1305,7 @@ int TDBXML::WriteDB(PGLOBAL g) ...@@ -1279,6 +1305,7 @@ int TDBXML::WriteDB(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
int TDBXML::DeleteDB(PGLOBAL g, int irc) int TDBXML::DeleteDB(PGLOBAL g, int irc)
{ {
// TODO: Handle null Nlist
if (irc == RC_FX) { if (irc == RC_FX) {
// Delete all rows // Delete all rows
for (Irow = 0; Irow < Nrow; Irow++) for (Irow = 0; Irow < Nrow; Irow++)
......
...@@ -52,6 +52,7 @@ class DllExport XMLDEF : public TABDEF { /* Logical table description */ ...@@ -52,6 +52,7 @@ class DllExport XMLDEF : public TABDEF { /* Logical table description */
bool Usedom; /* True: DOM, False: libxml2 */ bool Usedom; /* True: DOM, False: libxml2 */
bool Zipped; /* True: Zipped XML file(s) */ bool Zipped; /* True: Zipped XML file(s) */
bool Mulentries; /* True: multiple entries in zip file*/ bool Mulentries; /* True: multiple entries in zip file*/
bool Skip; /* Skip null columns */
}; // end of XMLDEF }; // end of XMLDEF
#if defined(INCLUDE_TDBXML) #if defined(INCLUDE_TDBXML)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment