Skip to content

Commit

Permalink
- Add column pattern and table type argument to catalog tables
Browse files Browse the repository at this point in the history
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/odbccat.h
  modified:   storage/connect/odbconn.cpp
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabjdbc.h
  modified:   storage/connect/tabodbc.cpp
  modified:   storage/connect/tabodbc.h

- Avoid longjump in AllocCatInfo functions
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/odbconn.cpp

- Change GetColumns error return value from 0 to -1
  modified:   storage/connect/JdbcInterface.class
  modified:   storage/connect/JdbcInterface.java
  • Loading branch information
Buggynours committed Jun 20, 2016
1 parent 7992dae commit 7e64b07
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 61 deletions.
Binary file modified storage/connect/JdbcInterface.class
Binary file not shown.
2 changes: 1 addition & 1 deletion storage/connect/JdbcInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public int GetMaxValue(int n) {
} // end of GetMaxValue

public int GetColumns(String[] parms) {
int ncol = 0;
int ncol = -1;

try {
if (rs != null) rs.close();
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5508,7 +5508,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,

break;
case FNC_TABLE:
qrp= ODBCTables(g, dsn, shm, tab, mxr, true, sop);
qrp= ODBCTables(g, dsn, shm, tab, NULL, mxr, true, sop);
break;
case FNC_DSN:
qrp= ODBCDataSources(g, mxr, true);
Expand Down
49 changes: 13 additions & 36 deletions storage/connect/jdbconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,42 +174,20 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db,
char *tab, PQRYRES qrp)
{
//size_t m, n;
JCATPARM *cap;

#if defined(_DEBUG)
assert(qrp);
#endif

// Save stack and allocation environment and prepare error return
if (g->jump_level == MAX_JUMP) {
strcpy(g->Message, MSG(TOO_MANY_JUMPS));
return NULL;
} // endif jump_level

if (setjmp(g->jumper[++g->jump_level]) != 0) {
printf("%s\n", g->Message);
cap = NULL;
goto fin;
} // endif rc

//m = (size_t)qrp->Maxres;
//n = (size_t)qrp->Nbcol;
cap = (JCATPARM *)PlugSubAlloc(g, NULL, sizeof(JCATPARM));
memset(cap, 0, sizeof(JCATPARM));
cap->Id = fid;
cap->Qrp = qrp;
cap->DB = (PUCHAR)db;
cap->Tab = (PUCHAR)tab;
//cap->Vlen = (SQLLEN* *)PlugSubAlloc(g, NULL, n * sizeof(SQLLEN *));
if ((cap = (JCATPARM *)PlgDBSubAlloc(g, NULL, sizeof(JCATPARM)))) {
memset(cap, 0, sizeof(JCATPARM));
cap->Id = fid;
cap->Qrp = qrp;
cap->DB = db;
cap->Tab = tab;
} // endif cap

//for (i = 0; i < n; i++)
// cap->Vlen[i] = (SQLLEN *)PlugSubAlloc(g, NULL, m * sizeof(SQLLEN));

//cap->Status = (UWORD *)PlugSubAlloc(g, NULL, m * sizeof(UWORD));

fin:
g->jump_level--;
return cap;
} // end of AllocCatInfo

Expand Down Expand Up @@ -291,7 +269,8 @@ PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp)))
return NULL;

cap->Pat = (PUCHAR)colpat;
// Colpat cannot be null or empty for some drivers
cap->Pat = (colpat && *colpat) ? colpat : "%";

/************************************************************************/
/* Now get the results into blocks. */
Expand Down Expand Up @@ -402,7 +381,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
return NULL;

cap->Pat = (PUCHAR)tabtyp;
cap->Pat = tabtyp;

if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
Expand Down Expand Up @@ -1931,9 +1910,9 @@ bool JDBConn::SetParam(JDBCCOL *colp)
{
PGLOBAL& g = m_G;
// void *buffer;
int i;
int i, ncol;
PSZ fnc = "Unknown";
uint n, ncol;
uint n;
short len, tp;
int crow = 0;
PQRYRES qrp = cap->Qrp;
Expand All @@ -1956,9 +1935,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(name.ptr(2)));
env->SetObjectArrayElement(parms, 1, env->NewStringUTF(name.ptr(1)));
env->SetObjectArrayElement(parms, 2, env->NewStringUTF(name.ptr(0)));

