Skip to content

Commit 44dea7f

Browse files
committed
Merge branch 'connect/10.1' into 10.1
2 parents f4faac4 + 3e20a0d commit 44dea7f

File tree

9 files changed

+62
-43
lines changed

9 files changed

+62
-43
lines changed

storage/connect/json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty)
594594
if (fs) {
595595
fputs(EL, fs);
596596
fclose(fs);
597-
str = (err) ? NULL : (char*) "Ok";
597+
str = (err) ? NULL : strcpy(g->Message, "Ok");
598598
} else if (!err) {
599599
str = ((JOUTSTR*)jp)->Strp;
600600
jp->WriteChr('\0');

storage/connect/mycat.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) Olivier Bertrand 2004 - 2015
1+
/* Copyright (C) Olivier Bertrand 2004 - 2016
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
1818
/* ------------- */
1919
/* Version 1.4 */
2020
/* */
21-
/* Author: Olivier Bertrand 2012 - 2015 */
21+
/* Author: Olivier Bertrand 2012 - 2016 */
2222
/* */
2323
/* WHAT THIS PROGRAM DOES: */
2424
/* ----------------------- */
@@ -509,30 +509,33 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
509509
/* GetTableDesc: retrieve a table descriptor. */
510510
/* Look for a table descriptor matching the name and type. */
511511
/***********************************************************************/
512-
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name,
512+
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
513513
LPCSTR type, PRELDEF *)
514514
{
515515
if (trace)
516-
printf("GetTableDesc: name=%s am=%s\n", name, SVP(type));
516+
printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
517517

518518
// If not specified get the type of this table
519519
if (!type)
520520
type= Hc->GetStringOption("Type","*");
521521

522-
return MakeTableDesc(g, name, type);
522+
return MakeTableDesc(g, tablep, type);
523523
} // end of GetTableDesc
524524

525525
/***********************************************************************/
526526
/* MakeTableDesc: make a table/view description. */
527527
/* Note: caller must check if name already exists before calling it. */
528528
/***********************************************************************/
529-
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
529+
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
530530
{
531531
TABTYPE tc;
532+
LPCSTR name = (PSZ)PlugDup(g, tablep->GetName());
533+
LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema());
532534
PRELDEF tdp= NULL;
533535

534536
if (trace)
535-
printf("MakeTableDesc: name=%s am=%s\n", name, SVP(am));
537+
printf("MakeTableDesc: name=%s schema=%s am=%s\n",
538+
name, SVP(schema), SVP(am));
536539

537540
/*********************************************************************/
538541
/* Get a unique enum identifier for types. */
@@ -571,11 +574,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
571574
case TAB_VIR: tdp= new(g) VIRDEF; break;
572575
case TAB_JSON: tdp= new(g) JSONDEF; break;
573576
default:
574-
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
577+
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
575578
} // endswitch
576579

577580
// Do make the table/view definition
578-
if (tdp && tdp->Define(g, this, name, am))
581+
if (tdp && tdp->Define(g, this, name, schema, am))
579582
tdp= NULL;
580583

581584
return tdp;
@@ -588,20 +591,20 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
588591
{
589592
PRELDEF tdp;
590593
PTDB tdbp= NULL;
591-
LPCSTR name= tablep->GetName();
594+
// LPCSTR name= tablep->GetName();
592595

593596
if (trace)
594-
printf("GetTableDB: name=%s\n", name);
597+
printf("GetTableDB: name=%s\n", tablep->GetName());
595598

596599
// Look for the description of the requested table
597-
tdp= GetTableDesc(g, name, type);
600+
tdp= GetTableDesc(g, tablep, type);
598601

599602
if (tdp) {
600603
if (trace)
601604
printf("tdb=%p type=%s\n", tdp, tdp->GetType());
602605

603-
if (tablep->GetQualifier())
604-
tdp->Database = SetPath(g, tablep->GetQualifier());
606+
if (tablep->GetSchema())
607+
tdp->Database = SetPath(g, tablep->GetSchema());
605608

606609
tdbp= tdp->GetTable(g, mode);
607610
} // endif tdp

storage/connect/mycat.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ class MYCAT : public CATALOG {
100100
//void SetDataPath(PGLOBAL g, const char *path)
101101
// {SetPath(g, &DataPath, path);}
102102
bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary
103-
PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
104-
LPCSTR type, PRELDEF *prp = NULL);
103+
// PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
104+
PRELDEF GetTableDesc(PGLOBAL g, PTABLE tablep,
105+
LPCSTR type, PRELDEF *prp = NULL);
105106
PTDB GetTable(PGLOBAL g, PTABLE tablep,
106107
MODE mode = MODE_READ, LPCSTR type = NULL);
107108
void ClearDB(PGLOBAL g);
108109

109110
protected:
110-
PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
111-
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);
111+
// PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
112+
PRELDEF MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am);
113+
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);
112114

