Commit 6aa163bc authored by Olivier Bertrand's avatar Olivier Bertrand

- Continue working on the JDBC table type

  Suppress the jpath option
  add the connect_jvm_path and connect_class_path global variables
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jdbccat.h
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/tabjdbc.h

- Add the envar UDF
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h

- Fix MDEV-9950
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/plgdbutl.cpp
parent 2323cf00
......@@ -193,12 +193,13 @@ extern "C" {
#if defined(JDBC_SUPPORT)
char *JvmPath;
char *ClassPath;
#endif // JDBC_SUPPORT
#if defined(__WIN__)
CRITICAL_SECTION parsec; // Used calling the Flex parser
#else // !__WIN__
pthread_mutex_t parmut;
pthread_mutex_t parmut = PTHREAD_MUTEX_INITIALIZER;
#endif // !__WIN__
/***********************************************************************/
......@@ -5156,7 +5157,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif // ODBC_SUPPORT
#if defined(JDBC_SUPPORT)
PJPARM sjp= NULL;
char *jpath= NULL;
char *driver= NULL;
char *url= NULL;
char *tabtyp = NULL;
......@@ -5223,7 +5223,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0);
#endif
#if defined(JDBC_SUPPORT)
jpath= GetListOption(g, "Jpath", topt->oplist, NULL);
driver= GetListOption(g, "Driver", topt->oplist, NULL);
url= GetListOption(g, "URL", topt->oplist, NULL);
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
......@@ -5510,15 +5509,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case FNC_NO:
case FNC_COL:
if (src) {
qrp= JDBCSrcCols(g, jpath, (char*)src, sjp);
qrp= JDBCSrcCols(g, (char*)src, sjp);
src= NULL; // for next tests
} else
qrp= JDBCColumns(g, jpath, shm, tab, NULL,
mxr, fnc == FNC_COL, sjp);
qrp= JDBCColumns(g, shm, tab, NULL, mxr, fnc == FNC_COL, sjp);
break;
case FNC_TABLE:
qrp= JDBCTables(g, dsn, shm, tab, tabtyp, mxr, true, sjp);
qrp= JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp);
break;
#if 0
case FNC_DSN:
......@@ -5526,7 +5524,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
break;
#endif // 0
case FNC_DRIVER:
qrp= JDBCDrivers(g, jpath, mxr, true);
qrp= JDBCDrivers(g, mxr, true);
break;
default:
sprintf(g->Message, "invalid catfunc %s", fncn);
......@@ -6853,6 +6851,12 @@ static MYSQL_SYSVAR_STR(jvm_path, JvmPath,
"Path to the directory where is the JVM lib",
// check_jvm_path, update_jvm_path,
NULL, NULL, NULL);
static MYSQL_SYSVAR_STR(class_path, ClassPath,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java class path",
// check_class_path, update_class_path,
NULL, NULL, NULL);
#endif // JDBC_SUPPORT
......@@ -6873,7 +6877,10 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(errmsg_dir_path),
#endif // XMSG
MYSQL_SYSVAR(json_grp_size),
#if defined(JDBC_SUPPORT)
MYSQL_SYSVAR(jvm_path),
MYSQL_SYSVAR(class_path),
#endif // JDBC_SUPPORT
NULL
};
......
......@@ -21,9 +21,9 @@ typedef struct jdbc_parms {
char *JDBCCheckConnection(PGLOBAL g, char *dsn, int cop);
#endif // PROMPT_OK
//PQRYRES JDBCDataSources(PGLOBAL g, int maxres, bool info);
PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table,
char *colpat, int maxres, bool info, PJPARM sop);
PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sop);
PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
PQRYRES JDBCSrcCols(PGLOBAL g, char *src, PJPARM sop);
PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat,
char *tabtyp, int maxres, bool info, PJPARM sop);
PQRYRES JDBCDrivers(PGLOBAL g, char *jpath, int maxres, bool info);
PQRYRES JDBCDrivers(PGLOBAL g, int maxres, bool info);
This diff is collapsed.
......@@ -32,15 +32,6 @@
typedef unsigned char *PUCHAR;
#endif // !__WIN__
// Field Flags, used to indicate status of fields
//efine SQL_FIELD_FLAG_DIRTY 0x1
//efine SQL_FIELD_FLAG_NULL 0x2
// Update options flags
//efine SQL_SETPOSUPDATES 0x0001
//efine SQL_POSITIONEDSQL 0x0002
//efine SQL_GDBOUND 0x0004
enum JCATINFO {
CAT_TAB = 1, // JDBC Tables
CAT_COL = 2, // JDBC Columns
......@@ -82,7 +73,7 @@ class JDBConn : public BLOCK {
public:
JDBConn(PGLOBAL g, TDBJDBC *tdbp);
int Open(PSZ jpath, PJPARM sop);
int Open(PJPARM sop);
int Rewind(char *sql);
void Close(void);
PQRYRES AllocateResult(PGLOBAL g);
......
......@@ -5027,3 +5027,30 @@ void json_serialize_deinit(UDF_INIT* initid)
{
JsonFreeMem((PGLOBAL)initid->ptr);
} // end of json_serialize_deinit
/*********************************************************************************/
/* Utility function returning an environment variable value. */
/*********************************************************************************/
my_bool envar_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 1) {
strcpy(message, "Unique argument must be an environment variable name");
return true;
} else
return false;
} // end of envar_init
char *envar(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *)
{
char *str, name[256];
int n = MY_MIN(args->lengths[0], sizeof(name) - 1);
memcpy(name, args->args[0], n);
name[n] = 0;
str = getenv(name);
*res_length = (str) ? strlen(str) : 0;
return str;
} // end of envar
......@@ -218,8 +218,12 @@ extern "C" {
DllExport my_bool json_serialize_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *json_serialize(UDF_EXEC_ARGS);
DllExport void json_serialize_deinit(UDF_INIT*);
DllExport my_bool envar_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *envar(UDF_EXEC_ARGS);
} // extern "C"
/*********************************************************************************/
/* Structure JPN. Used to make the locate path. */
/*********************************************************************************/
......
......@@ -5,7 +5,7 @@
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */
/* (C) Copyright to the author Olivier BERTRAND 1998-2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
......
......@@ -95,7 +95,7 @@ bool ExactInfo(void);
/***********************************************************************/
JDBCDEF::JDBCDEF(void)
{
Jpath = Driver = Url = Tabname = Tabschema = Username = NULL;
Driver = Url = Tabname = Tabschema = Username = NULL;
Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false;
......@@ -106,7 +106,6 @@ JDBCDEF::JDBCDEF(void)
/***********************************************************************/
bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
Jpath = GetStringCatInfo(g, "Jpath", "");
Driver = GetStringCatInfo(g, "Driver", NULL);
Desc = Url = GetStringCatInfo(g, "Connect", NULL);
......@@ -222,7 +221,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Cnp = NULL;
if (tdp) {
Jpath = tdp->Jpath;
Ops.Driver = tdp->Driver;
Ops.Url = tdp->Url;
TableName = tdp->Tabname;
......@@ -241,7 +239,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Memory = tdp->Memory;
Ops.Scrollable = tdp->Scrollable;
} else {
Jpath = NULL;
TableName = NULL;
Schema = NULL;
Ops.Driver = NULL;
......@@ -286,7 +283,6 @@ TDBJDBC::TDBJDBC(PTDBJDBC tdbp) : TDBASE(tdbp)
{
Jcp = tdbp->Jcp; // is that right ?
Cnp = tdbp->Cnp;
Jpath = tdbp->Jpath;
TableName = tdbp->TableName;
Schema = tdbp->Schema;
Ops = tdbp->Ops;
......@@ -684,7 +680,7 @@ int TDBJDBC::Cardinality(PGLOBAL g)
char qry[96], tbn[64];
JDBConn *jcp = new(g)JDBConn(g, this);
if (jcp->Open(Jpath, &Ops) == RC_FX)
if (jcp->Open(&Ops) == RC_FX)
return -1;
// Table name can be encoded in UTF-8
......@@ -795,7 +791,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g)
else if (Jcp->IsOpen())
Jcp->Close();
if (Jcp->Open(Jpath, &Ops) == RC_FX)
if (Jcp->Open(&Ops) == RC_FX)
return true;
else if (Quoted)
Quote = Jcp->GetQuoteChar();
......@@ -1545,7 +1541,7 @@ bool TDBXJDC::OpenDB(PGLOBAL g)
} else if (Jcp->IsOpen())
Jcp->Close();
if (Jcp->Open(Jpath, &Ops) == RC_FX)
if (Jcp->Open(&Ops) == RC_FX)
return true;
Use = USE_OPEN; // Do it now in case we are recursively called
......@@ -1657,7 +1653,7 @@ void JSRCCOL::WriteColumn(PGLOBAL g)
/***********************************************************************/
PQRYRES TDBJDRV::GetResult(PGLOBAL g)
{
return JDBCDrivers(g, Jpath, Maxres, false);
return JDBCDrivers(g, Maxres, false);
} // end of GetResult
/* ---------------------------TDBJTB class --------------------------- */
......@@ -1667,7 +1663,6 @@ PQRYRES TDBJDRV::GetResult(PGLOBAL g)
/***********************************************************************/
TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
{
Jpath = tdp->Jpath;
Schema = tdp->Tabschema;
Tab = tdp->Tabname;
Tabtype = tdp->Tabtype;
......@@ -1684,7 +1679,7 @@ TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
/***********************************************************************/
PQRYRES TDBJTB::GetResult(PGLOBAL g)
{
return JDBCTables(g, Jpath, Schema, Tab, Tabtype, Maxres, false, &Ops);
return JDBCTables(g, Schema, Tab, Tabtype, Maxres, false, &Ops);
} // end of GetResult
/* --------------------------TDBJDBCL class -------------------------- */
......@@ -1694,7 +1689,7 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g)
/***********************************************************************/
PQRYRES TDBJDBCL::GetResult(PGLOBAL g)
{
return JDBCColumns(g, Jpath, Schema, Tab, NULL, Maxres, false, &Ops);
return JDBCColumns(g, Schema, Tab, NULL, Maxres, false, &Ops);
} // end of GetResult
#if 0
......
......@@ -31,7 +31,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
// Implementation
virtual const char *GetType(void) { return "JDBC"; }
PSZ GetJpath(void) { return Jpath; }
PSZ GetTabname(void) { return Tabname; }
PSZ GetTabschema(void) { return Tabschema; }
PSZ GetTabcat(void) { return Tabcat; }
......@@ -48,7 +47,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
protected:
// Members
PSZ Jpath; /* Java class path */
PSZ Driver; /* JDBC driver */
PSZ Url; /* JDBC driver URL */
PSZ Tabname; /* External table name */
......@@ -130,7 +128,6 @@ class TDBJDBC : public TDBASE {
JDBCCOL *Cnp; // Points to count(*) column
JDBCPARM Ops; // Additional parameters
PSTRG Query; // Constructed SQL query
char *Jpath; // Java class path
char *TableName; // Points to JDBC table name
char *Schema; // Points to JDBC table Schema
char *User; // User connect info
......@@ -282,7 +279,7 @@ class JSRCCOL : public JDBCCOL {
class TDBJDRV : public TDBCAT {
public:
// Constructor
TDBJDRV(PJDBCDEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres; Jpath = tdp->Jpath;}
TDBJDRV(PJDBCDEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres;}
protected:
// Specific routines
......@@ -290,7 +287,6 @@ class TDBJDRV : public TDBCAT {
// Members
int Maxres; // Returned lines limit
char *Jpath; // Java class path
}; // end of class TDBJDRV
/***********************************************************************/
......@@ -306,7 +302,6 @@ class TDBJTB : public TDBJDRV {
virtual PQRYRES GetResult(PGLOBAL g);
// Members
char *Jpath; // Points to Java classpath
char *Schema; // Points to schema name or NULL
char *Tab; // Points to JDBC table name or pattern
char *Tabtype; // Points to JDBC table type
......
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