if (cap->Pat)
env->SetObjectArrayElement(parms, 3, env->NewStringUTF((const char*)cap->Pat));
env->SetObjectArrayElement(parms, 3, env->NewStringUTF((const char*)cap->Pat));

// Now do call the proper JDBC API
switch (cap->Id) {
Expand Down
6 changes: 3 additions & 3 deletions storage/connect/jdbconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ enum JCATINFO {
typedef struct tagJCATPARM {
JCATINFO Id; // Id to indicate function
PQRYRES Qrp; // Result set pointer
PUCHAR DB; // Database (Schema)
PUCHAR Tab; // Table name or pattern
PUCHAR Pat; // Table type or column pattern
char *DB; // Database (Schema)
char *Tab; // Table name or pattern
char *Pat; // Table type or column pattern
} JCATPARM;

typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/odbccat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
char *colpat, int maxres, bool info, POPARM sop);
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop);
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
int maxres, bool info, POPARM sop);
char *tabtyp, int maxres, bool info, POPARM sop);
PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info);
4 changes: 2 additions & 2 deletions storage/connect/odbconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info)
/* an ODBC database that will be retrieved by GetData commands. */
/**************************************************************************/
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
int maxres, bool info, POPARM sop)
char *tabtyp, int maxres, bool info, POPARM sop)
{
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING};
Expand Down Expand Up @@ -668,7 +668,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
return NULL;

//cap->Pat = (PUCHAR)tabtyp;
cap->Pat = (PUCHAR)tabtyp;

if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
Expand Down
20 changes: 17 additions & 3 deletions storage/connect/tabjdbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool ExactInfo(void);
/***********************************************************************/
JDBCDEF::JDBCDEF(void)
{
Driver = Url = Tabname = Tabschema = Username = NULL;
Driver = Url = Tabname = Tabschema = Username = Colpat = NULL;
Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false;
Expand Down Expand Up @@ -237,7 +237,13 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL);
Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
Tabtype = GetStringCatInfo(g, "Tabtype", NULL);

if (Catfunc == FNC_COL)
Colpat = GetStringCatInfo(g, "Colpat", NULL);

if (Catfunc == FNC_TABLE)
Tabtype = GetStringCatInfo(g, "Tabtype", NULL);

Qrystr = GetStringCatInfo(g, "Query_String", "?");
Sep = GetStringCatInfo(g, "Separator", NULL);
Xsrc = GetBoolCatInfo("Execsrc", FALSE);
Expand Down Expand Up @@ -1787,12 +1793,20 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g)

/* --------------------------TDBJDBCL class -------------------------- */

/***********************************************************************/
/* TDBJDBCL class constructor. */
/***********************************************************************/
TDBJDBCL::TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp)
{
Colpat = tdp->Colpat;
} // end of TDBJDBCL constructor

/***********************************************************************/
/* GetResult: Get the list of JDBC table columns. */
/***********************************************************************/
PQRYRES TDBJDBCL::GetResult(PGLOBAL g)
{
return JDBCColumns(g, Schema, Tab, NULL, Maxres, false, &Ops);
return JDBCColumns(g, Schema, Tab, Colpat, Maxres, false, &Ops);
} // end of GetResult

#if 0
Expand Down
9 changes: 6 additions & 3 deletions storage/connect/tabjdbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
friend class TDBXJDC;
friend class TDBJDRV;
friend class TDBJTB;
friend class TDBJDBCL;
public:
// Constructor
JDBCDEF(void);
Expand Down Expand Up @@ -58,6 +59,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */
PSZ Tabtype; /* External table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */
Expand Down Expand Up @@ -317,14 +319,15 @@ class TDBJTB : public TDBJDRV {
class TDBJDBCL : public TDBJTB {
public:
// Constructor
TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp) {}
TDBJDBCL(PJDBCDEF tdp);

protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);

// No additional Members
}; // end of class TDBJCL
// Members
char *Colpat; // Points to catalog column pattern
}; // end of class TDBJDBCL

