Skip to content

Commit 547ce1b

Browse files
committed
- Fix a few bug mainly concerning discovery and call from OEM
(and prepare new table types) modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h - Fix wrong line estimate modified: storage/connect/mysql-test/connect/r/part_table.result modified: storage/connect/mysql-test/connect/t/part_table.test
1 parent c2482c7 commit 547ce1b

File tree

6 files changed

+188
-147
lines changed

6 files changed

+188
-147
lines changed

storage/connect/mysql-test/connect/r/part_table.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ id msg
2323
CREATE TABLE xt3 (
2424
id INT KEY NOT NULL,
2525
msg VARCHAR(32))
26-
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5;
26+
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
2727
Warnings:
2828
Warning 1105 No file name. Table will use xt3.csv
2929
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
@@ -89,9 +89,10 @@ id msg
8989
60 sixty
9090
81 eighty one
9191
72 seventy two
92+
EXPLAIN PARTITIONS
9293
SELECT * FROM t1 WHERE id = 81;
93-
id msg
94-
81 eighty one
94+
id select_type table partitions type possible_keys key key_len ref rows Extra
95+
1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where
9596
DELETE FROM t1;
9697
Warnings:
9798
Note 1105 xt1: 4 affected rows

storage/connect/mysql-test/connect/t/part_table.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SELECT * FROM xt2;
2222
CREATE TABLE xt3 (
2323
id INT KEY NOT NULL,
2424
msg VARCHAR(32))
25-
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5;
25+
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
2626
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
2727
SELECT * FROM xt3;
2828

@@ -47,7 +47,7 @@ INSERT INTO t1 VALUES(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eight
4747
INSERT INTO t1 VALUES(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight');
4848
SELECT partition_name, table_rows FROM information_schema.partitions WHERE table_name = 't1';
4949
SELECT * FROM t1;
50-
#EXPLAIN PARTITIONS deleted because it returns differeent key on Windows and Linux
50+
EXPLAIN PARTITIONS
5151
SELECT * FROM t1 WHERE id = 81;
5252
DELETE FROM t1;
5353
DROP TABLE t1;

storage/connect/tabjson.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/************* tabjson C++ Program Source Code File (.CPP) *************/
2-
/* PROGRAM NAME: tabjson Version 1.5 */
3-
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */
2+
/* PROGRAM NAME: tabjson Version 1.6 */
3+
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */
44
/* This program are the JSON class DB execution routines. */
55
/***********************************************************************/
66

@@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg)
173173

174174
int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
175175
{
176+
char filename[_MAX_PATH];
176177
bool mgo = (GetTypeID(topt->type) == TAB_MONGO);
177178
PCSZ level = GetStringTableOption(g, topt, "Level", NULL);
178179

@@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
209210
return 0;
210211
} // endif Fn
211212

213+
if (tdp->Fn) {
214+
// We used the file name relative to recorded datapath
215+
PlugSetPath(filename, tdp->Fn, tdp->GetPath());
216+
tdp->Fn = PlugDup(g, filename);
217+
} // endif Fn
218+
212219
if (trace(1))
213220
htrc("File %s objname=%s pretty=%d lvl=%d\n",
214221
tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
@@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
342349
strncpy(colname, jpp->GetKey(), 64);
343350
fmt[bf] = 0;
344351

345-
if (Find(g, jpp->GetVal(), MY_MIN(lvl, 0)))
352+
if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0)))
346353
goto err;
347354

348355
} // endfor jpp
@@ -385,7 +392,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
385392
return 0;
386393
} // end of GetColumns
387394

388-
bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
395+
bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
389396
{
390397
char *p, *pc = colname + strlen(colname);
391398
int ars;
@@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
413420
job = (PJOB)jsp;
414421

415422
for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) {
416-
if (*jrp->GetKey() != '$') {
417-
strncat(strncat(fmt, sep, 128), jrp->GetKey(), 128);
418-
strncat(strncat(colname, "_", 64), jrp->GetKey(), 64);
423+
PCSZ k = jrp->GetKey();
424+
425+
if (*k != '$') {
426+
strncat(strncat(fmt, sep, 128), k, 128);
427+
strncat(strncat(colname, "_", 64), k, 64);
419428
} // endif Key
420429

421-
if (Find(g, jrp->GetVal(), j + 1))
430+
if (Find(g, jrp->GetVal(), k, j + 1))
422431
return true;
423432

424433
*p = *pc = 0;
@@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
428437
case TYPE_JAR:
429438
jar = (PJAR)jsp;
430439

431-
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, colname)))
440+
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key)))
432441
ars = jar->GetSize(false);
433442
else
434443
ars = MY_MIN(jar->GetSize(false), 1);
435444

436445
for (int k = 0; k < ars; k++) {
437-
if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) {
446+
if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
438447
sprintf(buf, "%d", k);
439448

440449
if (tdp->Uri)
@@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
448457
} else
449458
strncat(fmt, (tdp->Uri ? sep : "[*]"), 128);
450459

451-
if (Find(g, jar->GetValue(k), j))
460+
if (Find(g, jar->GetValue(k), "", j))
452461
return true;
453462

454463
*p = *pc = 0;
@@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g)
522531
n++;
523532
} // endif jcp
524533

525-
pjcp = jcp;
534+
if (jcp)
535+
pjcp = jcp;
536+
526537
} // end of AddColumn
527538

528539

@@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void)
549560
/***********************************************************************/
550561
/* DefineAM: define specific AM block values. */
551562
/***********************************************************************/
552-
bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
563+
bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
553564
{
554565
Schema = GetStringCatInfo(g, "DBname", Schema);
555566
Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT);
@@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
561572
Sep = *GetStringCatInfo(g, "Separator", ".");
562573
Accept = GetBoolCatInfo("Accept", false);
563574

564-
if (Uri = GetStringCatInfo(g, "Connect", NULL)) {
575+
// Don't use url as uri when called from REST OEM module
576+
if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) {
565577
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
566578
Collname = GetStringCatInfo(g, "Name",
567579
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
@@ -2340,7 +2352,7 @@ void TDBJSON::CloseDB(PGLOBAL g)
23402352
TDBJCL::TDBJCL(PJDEF tdp) : TDBCAT(tdp)
23412353
{
23422354
Topt = tdp->GetTopt();
2343-
Db = tdp->Schema;
2355+
Db = tdp->Schema;
23442356
Dsn = tdp->Uri;
23452357
} // end of TDBJCL constructor
23462358

storage/connect/tabjson.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class JSONDISC : public BLOCK {
5252

5353
// Functions
5454
int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt);
55-
bool Find(PGLOBAL g, PJVAL jvp, int j);
55+
bool Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j);
5656
void AddColumn(PGLOBAL g);
5757

5858
// Members

0 commit comments

Comments
 (0)