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 { ...@@ -307,7 +307,7 @@ public class JdbcInterface {
} // end of GetMaxValue } // end of GetMaxValue
public int GetColumns(String[] parms) { public int GetColumns(String[] parms) {
int ncol = 0; int ncol = -1;
try { try {
if (rs != null) rs.close(); if (rs != null) rs.close();
......
...@@ -5508,7 +5508,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5508,7 +5508,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
break; break;
case FNC_TABLE: case FNC_TABLE:
qrp= ODBCTables(g, dsn, shm, tab, mxr, true, sop); qrp= ODBCTables(g, dsn, shm, tab, NULL, mxr, true, sop);
break; break;
case FNC_DSN: case FNC_DSN:
qrp= ODBCDataSources(g, mxr, true); qrp= ODBCDataSources(g, mxr, true);
......
...@@ -174,42 +174,20 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v) ...@@ -174,42 +174,20 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db, static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db,
char *tab, PQRYRES qrp) char *tab, PQRYRES qrp)
{ {
//size_t m, n;
JCATPARM *cap; JCATPARM *cap;
#if defined(_DEBUG) #if defined(_DEBUG)
assert(qrp); assert(qrp);
#endif #endif
// Save stack and allocation environment and prepare error return if ((cap = (JCATPARM *)PlgDBSubAlloc(g, NULL, sizeof(JCATPARM)))) {
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)); memset(cap, 0, sizeof(JCATPARM));
cap->Id = fid; cap->Id = fid;
cap->Qrp = qrp; cap->Qrp = qrp;
cap->DB = (PUCHAR)db; cap->DB = db;
cap->Tab = (PUCHAR)tab; cap->Tab = tab;
//cap->Vlen = (SQLLEN* *)PlugSubAlloc(g, NULL, n * sizeof(SQLLEN *)); } // 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; return cap;
} // end of AllocCatInfo } // end of AllocCatInfo
...@@ -291,7 +269,8 @@ PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat, ...@@ -291,7 +269,8 @@ PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp))) if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp)))
return NULL; 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. */ /* Now get the results into blocks. */
...@@ -402,7 +381,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp, ...@@ -402,7 +381,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp))) if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
return NULL; return NULL;
cap->Pat = (PUCHAR)tabtyp; cap->Pat = tabtyp;
if (trace) if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol); htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
...@@ -1931,9 +1910,9 @@ bool JDBConn::SetParam(JDBCCOL *colp) ...@@ -1931,9 +1910,9 @@ bool JDBConn::SetParam(JDBCCOL *colp)
{ {
PGLOBAL& g = m_G; PGLOBAL& g = m_G;
// void *buffer; // void *buffer;
int i; int i, ncol;
PSZ fnc = "Unknown"; PSZ fnc = "Unknown";
uint n, ncol; uint n;
short len, tp; short len, tp;
int crow = 0; int crow = 0;
PQRYRES qrp = cap->Qrp; PQRYRES qrp = cap->Qrp;
...@@ -1956,8 +1935,6 @@ bool JDBConn::SetParam(JDBCCOL *colp) ...@@ -1956,8 +1935,6 @@ bool JDBConn::SetParam(JDBCCOL *colp)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(name.ptr(2))); env->SetObjectArrayElement(parms, 0, env->NewStringUTF(name.ptr(2)));
env->SetObjectArrayElement(parms, 1, env->NewStringUTF(name.ptr(1))); env->SetObjectArrayElement(parms, 1, env->NewStringUTF(name.ptr(1)));
env->SetObjectArrayElement(parms, 2, env->NewStringUTF(name.ptr(0))); 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 // Now do call the proper JDBC API
......
...@@ -46,9 +46,9 @@ enum JCATINFO { ...@@ -46,9 +46,9 @@ enum JCATINFO {
typedef struct tagJCATPARM { typedef struct tagJCATPARM {
JCATINFO Id; // Id to indicate function JCATINFO Id; // Id to indicate function
PQRYRES Qrp; // Result set pointer PQRYRES Qrp; // Result set pointer
PUCHAR DB; // Database (Schema) char *DB; // Database (Schema)
PUCHAR Tab; // Table name or pattern char *Tab; // Table name or pattern
PUCHAR Pat; // Table type or column pattern char *Pat; // Table type or column pattern
} JCATPARM; } JCATPARM;
typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *); typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
......
...@@ -21,5 +21,5 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, ...@@ -21,5 +21,5 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
char *colpat, int maxres, bool info, POPARM sop); char *colpat, int maxres, bool info, POPARM sop);
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop); PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop);
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, 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); PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info);
...@@ -606,7 +606,7 @@ PQRYRES ODBCDataSources(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. */ /* an ODBC database that will be retrieved by GetData commands. */
/**************************************************************************/ /**************************************************************************/
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, 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, int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING}; TYPE_STRING, TYPE_STRING};
...@@ -668,7 +668,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, ...@@ -668,7 +668,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp))) if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
return NULL; return NULL;
//cap->Pat = (PUCHAR)tabtyp; cap->Pat = (PUCHAR)tabtyp;
if (trace) if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol); htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
......
...@@ -96,7 +96,7 @@ bool ExactInfo(void); ...@@ -96,7 +96,7 @@ bool ExactInfo(void);
/***********************************************************************/ /***********************************************************************/
JDBCDEF::JDBCDEF(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; Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0; Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false; Scrollable = Xsrc = false;
...@@ -237,7 +237,13 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -237,7 +237,13 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat); Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL); Tabschema = GetStringCatInfo(g, "Dbname", NULL);
Tabschema = GetStringCatInfo(g, "Schema", Tabschema); Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
if (Catfunc == FNC_COL)
Colpat = GetStringCatInfo(g, "Colpat", NULL);
if (Catfunc == FNC_TABLE)
Tabtype = GetStringCatInfo(g, "Tabtype", NULL); Tabtype = GetStringCatInfo(g, "Tabtype", NULL);
Qrystr = GetStringCatInfo(g, "Query_String", "?"); Qrystr = GetStringCatInfo(g, "Query_String", "?");
Sep = GetStringCatInfo(g, "Separator", NULL); Sep = GetStringCatInfo(g, "Separator", NULL);
Xsrc = GetBoolCatInfo("Execsrc", FALSE); Xsrc = GetBoolCatInfo("Execsrc", FALSE);
...@@ -1787,12 +1793,20 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g) ...@@ -1787,12 +1793,20 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g)
/* --------------------------TDBJDBCL class -------------------------- */ /* --------------------------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. */ /* GetResult: Get the list of JDBC table columns. */
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBJDBCL::GetResult(PGLOBAL g) 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 } // end of GetResult
#if 0 #if 0
......
...@@ -26,6 +26,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */ ...@@ -26,6 +26,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
friend class TDBXJDC; friend class TDBXJDC;
friend class TDBJDRV; friend class TDBJDRV;
friend class TDBJTB; friend class TDBJTB;
friend class TDBJDBCL;
public: public:
// Constructor // Constructor
JDBCDEF(void); JDBCDEF(void);
...@@ -58,6 +59,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */ ...@@ -58,6 +59,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
PSZ Password; /* Password connect info */ PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */ PSZ Tabcat; /* External table catalog */
PSZ Tabtype; /* External table type */ PSZ Tabtype; /* External table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */ PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */ PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */ PSZ Qrystr; /* The original query */
...@@ -317,14 +319,15 @@ class TDBJTB : public TDBJDRV { ...@@ -317,14 +319,15 @@ class TDBJTB : public TDBJDRV {
class TDBJDBCL : public TDBJTB { class TDBJDBCL : public TDBJTB {
public: public:
// Constructor // Constructor
TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp) {} TDBJDBCL(PJDBCDEF tdp);
protected: protected:
// Specific routines // Specific routines
virtual PQRYRES GetResult(PGLOBAL g); virtual PQRYRES GetResult(PGLOBAL g);
// No additional Members // Members
}; // end of class TDBJCL char *Colpat; // Points to catalog column pattern
}; // end of class TDBJDBCL
#if 0 #if 0
/***********************************************************************/ /***********************************************************************/
......
/************* Tabodbc C++ Program Source Code File (.CPP) *************/ /************* Tabodbc C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABODBC */ /* PROGRAM NAME: TABODBC */
/* ------------- */ /* ------------- */
/* Version 3.0 */ /* Version 3.1 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -96,7 +96,7 @@ bool ExactInfo(void); ...@@ -96,7 +96,7 @@ bool ExactInfo(void);
ODBCDEF::ODBCDEF(void) ODBCDEF::ODBCDEF(void)
{ {
Connect = Tabname = Tabschema = Username = Password = NULL; 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; Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = UseCnc = false; Scrollable = Xsrc = UseCnc = false;
} // end of ODBCDEF constructor } // end of ODBCDEF constructor
...@@ -141,6 +141,12 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -141,6 +141,12 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Scrollable = GetBoolCatInfo("Scrollable", false)) && !Elemt) if ((Scrollable = GetBoolCatInfo("Scrollable", false)) && !Elemt)
Elemt = 1; // Cannot merge SQLFetch and SQLExtendedFetch 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); UseCnc = GetBoolCatInfo("UseDSN", false);
// Memory was Boolean, it is now integer // Memory was Boolean, it is now integer
...@@ -1768,6 +1774,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) ...@@ -1768,6 +1774,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
Dsn = tdp->GetConnect(); Dsn = tdp->GetConnect();
Schema = tdp->GetTabschema(); Schema = tdp->GetTabschema();
Tab = tdp->GetTabname(); Tab = tdp->GetTabname();
Tabtyp = tdp->Tabtyp;
Ops.User = tdp->Username; Ops.User = tdp->Username;
Ops.Pwd = tdp->Password; Ops.Pwd = tdp->Password;
Ops.Cto = tdp->Cto; Ops.Cto = tdp->Cto;
...@@ -1780,17 +1787,25 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) ...@@ -1780,17 +1787,25 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBOTB::GetResult(PGLOBAL g) 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 } // end of GetResult
/* ---------------------------TDBOCL class --------------------------- */ /* ---------------------------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. */ /* GetResult: Get the list of ODBC table columns. */
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBOCL::GetResult(PGLOBAL g) 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 GetResult
/* ------------------------ End of Tabodbc --------------------------- */ /* ------------------------ End of Tabodbc --------------------------- */
...@@ -25,7 +25,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ ...@@ -25,7 +25,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
friend class TDBXDBC; friend class TDBXDBC;
friend class TDBDRV; friend class TDBDRV;
friend class TDBOTB; friend class TDBOTB;
public: friend class TDBOCL;
public:
// Constructor // Constructor
ODBCDEF(void); ODBCDEF(void);
...@@ -54,6 +55,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ ...@@ -54,6 +55,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
PSZ Username; /* User connect name */ PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */ PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */ PSZ Tabcat; /* External table catalog */
PSZ Tabtyp; /* Catalog table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */ PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */ PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */ PSZ Qrystr; /* The original query */
...@@ -326,6 +329,7 @@ class TDBOTB : public TDBDRV { ...@@ -326,6 +329,7 @@ class TDBOTB : public TDBDRV {
char *Dsn; // Points to connection string char *Dsn; // Points to connection string
char *Schema; // Points to schema name or NULL char *Schema; // Points to schema name or NULL
char *Tab; // Points to ODBC table name or pattern char *Tab; // Points to ODBC table name or pattern
char *Tabtyp; // Points to ODBC table type
ODBCPARM Ops; // Additional parameters ODBCPARM Ops; // Additional parameters
}; // end of class TDBOTB }; // end of class TDBOTB
...@@ -335,13 +339,14 @@ class TDBOTB : public TDBDRV { ...@@ -335,13 +339,14 @@ class TDBOTB : public TDBDRV {
class TDBOCL : public TDBOTB { class TDBOCL : public TDBOTB {
public: public:
// Constructor // Constructor
TDBOCL(PODEF tdp) : TDBOTB(tdp) {} TDBOCL(PODEF tdp);
protected: protected:
// Specific routines // Specific routines
virtual PQRYRES GetResult(PGLOBAL g); virtual PQRYRES GetResult(PGLOBAL g);
// No additional Members // Members
char *Colpat; // Points to column pattern
}; // end of class TDBOCL }; // end of class TDBOCL
#endif // !NODBC #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