Skip to content

Commit

Permalink
- Fix MDEV-9239. Meanwhile, make all references to the database in XT…
Browse files Browse the repository at this point in the history
…AB 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
  • Loading branch information
Buggynours committed Jan 9, 2016
1 parent 6883e5c commit 0891ae2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 42 deletions.
31 changes: 17 additions & 14 deletions storage/connect/mycat.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) Olivier Bertrand 2004 - 2015
/* Copyright (C) Olivier Bertrand 2004 - 2016
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
Expand All @@ -18,7 +18,7 @@
/* ------------- */
/* Version 1.4 */
/* */
/* Author: Olivier Bertrand 2012 - 2015 */
/* Author: Olivier Bertrand 2012 - 2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
Expand Down Expand Up @@ -509,30 +509,33 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
/* GetTableDesc: retrieve a table descriptor. */
/* 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 *)
{
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 (!type)
type= Hc->GetStringOption("Type","*");

return MakeTableDesc(g, name, type);
return MakeTableDesc(g, tablep, type);
} // end of GetTableDesc

/***********************************************************************/
/* MakeTableDesc: make a table/view description. */
/* 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;
LPCSTR name = (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema());
PRELDEF tdp= NULL;

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. */
Expand Down Expand Up @@ -571,11 +574,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch

// 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;

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

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

// Look for the description of the requested table
tdp= GetTableDesc(g, name, type);
tdp= GetTableDesc(g, tablep, type);

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

if (tablep->GetQualifier())
tdp->Database = SetPath(g, tablep->GetQualifier());
if (tablep->GetSchema())
tdp->Database = SetPath(g, tablep->GetSchema());

tdbp= tdp->GetTable(g, mode);
} // endif tdp
Expand Down
10 changes: 6 additions & 4 deletions storage/connect/mycat.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ class MYCAT : public CATALOG {
//void SetDataPath(PGLOBAL g, const char *path)
// {SetPath(g, &DataPath, path);}
bool StoreIndex(PGLOBAL, PTABDEF) {return false;} // Temporary
PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
LPCSTR type, PRELDEF *prp = NULL);
// PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name,
PRELDEF GetTableDesc(PGLOBAL g, PTABLE tablep,
LPCSTR type, PRELDEF *prp = NULL);
PTDB GetTable(PGLOBAL g, PTABLE tablep,
MODE mode = MODE_READ, LPCSTR type = NULL);
void ClearDB(PGLOBAL g);

protected:
PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);
// PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am);
PRELDEF MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am);
//void SetPath(PGLOBAL g, LPCSTR *datapath, const char *path);

// Members
ha_connect *Hc; // The Connect handler
Expand Down
13 changes: 8 additions & 5 deletions storage/connect/reldef.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/************* RelDef CPP Program Source Code File (.CPP) **************/
/* PROGRAM NAME: RELDEF */
/* ------------- */
/* Version 1.4 */
/* Version 1.5 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 2004-2015 */
/* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
Expand Down Expand Up @@ -37,6 +37,7 @@
#include "plgdbsem.h"
#include "reldef.h"
#include "colblk.h"
#include "tabcol.h"
#include "filamap.h"
#include "filamfix.h"
#include "filamvct.h"
Expand Down Expand Up @@ -217,11 +218,13 @@ TABDEF::TABDEF(void)
/***********************************************************************/
/* 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;

Name = (PSZ)PlugDup(g, name);
Name = (PSZ)name;
Schema = (PSZ)schema;
Cat = cat;
Hc = ((MYCAT*)cat)->GetHandler();
Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL));
Expand Down Expand Up @@ -569,7 +572,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
} // endif Cbuf

// 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;

// Ok, return external block
Expand Down
12 changes: 7 additions & 5 deletions storage/connect/reldef.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*************** 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. */
/***********************************************************************/
Expand Down Expand Up @@ -50,7 +50,8 @@ class DllExport RELDEF : public BLOCK { // Relation definition block
int GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size);
char *GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef);
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;