113115
// Members
114116
ha_connect *Hc; // The Connect handler

storage/connect/reldef.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/************* RelDef CPP Program Source Code File (.CPP) **************/
22
/* PROGRAM NAME: RELDEF */
33
/* ------------- */
4-
/* Version 1.4 */
4+
/* Version 1.5 */
55
/* */
66
/* COPYRIGHT: */
77
/* ---------- */
8-
/* (C) Copyright to the author Olivier BERTRAND 2004-2015 */
8+
/* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
99
/* */
1010
/* WHAT THIS PROGRAM DOES: */
1111
/* ----------------------- */
@@ -37,6 +37,7 @@
3737
#include "plgdbsem.h"
3838
#include "reldef.h"
3939
#include "colblk.h"
40+
#include "tabcol.h"
4041
#include "filamap.h"
4142
#include "filamfix.h"
4243
#include "filamvct.h"
@@ -217,11 +218,13 @@ TABDEF::TABDEF(void)
217218
/***********************************************************************/
218219
/* Define: initialize the table definition block from XDB file. */
219220
/***********************************************************************/
220-
bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am)
221+
bool TABDEF::Define(PGLOBAL g, PCATLG cat,
222+
LPCSTR name, LPCSTR schema, LPCSTR am)
221223
{
222224
int poff = 0;
223225

224-
Name = (PSZ)PlugDup(g, name);
226+
Name = (PSZ)name;
227+
Schema = (PSZ)schema;
225228
Cat = cat;
226229
Hc = ((MYCAT*)cat)->GetHandler();
227230
Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL));
@@ -569,7 +572,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
569572
} // endif Cbuf
570573

571574
// Here "OEM" should be replace by a more useful value
572-
if (xdefp->Define(g, cat, Name, "OEM"))
575+
if (xdefp->Define(g, cat, Name, Schema, "OEM"))
573576
return NULL;
574577

575578
// Ok, return external block

storage/connect/reldef.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*************** RelDef H Declares Source Code File (.H) ***************/
2-
/* Name: RELDEF.H Version 1.5 */
2+
/* Name: RELDEF.H Version 1.6 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2004-2015 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
55
/* */
66
/* This file contains the DEF classes definitions. */
77
/***********************************************************************/
@@ -50,7 +50,8 @@ class DllExport RELDEF : public BLOCK { // Relation definition block
5050
int GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size);
5151
char *GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef);
5252
virtual int Indexable(void) {return 0;}
53-
virtual bool Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) = 0;
53+
virtual bool Define(PGLOBAL g, PCATLG cat,
54+
LPCSTR name, LPCSTR schema, LPCSTR am) = 0;
5455
virtual PTDB GetTable(PGLOBAL g, MODE mode) = 0;
5556

5657
protected:
@@ -97,8 +98,9 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
9798
int GetColCatInfo(PGLOBAL g);
9899
void SetIndexInfo(void);
99100
bool DropTable(PGLOBAL g, PSZ name);
100-
virtual bool Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am);
101-
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;
101+
virtual bool Define(PGLOBAL g, PCATLG cat,
102+
LPCSTR name, LPCSTR schema, LPCSTR am);
103+
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;
102104

103105
protected:
104106
// Members

storage/connect/tabmysql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
334334
Delayed = !!GetIntCatInfo("Delayed", 0);
335335
} else {
336336
// MYSQL access from a PROXY table
337-
Database = GetStringCatInfo(g, "Database", "*");
337+
Database = GetStringCatInfo(g, "Database", Schema ? Schema : "*");
338338
Isview = GetBoolCatInfo("View", false);
339339

340340
// We must get other connection parms from the calling table

storage/connect/tabpivot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
348348
return TRUE;
349349

350350
Tabname = (char*)Tablep->GetName();
351-
DB = (char*)Tablep->GetQualifier();
351+
DB = (char*)Tablep->GetSchema();
352352
Tabsrc = (char*)Tablep->GetSrc();
353353

354354
Host = GetStringCatInfo(g, "Host", "localhost");
@@ -529,7 +529,7 @@ bool TDBPIVOT::GetSourceTable(PGLOBAL g)
529529
// Get the new table description block of this source table
530530
PTABLE tablep = new(g) XTAB("whatever", Tabsrc);
531531

532-
tablep->SetQualifier(Database);
532+
tablep->SetSchema(Database);
533533

534534
if (!(Tdbp = GetSubTable(g, tablep, true)))
535535
return true;

storage/connect/tabtbl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* */
66
/* COPYRIGHT: */
77
/* ---------- */
8-
/* (C) Copyright to PlugDB Software Development 2008-2015 */
8+
/* (C) Copyright to PlugDB Software Development 2008-2016 */
99
/* Author: Olivier BERTRAND */
1010
/* */
1111
/* WHAT THIS PROGRAM DOES: */
@@ -130,10 +130,10 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR, int)
130130

