1
1
/* ************ 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 */
4
4
/* This program are the JSON class DB execution routines. */
5
5
/* **********************************************************************/
6
6
@@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg)
173
173
174
174
int JSONDISC::GetColumns (PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
175
175
{
176
+ char filename[_MAX_PATH];
176
177
bool mgo = (GetTypeID (topt->type ) == TAB_MONGO);
177
178
PCSZ level = GetStringTableOption (g, topt, " Level" , NULL );
178
179
@@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
209
210
return 0 ;
210
211
} // endif Fn
211
212
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
+
212
219
if (trace (1 ))
213
220
htrc (" File %s objname=%s pretty=%d lvl=%d\n " ,
214
221
tdp->Fn , tdp->Objname , tdp->Pretty , lvl);
@@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
342
349
strncpy (colname, jpp->GetKey (), 64 );
343
350
fmt[bf] = 0 ;
344
351
345
- if (Find (g, jpp->GetVal (), MY_MIN (lvl, 0 )))
352
+ if (Find (g, jpp->GetVal (), colname, MY_MIN (lvl, 0 )))
346
353
goto err;
347
354
348
355
} // endfor jpp
@@ -385,7 +392,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
385
392
return 0 ;
386
393
} // end of GetColumns
387
394
388
- bool JSONDISC::Find (PGLOBAL g, PJVAL jvp, int j)
395
+ bool JSONDISC::Find (PGLOBAL g, PJVAL jvp, PCSZ key, int j)
389
396
{
390
397
char *p, *pc = colname + strlen (colname);
391
398
int ars;
@@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
413
420
job = (PJOB)jsp;
414
421
415
422
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 );
419
428
} // endif Key
420
429
421
- if (Find (g, jrp->GetVal (), j + 1 ))
430
+ if (Find (g, jrp->GetVal (), k, j + 1 ))
422
431
return true ;
423
432
424
433
*p = *pc = 0 ;
@@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
428
437
case TYPE_JAR:
429
438
jar = (PJAR)jsp;
430
439
431
- if (all || (tdp->Xcol && !stricmp (tdp->Xcol , colname )))
440
+ if (all || (tdp->Xcol && !stricmp (tdp->Xcol , key )))
432
441
ars = jar->GetSize (false );
433
442
else
434
443
ars = MY_MIN (jar->GetSize (false ), 1 );
435
444
436
445
for (int k = 0 ; k < ars; k++) {
437
- if (!tdp->Xcol || stricmp (tdp->Xcol , colname )) {
446
+ if (!tdp->Xcol || stricmp (tdp->Xcol , key )) {
438
447
sprintf (buf, " %d" , k);
439
448
440
449
if (tdp->Uri )
@@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
448
457
} else
449
458
strncat (fmt, (tdp->Uri ? sep : " [*]" ), 128 );
450
459
451
- if (Find (g, jar->GetValue (k), j))
460
+ if (Find (g, jar->GetValue (k), " " , j))
452
461
return true ;
453
462
454
463
*p = *pc = 0 ;
@@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g)
522
531
n++;
523
532
} // endif jcp
524
533
525
- pjcp = jcp;
534
+ if (jcp)
535
+ pjcp = jcp;
536
+
526
537
} // end of AddColumn
527
538
528
539
@@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void)
549
560
/* **********************************************************************/
550
561
/* DefineAM: define specific AM block values. */
551
562
/* **********************************************************************/
552
- bool JSONDEF::DefineAM (PGLOBAL g, LPCSTR, int poff)
563
+ bool JSONDEF::DefineAM (PGLOBAL g, LPCSTR am , int poff)
553
564
{
554
565
Schema = GetStringCatInfo (g, " DBname" , Schema);
555
566
Jmode = (JMODE)GetIntCatInfo (" Jmode" , MODE_OBJECT);
@@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
561
572
Sep = *GetStringCatInfo (g, " Separator" , " ." );
562
573
Accept = GetBoolCatInfo (" Accept" , false );
563
574
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 ))) {
565
577
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
566
578
Collname = GetStringCatInfo (g, " Name" ,
567
579
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
@@ -2340,7 +2352,7 @@ void TDBJSON::CloseDB(PGLOBAL g)
2340
2352
TDBJCL::TDBJCL (PJDEF tdp) : TDBCAT(tdp)
2341
2353
{
2342
2354
Topt = tdp->GetTopt ();
2343
- Db = tdp->Schema ;
2355
+ Db = tdp->Schema ;
2344
2356
Dsn = tdp->Uri ;
2345
2357
} // end of TDBJCL constructor
2346
2358
0 commit comments