protected:
Expand Down Expand Up @@ -97,8 +98,9 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
int GetColCatInfo(PGLOBAL g);
void SetIndexInfo(void);
bool DropTable(PGLOBAL g, PSZ name);
virtual bool Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am);
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;
virtual bool Define(PGLOBAL g, PCATLG cat,
LPCSTR name, LPCSTR schema, LPCSTR am);
virtual bool DefineAM(PGLOBAL, LPCSTR, int) = 0;

protected:
// Members
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/tabmysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
Delayed = !!GetIntCatInfo("Delayed", 0);
} else {
// MYSQL access from a PROXY table
Database = GetStringCatInfo(g, "Database", "*");
Database = GetStringCatInfo(g, "Database", Schema ? Schema : "*");
Isview = GetBoolCatInfo("View", false);

// We must get other connection parms from the calling table
Expand Down
4 changes: 2 additions & 2 deletions storage/connect/tabpivot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bool PIVOTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
return TRUE;

Tabname = (char*)Tablep->GetName();
DB = (char*)Tablep->GetQualifier();
DB = (char*)Tablep->GetSchema();
Tabsrc = (char*)Tablep->GetSrc();

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

tablep->SetQualifier(Database);
tablep->SetSchema(Database);

if (!(Tdbp = GetSubTable(g, tablep, true)))
return true;
Expand Down
6 changes: 3 additions & 3 deletions storage/connect/tabtbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to PlugDB Software Development 2008-2015 */
/* (C) Copyright to PlugDB Software Development 2008-2016 */
/* Author: Olivier BERTRAND */
/* */
/* WHAT THIS PROGRAM DOES: */
Expand Down Expand Up @@ -130,10 +130,10 @@ bool TBLDEF::DefineAM(PGLOBAL g, LPCSTR, int)

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

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
if (Tablep)
Expand Down
25 changes: 17 additions & 8 deletions storage/connect/tabutil.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/************* Tabutil cpp Declares Source Code File (.CPP) ************/
/* 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. */
/***********************************************************************/
Expand Down Expand Up @@ -118,7 +118,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
FLD_LENGTH, FLD_SCALE, FLD_RADIX, FLD_NULL,
FLD_REM, FLD_NO, FLD_CHARSET};
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 prec, len, type, scale;
int zconv = GetConvSize();
Expand All @@ -130,7 +130,16 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
PCOLRES crp;

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;
} else if (s->is_view) {
strcpy(g->Message, "Use MYSQL type to see columns from a view");
Expand Down Expand Up @@ -315,7 +324,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR, int)
} // endif pn

Tablep = new(g) XTAB(tab, def);
Tablep->SetQualifier(db);
Tablep->SetSchema(db);
return false;
} // end of DefineAM

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

db = (char*)tabp->GetQualifier();
db = (char*)(tabp->GetSchema() ? tabp->GetSchema() : curdb);
name = (char*)tabp->GetName();

// Check for eventual loop
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)) {
sprintf(g->Message, "Table %s.%s pointing on itself", db, name);
Expand Down Expand Up @@ -423,7 +432,7 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
} // endif Define

if (db)
((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier());
((PTDBMY)tdbp)->SetDatabase(tabp->GetSchema());

if (Mode == MODE_UPDATE || Mode == MODE_DELETE)
tdbp->SetName(Name); // For Make_Command
Expand Down Expand Up @@ -757,7 +766,7 @@ void PRXCOL::WriteColumn(PGLOBAL g)
/***********************************************************************/
TDBTBC::TDBTBC(PPRXDEF tdp) : TDBCAT(tdp)
{
Db = (PSZ)tdp->Tablep->GetQualifier();
Db = (PSZ)tdp->Tablep->GetSchema();
Tab = (PSZ)tdp->Tablep->GetName();
} // end of TDBTBC constructor

Expand Down

0 comments on commit 0891ae2

Please sign in to comment.