131131
// Allocate the TBLIST block for that table
132132
tbl = new(g) XTAB(pn, def);
133-
tbl->SetQualifier(pdb);
133+
tbl->SetSchema(pdb);
134134

135135
if (trace)
136-
htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetQualifier());
136+
htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetSchema());
137137

138138
// Link the blocks
139139
if (Tablep)

storage/connect/tabutil.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************* Tabutil cpp Declares Source Code File (.CPP) ************/
22
/* Name: TABUTIL.CPP Version 1.1 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2013 - 2015 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2013 - 2016 */
55
/* */
66
/* Utility function used by the PROXY, XCOL, OCCUR, and TBL tables. */
77
/***********************************************************************/
@@ -118,7 +118,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
118118
FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL,
119119
FLD_REM, FLD_NO, FLD_CHARSET};
120120
unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 32, 32};
121-
char *fld, *colname, *chset, *fmt, v;
121+
char *pn, *tn, *fld, *colname, *chset, *fmt, v;
122122
int i, n, ncol = sizeof(buftyp) / sizeof(int);
123123
int prec, len, type, scale;
124124
int zconv = GetConvSize();
@@ -130,7 +130,16 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
130130
PCOLRES crp;
131131

132132
if (!info) {
133-
if (!(s = GetTableShare(g, thd, db, name, mysql))) {
133+
// Analyze the table name, it may have the format: [dbname.]tabname
134+
if (strchr((char*)name, '.')) {
135+
tn = (char*)PlugDup(g, name);
136+
pn = strchr(tn, '.');
137+
*pn++ = 0;
138+
db = tn;
139+
name = pn;
140+
} // endif pn
141+
142+
if (!(s = GetTableShare(g, thd, db, name, mysql))) {
134143
return NULL;
135144
} else if (s->is_view) {
136145
strcpy(g->Message, "Use MYSQL type to see columns from a view");
@@ -315,7 +324,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR, int)
315324
} // endif pn
316325

317326
Tablep = new(g) XTAB(tab, def);
318-
Tablep->SetQualifier(db);
327+
Tablep->SetSchema(db);
319328
return false;
320329
} // end of DefineAM
321330

@@ -379,12 +388,12 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
379388
LPCSTR cdb, curdb = hc->GetDBName(NULL);
380389
THD *thd = (hc->GetTable())->in_use;
381390

382-
db = (char*)tabp->GetQualifier();
391+
db = (char*)(tabp->GetSchema() ? tabp->GetSchema() : curdb);
383392
name = (char*)tabp->GetName();
384393

385394
// Check for eventual loop
386395
for (PTABLE tp = To_Table; tp; tp = tp->Next) {
387-
cdb = (tp->Qualifier) ? tp->Qualifier : curdb;
396+
cdb = (tp->Schema) ? tp->Schema : curdb;
388397

389398
if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) {
390399
sprintf(g->Message, "Table %s.%s pointing on itself", db, name);
@@ -423,7 +432,7 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
423432
} // endif Define
424433

425434
if (db)
426-
((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier());
435+
((PTDBMY)tdbp)->SetDatabase(tabp->GetSchema());
427436

428437
if (Mode == MODE_UPDATE || Mode == MODE_DELETE)
429438
tdbp->SetName(Name); // For Make_Command
@@ -757,7 +766,7 @@ void PRXCOL::WriteColumn(PGLOBAL g)
757766
/***********************************************************************/
758767
TDBTBC::TDBTBC(PPRXDEF tdp) : TDBCAT(tdp)
759768
{
760-
Db = (PSZ)tdp->Tablep->GetQualifier();
769+
Db = (PSZ)tdp->Tablep->GetSchema();
761770
Tab = (PSZ)tdp->Tablep->GetName();
762771
} // end of TDBTBC constructor
763772

0 commit comments

Comments
 (0)