Commit 0891ae2f authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix MDEV-9239. Meanwhile, make all references to the database in XTAB Schema

  (was sometimes in XTAB Catalog)
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/mycat.h
  modified:   storage/connect/reldef.cpp
  modified:   storage/connect/reldef.h
  modified:   storage/connect/tabmysql.cpp
  modified:   storage/connect/tabpivot.cpp
  modified:   storage/connect/tabtbl.cpp
  modified:   storage/connect/tabutil.cpp
parent 6883e5c4
/* Copyright (C) Olivier Bertrand 2004 - 2015 /* Copyright (C) Olivier Bertrand 2004 - 2016
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/* ------------- */ /* ------------- */
/* Version 1.4 */ /* Version 1.4 */
/* */ /* */
/* Author: Olivier Bertrand 2012 - 2015 */ /* Author: Olivier Bertrand 2012 - 2016 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -509,30 +509,33 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path) ...@@ -509,30 +509,33 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
/* GetTableDesc: retrieve a table descriptor. */ /* GetTableDesc: retrieve a table descriptor. */
/* Look for a table descriptor matching the name and type. */ /* Look for a table descriptor matching the name and type. */
/***********************************************************************/ /***********************************************************************/
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name, PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
LPCSTR type, PRELDEF *) LPCSTR type, PRELDEF *)
{ {
if (trace) if (trace)
printf("GetTableDesc: name=%s am=%s\n", name, SVP(type)); printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
// If not specified get the type of this table // If not specified get the type of this table
if (!type) if (!type)
type= Hc->GetStringOption("Type","*"); type= Hc->GetStringOption("Type","*");
return MakeTableDesc(g, name, type); return MakeTableDesc(g, tablep, type);
} // end of GetTableDesc } // end of GetTableDesc
/***********************************************************************/ /***********************************************************************/
/* MakeTableDesc: make a table/view description. */ /* MakeTableDesc: make a table/view description. */
/* Note: caller must check if name already exists before calling it. */ /* Note: caller must check if name already exists before calling it. */
/***********************************************************************/ /***********************************************************************/
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
{ {
TABTYPE tc; TABTYPE tc;
LPCSTR name = (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema());
PRELDEF tdp= NULL; PRELDEF tdp= NULL;
if (trace) if (trace)
printf("MakeTableDesc: name=%s am=%s\n", name, SVP(am)); printf("MakeTableDesc: name=%s schema=%s am=%s\n",
name, SVP(schema), SVP(am));
/*********************************************************************/ /*********************************************************************/
/* Get a unique enum identifier for types. */ /* Get a unique enum identifier for types. */
...@@ -571,11 +574,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) ...@@ -571,11 +574,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break; case TAB_JSON: tdp= new(g) JSONDEF; break;
default: default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch } // endswitch
// Do make the table/view definition // Do make the table/view definition
if (tdp && tdp->Define(g, this, name, am)) if (tdp && tdp->Define(g, this, name, schema, am))
tdp= NULL; tdp= NULL;
return tdp; return tdp;
...@@ -588,20 +591,20 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type) ...@@ -588,20 +591,20 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
{ {
PRELDEF tdp; PRELDEF tdp;
PTDB tdbp= NULL; PTDB tdbp= NULL;
LPCSTR name= tablep->GetName(); // LPCSTR name= tablep->GetName();
if (trace) if (trace)
printf("GetTableDB: name=%s\n", name); printf("GetTableDB: name=%s\n", tablep->GetName());
// Look for the description of the requested table // Look for the description of the requested table
tdp= GetTableDesc(g, name, type); tdp= GetTableDesc(g, tablep, type);
if (tdp) { if (tdp) {
if (trace) if (trace)
printf("tdb=%p type=%s\n", tdp, tdp->GetType()); printf("tdb=%p type=%s\n", tdp, tdp->GetType());
if (tablep->GetQualifier()) if (tablep->GetSchema())
tdp->Database = SetPath(g, tablep->GetQualifier()); tdp->Database = SetPath(g, tablep->GetSchema());
tdbp= tdp->GetTable(g, mode); tdbp= tdp->GetTable(g, mode);
} // endif tdp } // endif tdp
......
...@@ -100,15 +100,17 @@ class MYCAT : public CATALOG { ...@@ -100,15 +100,17 @@ class MYCAT : public CATALOG {
//void SetDataPath(PGLOBAL g, const char *path) //void SetDataPath(PGLOBAL g, const char *path)
// {SetPath(g, &DataPath, path);} // {SetPath(g, &DataPath, path);}
bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary
PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name, // PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
LPCSTR type, PRELDEF *prp = NULL); PRELDEF GetTableDesc(PGLOBAL g, PTABLE tablep,
LPCSTR type, PRELDEF *prp = NULL);
PTDB GetTable(PGLOBAL g, PTABLE tablep, PTDB GetTable(PGLOBAL g, PTABLE tablep,
MODE mode = MODE_READ, LPCSTR type = NULL); MODE mode = MODE_READ, LPCSTR type = NULL);
void ClearDB(PGLOBAL g); void ClearDB(PGLOBAL g);
protected: protected:
PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am); // PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path); PRELDEF MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am);
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);
// Members // Members
ha_connect *Hc; // The Connect handler ha_connect *Hc; // The Connect handler
......
/************* RelDef CPP Program Source Code File (.CPP) **************/ /************* RelDef CPP Program Source Code File (.CPP) **************/
/* PROGRAM NAME: RELDEF */ /* PROGRAM NAME: RELDEF */
/* ------------- */ /* ------------- */
/* Version 1.4 */ /* Version 1.5 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 2004-2015 */ /* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "plgdbsem.h" #include "plgdbsem.h"
#include "reldef.h" #include "reldef.h"
#include "colblk.h" #include "colblk.h"
#include "tabcol.h"
#include "filamap.h" #include "filamap.h"
#include "filamfix.h" #include "filamfix.h"
#include "filamvct.h" #include "filamvct.h"
...@@ -217,11 +218,13 @@ TABDEF::TABDEF(void) ...@@ -217,11 +218,13 @@ TABDEF::TABDEF(void)
/***********************************************************************/ /***********************************************************************/
/* Define: initialize the table definition block from XDB file. */ /* Define: initialize the table definition block from XDB file. */
/***********************************************************************/ /***********************************************************************/
bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) bool TABDEF::Define(PGLOBAL g, PCATLG cat,
LPCSTR name, LPCSTR schema, LPCSTR am)
{ {
int poff = 0; int poff = 0;
Name = (PSZ)PlugDup(g, name); Name = (PSZ)name;
Schema = (PSZ)schema;
Cat = cat; Cat = cat;
Hc = ((MYCAT*)cat)->GetHandler(); Hc = ((MYCAT*)cat)->GetHandler();
Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL)); Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL));
...@@ -569,7 +572,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) ...@@ -569,7 +572,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
} // endif Cbuf } // endif Cbuf
// Here "OEM" should be replace by a more useful value // Here "OEM" should be replace by a more useful value
if (xdefp->Define(g, cat, Name, "OEM")) if (xdefp->Define(g, cat, Name, Schema, "OEM"))
return NULL; return NULL;
// Ok, return external block // Ok, return external block
......
/*************** RelDef H Declares Source Code File (.H) ***************/ /*************** RelDef H Declares Source Code File (.H) ***************/
/* Name: RELDEF.H Version 1.5 */ /* Name: RELDEF.H Version 1.6 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2004-2015 */ /* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
/* */ /* */
/* This file contains the DEF classes definitions. */ /* This file contains the DEF classes definitions. */
/***********************************************************************/ /***********************************************************************/
...@@ -50,7 +50,8 @@ class DllExport RELDEF : public BLOCK { // Relation definition block ...@@ -50,7 +50,8 @@ class DllExport RELDEF : public BLOCK { // Relation definition block
int GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size); int GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size);
char *GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef); char *GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef);
virtual int Indexable(void) {return 0;} virtual int Indexable(void) {return 0;}
virtual bool Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) = 0; virtual bool Define(PGLOBAL g, PCATLG cat,
LPCSTR name, LPCSTR schema, LPCSTR am) = 0;
virtual PTDB GetTable(PGLOBAL g, MODE mode) = 0; virtual PTDB GetTable(PGLOBAL g, MODE mode) = 0;
protected: protected:
...@@ -97,8 +98,9 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */ ...@@ -97,8 +98,9 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
int GetColCatInfo(PGLOBAL g); int GetColCatInfo(PGLOBAL g);
void SetIndexInfo(void); void SetIndexInfo(void);
bool DropTable(PGLOBAL g, PSZ name); bool DropTable(PGLOBAL g, PSZ name);
virtual bool Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am); virtual bool Define(PGLOBAL g, PCATLG cat,
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0; LPCSTR name, LPCSTR schema, LPCSTR am);
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;
protected: protected:
// Members // Members
......
...@@ -334,7 +334,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int) ...@@ -334,7 +334,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
Delayed = !!GetIntCatInfo("Delayed", 0); Delayed = !!GetIntCatInfo("Delayed", 0);
} else { } else {
// MYSQL access from a PROXY table // MYSQL access from a PROXY table
Database = GetStringCatInfo(g, "Database", "*"); Database = GetStringCatInfo(g, "Database", Schema ? Schema : "*");
Isview = GetBoolCatInfo("View", false); Isview = GetBoolCatInfo("View", false);
// We must get other connection parms from the calling table // We must get other connection parms from the calling table
......
...@@ -348,7 +348,7 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -348,7 +348,7 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
return TRUE; return TRUE;
Tabname = (char*)Tablep->GetName(); Tabname = (char*)Tablep->GetName();
DB = (char*)Tablep->GetQualifier(); DB = (char*)Tablep->GetSchema();
Tabsrc = (char*)Tablep->GetSrc(); Tabsrc = (char*)Tablep->GetSrc();
Host = GetStringCatInfo(g, "Host", "localhost"); Host = GetStringCatInfo(g, "Host", "localhost");
...@@ -529,7 +529,7 @@ bool TDBPIVOT::GetSourceTable(PGLOBAL g) ...@@ -529,7 +529,7 @@ bool TDBPIVOT::GetSourceTable(PGLOBAL g)
// Get the new table description block of this source table // Get the new table description block of this source table
PTABLE tablep = new(g) XTAB("whatever", Tabsrc); PTABLE tablep = new(g) XTAB("whatever", Tabsrc);
tablep->SetQualifier(Database); tablep->SetSchema(Database);
if (!(Tdbp = GetSubTable(g, tablep, true))) if (!(Tdbp = GetSubTable(g, tablep, true)))
return true; return true;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to PlugDB Software Development 2008-2015 */ /* (C) Copyright to PlugDB Software Development 2008-2016 */
/* Author: Olivier BERTRAND */ /* Author: Olivier BERTRAND */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
...@@ -130,10 +130,10 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR, int) ...@@ -130,10 +130,10 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR, int)
// Allocate the TBLIST block for that table // Allocate the TBLIST block for that table
tbl = new(g) XTAB(pn, def); tbl = new(g) XTAB(pn, def);
tbl->SetQualifier(pdb); tbl->SetSchema(pdb);
if (trace) if (trace)
htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetQualifier()); htrc("TBL: Name=%s db=%s\n", tbl->GetName(), tbl->GetSchema());
// Link the blocks // Link the blocks
if (Tablep) if (Tablep)
......
/************* Tabutil cpp Declares Source Code File (.CPP) ************/ /************* Tabutil cpp Declares Source Code File (.CPP) ************/
/* Name: TABUTIL.CPP Version 1.1 */ /* Name: TABUTIL.CPP Version 1.1 */
/* */ /* */
/* (C) Copyright to the author Olivier BERTRAND 2013 - 2015 */ /* (C) Copyright to the author Olivier BERTRAND 2013 - 2016 */
/* */ /* */
/* Utility function used by the PROXY, XCOL, OCCUR, and TBL tables. */ /* Utility function used by the PROXY, XCOL, OCCUR, and TBL tables. */
/***********************************************************************/ /***********************************************************************/
...@@ -118,7 +118,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, ...@@ -118,7 +118,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL, FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL,
FLD_REM, FLD_NO, FLD_CHARSET}; FLD_REM, FLD_NO, FLD_CHARSET};
unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 32, 32}; unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 32, 32};
char *fld, *colname, *chset, *fmt, v; char *pn, *tn, *fld, *colname, *chset, *fmt, v;
int i, n, ncol = sizeof(buftyp) / sizeof(int); int i, n, ncol = sizeof(buftyp) / sizeof(int);
int prec, len, type, scale; int prec, len, type, scale;
int zconv = GetConvSize(); int zconv = GetConvSize();
...@@ -130,7 +130,16 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, ...@@ -130,7 +130,16 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
PCOLRES crp; PCOLRES crp;
if (!info) { if (!info) {
if (!(s = GetTableShare(g, thd, db, name, mysql))) { // Analyze the table name, it may have the format: [dbname.]tabname
if (strchr((char*)name, '.')) {
tn = (char*)PlugDup(g, name);
pn = strchr(tn, '.');
*pn++ = 0;
db = tn;
name = pn;
} // endif pn
if (!(s = GetTableShare(g, thd, db, name, mysql))) {
return NULL; return NULL;
} else if (s->is_view) { } else if (s->is_view) {
strcpy(g->Message, "Use MYSQL type to see columns from a view"); strcpy(g->Message, "Use MYSQL type to see columns from a view");
...@@ -315,7 +324,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR, int) ...@@ -315,7 +324,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR, int)
} // endif pn } // endif pn
Tablep = new(g) XTAB(tab, def); Tablep = new(g) XTAB(tab, def);
Tablep->SetQualifier(db); Tablep->SetSchema(db);
return false; return false;
} // end of DefineAM } // end of DefineAM
...@@ -379,12 +388,12 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) ...@@ -379,12 +388,12 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
LPCSTR cdb, curdb = hc->GetDBName(NULL); LPCSTR cdb, curdb = hc->GetDBName(NULL);
THD *thd = (hc->GetTable())->in_use; THD *thd = (hc->GetTable())->in_use;
db = (char*)tabp->GetQualifier(); db = (char*)(tabp->GetSchema() ? tabp->GetSchema() : curdb);
name = (char*)tabp->GetName(); name = (char*)tabp->GetName();
// Check for eventual loop // Check for eventual loop
for (PTABLE tp = To_Table; tp; tp = tp->Next) { for (PTABLE tp = To_Table; tp; tp = tp->Next) {
cdb = (tp->Qualifier) ? tp->Qualifier : curdb; cdb = (tp->Schema) ? tp->Schema : curdb;
if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) { if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) {
sprintf(g->Message, "Table %s.%s pointing on itself", db, name); sprintf(g->Message, "Table %s.%s pointing on itself", db, name);
...@@ -423,7 +432,7 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) ...@@ -423,7 +432,7 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
} // endif Define } // endif Define
if (db) if (db)
((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier()); ((PTDBMY)tdbp)->SetDatabase(tabp->GetSchema());
if (Mode == MODE_UPDATE || Mode == MODE_DELETE) if (Mode == MODE_UPDATE || Mode == MODE_DELETE)
tdbp->SetName(Name); // For Make_Command tdbp->SetName(Name); // For Make_Command
...@@ -757,7 +766,7 @@ void PRXCOL::WriteColumn(PGLOBAL g) ...@@ -757,7 +766,7 @@ void PRXCOL::WriteColumn(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
TDBTBC::TDBTBC(PPRXDEF tdp) : TDBCAT(tdp) TDBTBC::TDBTBC(PPRXDEF tdp) : TDBCAT(tdp)
{ {
Db = (PSZ)tdp->Tablep->GetQualifier(); Db = (PSZ)tdp->Tablep->GetSchema();
Tab = (PSZ)tdp->Tablep->GetName(); Tab = (PSZ)tdp->Tablep->GetName();
} // end of TDBTBC constructor } // end of TDBTBC constructor
......
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