Commit 7e64b079 authored by Olivier Bertrand's avatar Olivier Bertrand

- Add column pattern and table type argument to catalog tables

  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
parent 7992dae6
This diff was suppressed by a .gitattributes entry.
......@@ -307,7 +307,7 @@ public class JdbcInterface {
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
int ncol = -1;
try {
if (rs != null) rs.close();
......
......@@ -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);
......
......@@ -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));
if ((cap = (JCATPARM *)PlgDBSubAlloc(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 *));
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
......@@ -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. */
......@@ -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);
......@@ -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;
......@@ -1956,8 +1935,6 @@ 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));
// Now do call the proper JDBC API
......
......@@ -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 *);
......
......@@ -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);
......@@ -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};
......@@ -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);
......
......@@ -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;
......@@ -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);
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);
......@@ -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
......
......@@ -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);
......@@ -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 */
......@@ -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
/***********************************************************************/
......
/************* Tabodbc C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABODBC */
/* ------------- */
/* Version 3.0 */
/* Version 3.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
......@@ -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
......@@ -141,6 +141,12 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Scrollable = GetBoolCatInfo("Scrollable", false)) && !Elemt)
Elemt = 1; // Cannot merge SQLFetch and SQLExtendedFetch
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
......@@ -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;
......@@ -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 --------------------------- */
......@@ -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);
......@@ -54,6 +55,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */
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 */
......@@ -326,6 +329,7 @@ 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
char *Tabtyp; // Points to ODBC table type
ODBCPARM Ops; // Additional parameters
}; // end of class TDBOTB
......@@ -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
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