#if 0
/***********************************************************************/
Expand Down
27 changes: 21 additions & 6 deletions storage/connect/tabodbc.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/************* Tabodbc C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABODBC */
/* ------------- */
/* Version 3.0 */
/* Version 3.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
Expand Down Expand Up @@ -96,7 +96,7 @@ bool ExactInfo(void);
ODBCDEF::ODBCDEF(void)
{
Connect = Tabname = Tabschema = Username = Password = NULL;
Tabcat = Srcdef = Qchar = Qrystr = Sep = NULL;
Tabcat = Colpat = Srcdef = Qchar = Qrystr = Sep = NULL;
Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = UseCnc = false;
} // end of ODBCDEF constructor
Expand All @@ -120,7 +120,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Username = GetStringCatInfo(g, "User", NULL);
Username = GetStringCatInfo(g, "User", NULL);
Password = GetStringCatInfo(g, "Password", NULL);

if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Expand All @@ -141,7 +141,13 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Scrollable = GetBoolCatInfo("Scrollable", false)) && !Elemt)
Elemt = 1; // Cannot merge SQLFetch and SQLExtendedFetch

UseCnc = GetBoolCatInfo("UseDSN", false);
if (Catfunc == FNC_COL)
Colpat = GetStringCatInfo(g, "Colpat", NULL);

if (Catfunc == FNC_TABLE)
Tabtyp = GetStringCatInfo(g, "Tabtype", NULL);

UseCnc = GetBoolCatInfo("UseDSN", false);

// Memory was Boolean, it is now integer
if (!(Memory = GetIntCatInfo("Memory", 0)))
Expand Down Expand Up @@ -1768,6 +1774,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
Dsn = tdp->GetConnect();
Schema = tdp->GetTabschema();
Tab = tdp->GetTabname();
Tabtyp = tdp->Tabtyp;
Ops.User = tdp->Username;
Ops.Pwd = tdp->Password;
Ops.Cto = tdp->Cto;
Expand All @@ -1780,17 +1787,25 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
/***********************************************************************/
PQRYRES TDBOTB::GetResult(PGLOBAL g)
{
return ODBCTables(g, Dsn, Schema, Tab, Maxres, false, &Ops);
return ODBCTables(g, Dsn, Schema, Tab, Tabtyp, Maxres, false, &Ops);
} // end of GetResult

/* ---------------------------TDBOCL class --------------------------- */

/***********************************************************************/
/* TDBOCL class constructor. */
/***********************************************************************/
TDBOCL::TDBOCL(PODEF tdp) : TDBOTB(tdp)
{
Colpat = tdp->Colpat;
} // end of TDBOTB constructor

/***********************************************************************/
/* GetResult: Get the list of ODBC table columns. */
/***********************************************************************/
PQRYRES TDBOCL::GetResult(PGLOBAL g)
{
return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, false, &Ops);
return ODBCColumns(g, Dsn, Schema, Tab, Colpat, Maxres, false, &Ops);
} // end of GetResult

/* ------------------------ End of Tabodbc --------------------------- */
15 changes: 10 additions & 5 deletions storage/connect/tabodbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
friend class TDBXDBC;
friend class TDBDRV;
friend class TDBOTB;
public:
friend class TDBOCL;
public:
// Constructor
ODBCDEF(void);

Expand Down Expand Up @@ -54,7 +55,9 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */
PSZ Srcdef; /* The source table SQL definition */
PSZ Tabtyp; /* Catalog table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */
PSZ Sep; /* Decimal separator */
Expand Down Expand Up @@ -326,7 +329,8 @@ class TDBOTB : public TDBDRV {
char *Dsn; // Points to connection string
char *Schema; // Points to schema name or NULL
char *Tab; // Points to ODBC table name or pattern
ODBCPARM Ops; // Additional parameters
char *Tabtyp; // Points to ODBC table type
ODBCPARM Ops; // Additional parameters
}; // end of class TDBOTB

/***********************************************************************/
Expand All @@ -335,13 +339,14 @@ class TDBOTB : public TDBDRV {
class TDBOCL : public TDBOTB {
public:
// Constructor
TDBOCL(PODEF tdp) : TDBOTB(tdp) {}
TDBOCL(PODEF tdp);

protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);

// No additional Members
// Members
char *Colpat; // Points to column pattern
}; // end of class TDBOCL

#endif // !NODBC

0 comments on commit 7e64b07

Please sign in to comment.