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" { ...@@ -193,12 +193,13 @@ extern "C" {
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
char *JvmPath; char *JvmPath;
char *ClassPath;
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#if defined(__WIN__) #if defined(__WIN__)
CRITICAL_SECTION parsec; // Used calling the Flex parser CRITICAL_SECTION parsec; // Used calling the Flex parser
#else // !__WIN__ #else // !__WIN__
pthread_mutex_t parmut; pthread_mutex_t parmut = PTHREAD_MUTEX_INITIALIZER;
#endif // !__WIN__ #endif // !__WIN__
/***********************************************************************/ /***********************************************************************/
...@@ -5156,7 +5157,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5156,7 +5157,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
PJPARM sjp= NULL; PJPARM sjp= NULL;
char *jpath= NULL;
char *driver= NULL; char *driver= NULL;
char *url= NULL; char *url= NULL;
char *tabtyp = NULL; char *tabtyp = NULL;
...@@ -5223,7 +5223,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5223,7 +5223,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0); cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0);
#endif #endif
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
jpath= GetListOption(g, "Jpath", topt->oplist, NULL);
driver= GetListOption(g, "Driver", topt->oplist, NULL); driver= GetListOption(g, "Driver", topt->oplist, NULL);
url= GetListOption(g, "URL", topt->oplist, NULL); url= GetListOption(g, "URL", topt->oplist, NULL);
tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL); tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL);
...@@ -5510,15 +5509,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5510,15 +5509,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case FNC_NO: case FNC_NO:
case FNC_COL: case FNC_COL:
if (src) { if (src) {
qrp= JDBCSrcCols(g, jpath, (char*)src, sjp); qrp= JDBCSrcCols(g, (char*)src, sjp);
src= NULL; // for next tests src= NULL; // for next tests
} else } else
qrp= JDBCColumns(g, jpath, shm, tab, NULL, qrp= JDBCColumns(g, shm, tab, NULL, mxr, fnc == FNC_COL, sjp);
mxr, fnc == FNC_COL, sjp);
break; break;
case FNC_TABLE: case FNC_TABLE:
qrp= JDBCTables(g, dsn, shm, tab, tabtyp, mxr, true, sjp); qrp= JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp);
break; break;
#if 0 #if 0
case FNC_DSN: case FNC_DSN:
...@@ -5526,7 +5524,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5526,7 +5524,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
break; break;
#endif // 0 #endif // 0
case FNC_DRIVER: case FNC_DRIVER:
qrp= JDBCDrivers(g, jpath, mxr, true); qrp= JDBCDrivers(g, mxr, true);
break; break;
default: default:
sprintf(g->Message, "invalid catfunc %s", fncn); sprintf(g->Message, "invalid catfunc %s", fncn);
...@@ -6853,6 +6851,12 @@ static MYSQL_SYSVAR_STR(jvm_path, JvmPath, ...@@ -6853,6 +6851,12 @@ static MYSQL_SYSVAR_STR(jvm_path, JvmPath,
"Path to the directory where is the JVM lib", "Path to the directory where is the JVM lib",
// check_jvm_path, update_jvm_path, // check_jvm_path, update_jvm_path,
NULL, NULL, NULL); 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 #endif // JDBC_SUPPORT
...@@ -6873,7 +6877,10 @@ static struct st_mysql_sys_var* connect_system_variables[]= { ...@@ -6873,7 +6877,10 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(errmsg_dir_path), MYSQL_SYSVAR(errmsg_dir_path),
#endif // XMSG #endif // XMSG
MYSQL_SYSVAR(json_grp_size), MYSQL_SYSVAR(json_grp_size),
#if defined(JDBC_SUPPORT)
MYSQL_SYSVAR(jvm_path), MYSQL_SYSVAR(jvm_path),
MYSQL_SYSVAR(class_path),
#endif // JDBC_SUPPORT
NULL NULL
}; };
......
...@@ -21,9 +21,9 @@ typedef struct jdbc_parms { ...@@ -21,9 +21,9 @@ typedef struct jdbc_parms {
char *JDBCCheckConnection(PGLOBAL g, char *dsn, int cop); char *JDBCCheckConnection(PGLOBAL g, char *dsn, int cop);
#endif // PROMPT_OK #endif // PROMPT_OK
//PQRYRES JDBCDataSources(PGLOBAL g, int maxres, bool info); //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); char *colpat, int maxres, bool info, PJPARM sop);
PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sop); PQRYRES JDBCSrcCols(PGLOBAL g, char *src, PJPARM sop);
PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat, PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat,
char *tabtyp, int maxres, bool info, PJPARM sop); 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);
...@@ -55,6 +55,7 @@ extern "C" HINSTANCE s_hModule; // Saved module handle ...@@ -55,6 +55,7 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
int GetConvSize(); int GetConvSize();
extern char *JvmPath; // The connect_jvm_path global variable value extern char *JvmPath; // The connect_jvm_path global variable value
extern char *ClassPath; // The connect_class_path global variable value
/***********************************************************************/ /***********************************************************************/
/* Static JDBConn objects. */ /* Static JDBConn objects. */
...@@ -213,8 +214,8 @@ static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db, ...@@ -213,8 +214,8 @@ static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db,
/* JDBCColumns: constructs the result blocks containing all columns */ /* JDBCColumns: constructs the result blocks containing all columns */
/* of a JDBC table that will be retrieved by GetData commands. */ /* of a JDBC table that will be retrieved by GetData commands. */
/***********************************************************************/ /***********************************************************************/
PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table, PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
char *colpat, int maxres, bool info, PJPARM sjp) int maxres, bool info, PJPARM sjp)
{ {
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT,
...@@ -236,7 +237,7 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table, ...@@ -236,7 +237,7 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
if (!info) { if (!info) {
jcp = new(g)JDBConn(g, NULL); jcp = new(g)JDBConn(g, NULL);
if (jcp->Open(jpath, sjp) != RC_OK) // openReadOnly + noJDBCdialog if (jcp->Open(sjp) != RC_OK) // openReadOnly + noJDBCdialog
return NULL; return NULL;
if (table && !strchr(table, '%')) { if (table && !strchr(table, '%')) {
...@@ -315,11 +316,11 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table, ...@@ -315,11 +316,11 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
/* JDBCSrcCols: constructs the result blocks containing the */ /* JDBCSrcCols: constructs the result blocks containing the */
/* description of all the columns of a Srcdef option. */ /* description of all the columns of a Srcdef option. */
/**************************************************************************/ /**************************************************************************/
PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sjp) PQRYRES JDBCSrcCols(PGLOBAL g, char *src, PJPARM sjp)
{ {
JDBConn *jcp = new(g)JDBConn(g, NULL); JDBConn *jcp = new(g)JDBConn(g, NULL);
if (jcp->Open(jpath, sjp)) if (jcp->Open(sjp))
return NULL; return NULL;
return jcp->GetMetaData(g, src); return jcp->GetMetaData(g, src);
...@@ -329,8 +330,8 @@ PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sjp) ...@@ -329,8 +330,8 @@ PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sjp)
/* JDBCTables: constructs the result blocks containing all tables in */ /* JDBCTables: constructs the result blocks containing all tables in */
/* an JDBC database that will be retrieved by GetData commands. */ /* an JDBC database that will be retrieved by GetData commands. */
/**************************************************************************/ /**************************************************************************/
PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat, PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
char *tabtyp, int maxres, bool info, PJPARM sjp) int maxres, bool info, PJPARM sjp)
{ {
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING}; TYPE_STRING, TYPE_STRING};
...@@ -352,7 +353,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat, ...@@ -352,7 +353,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
/**********************************************************************/ /**********************************************************************/
jcp = new(g)JDBConn(g, NULL); jcp = new(g)JDBConn(g, NULL);
if (jcp->Open(jpath, sjp) == RC_FX) if (jcp->Open(sjp) == RC_FX)
return NULL; return NULL;
if (!maxres) if (!maxres)
...@@ -429,7 +430,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat, ...@@ -429,7 +430,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
/* drivers available on the local host. */ /* drivers available on the local host. */
/* Called with info=true to have result column names. */ /* Called with info=true to have result column names. */
/*************************************************************************/ /*************************************************************************/
PQRYRES JDBCDrivers(PGLOBAL g, char *jpath, int maxres, bool info) PQRYRES JDBCDrivers(PGLOBAL g, int maxres, bool info)
{ {
int buftyp[] ={TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING}; int buftyp[] ={TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING};
XFLD fldtyp[] ={FLD_NAME, FLD_EXTRA, FLD_DEFAULT, FLD_REM }; XFLD fldtyp[] ={FLD_NAME, FLD_EXTRA, FLD_DEFAULT, FLD_REM };
...@@ -446,7 +447,7 @@ PQRYRES JDBCDrivers(PGLOBAL g, char *jpath, int maxres, bool info) ...@@ -446,7 +447,7 @@ PQRYRES JDBCDrivers(PGLOBAL g, char *jpath, int maxres, bool info)
if (!info) { if (!info) {
jcp = new(g) JDBConn(g, NULL); jcp = new(g) JDBConn(g, NULL);
if (jcp->Open(jpath, NULL) != RC_OK) if (jcp->Open(NULL) != RC_OK)
return NULL; return NULL;
if (!maxres) if (!maxres)
...@@ -796,12 +797,12 @@ bool JDBConn::GetJVM(PGLOBAL g) ...@@ -796,12 +797,12 @@ bool JDBConn::GetJVM(PGLOBAL g)
if (!LibJvm) { if (!LibJvm) {
char soname[512]; char soname[512];
#if defined(__WIN__)
if (JvmPath) if (JvmPath)
strcat(strcpy(soname, JvmPath), "\\jvm.dll"); strcat(strcpy(soname, JvmPath), "\\jvm.dll");
else else
strcpy(soname, "jvm.dll"); strcpy(soname, "jvm.dll");
#if defined(__WIN__)
// Load the desired shared library // Load the desired shared library
if (!(LibJvm = LoadLibrary(soname))) { if (!(LibJvm = LoadLibrary(soname))) {
char buf[256]; char buf[256];
...@@ -826,6 +827,11 @@ bool JDBConn::GetJVM(PGLOBAL g) ...@@ -826,6 +827,11 @@ bool JDBConn::GetJVM(PGLOBAL g)
#else // !__WIN__ #else // !__WIN__
const char *error = NULL; const char *error = NULL;
if (JvmPath)
strcat(strcpy(soname, JvmPath), "/libjvm.so");
else
strcpy(soname, "libjvm.so");
// Load the desired shared library // Load the desired shared library
if (!(LibJvm = dlopen(soname, RTLD_LAZY))) { if (!(LibJvm = dlopen(soname, RTLD_LAZY))) {
error = dlerror(); error = dlerror();
...@@ -835,7 +841,7 @@ bool JDBConn::GetJVM(PGLOBAL g) ...@@ -835,7 +841,7 @@ bool JDBConn::GetJVM(PGLOBAL g)
sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_CreateJavaVM", SVP(error)); sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_CreateJavaVM", SVP(error));
dlclose(LibJvm); dlclose(LibJvm);
LibJvm = NULL; LibJvm = NULL;
} else if (!(GetCreatedJavaVMs = (CRTJVM)dlsym(LibJvm, "JNI_GetCreatedJavaVMs"))) { } else if (!(GetCreatedJavaVMs = (GETJVM)dlsym(LibJvm, "JNI_GetCreatedJavaVMs"))) {
error = dlerror(); error = dlerror();
sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_GetCreatedJavaVMs", SVP(error)); sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_GetCreatedJavaVMs", SVP(error));
dlclose(LibJvm); dlclose(LibJvm);
...@@ -851,14 +857,32 @@ bool JDBConn::GetJVM(PGLOBAL g) ...@@ -851,14 +857,32 @@ bool JDBConn::GetJVM(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
/* Open: connect to a data source. */ /* Open: connect to a data source. */
/***********************************************************************/ /***********************************************************************/
int JDBConn::Open(PSZ jpath, PJPARM sop) int JDBConn::Open(PJPARM sop)
{ {
PGLOBAL& g = m_G; PGLOBAL& g = m_G;
// Link or check whether jvm library was linked
if (GetJVM(g)) if (GetJVM(g))
return true; return true;
PSTRG jpop = new(g) STRING(g, 512, "-Djava.class.path="); // Firstly check whether the jvm was already created
JavaVM* jvms[1];
jsize jsz;
jint rc = GetCreatedJavaVMs(jvms, 1, &jsz);
if (rc == JNI_OK && jsz == 1) {
// jvm already existing
jvm = jvms[0];
rc = jvm->AttachCurrentThread((void**)&env, nullptr);
if (rc != JNI_OK) {
strcpy(g->Message, "Cannot attach jvm to the current thread");
return RC_FX;
} // endif rc
} else {
// Create a new jvm
PSTRG jpop = new(g)STRING(g, 512, "-Djava.class.path=");
char *cp = NULL; char *cp = NULL;
char sep; char sep;
...@@ -868,18 +892,6 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -868,18 +892,6 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
sep = ':'; sep = ':';
#endif #endif
if (sop) {
m_Driver = sop->Driver;
m_Url = sop->Url;
m_User = sop->User;
m_Pwd = sop->Pwd;
m_Scrollable = sop->Scrollable;
m_RowsetSize = sop->Fsize;
//m_LoginTimeout = sop->Cto;
//m_QueryTimeout = sop->Qto;
//m_UseCnc = sop->UseCnc;
} // endif sop
//================== prepare loading of Java VM ============================ //================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
...@@ -889,29 +901,29 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -889,29 +901,29 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
jpop->Append(cp); jpop->Append(cp);
if (trace) { if (trace) {
htrc("CLASSPATH=%s\n", cp); htrc("CLASSPATH=%s\n", getenv("CLASSPATH"));
htrc("jpath=%s\n", jpath); htrc("ClassPath=%s\n", ClassPath);
} // endif trace } // endif trace
if (jpath && *jpath) { if (ClassPath && *ClassPath) {
if (cp) if (cp)
jpop->Append(sep); jpop->Append(sep);
jpop->Append(jpath); jpop->Append(ClassPath);
} // endif jpath } // endif ClassPath
if (trace) if (trace)
htrc("%s\n", jpop->GetStr()); htrc("%s\n", jpop->GetStr());
options[0].optionString = jpop->GetStr(); options[0].optionString = jpop->GetStr();
//options[1].optionString = "-verbose:jni"; //options[1].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_6; // minimum Java version vm_args.version = JNI_VERSION_1_6; // minimum Java version
vm_args.nOptions = 1; // number of options vm_args.nOptions = 1; // number of options
vm_args.options = options; vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
//=============== load and initialize Java VM and JNI interface ============= //=============== load and initialize Java VM and JNI interface =============
jint rc = CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !! rc = CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
delete options; // we then no longer need the initialisation options. delete options; // we then no longer need the initialisation options.
switch (rc) { switch (rc) {
...@@ -932,24 +944,7 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -932,24 +944,7 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
return RC_FX; return RC_FX;
case JNI_EEXIST: case JNI_EEXIST:
strcpy(g->Message, "VM already created"); strcpy(g->Message, "VM already created");
{
JavaVM* jvms[1];
jsize jsz;
rc = GetCreatedJavaVMs(jvms, 1, &jsz);
if (rc == JNI_OK && jsz == 1) {
jvm = jvms[0];
rc = jvm->AttachCurrentThread((void**)&env, nullptr);
} // endif rc
} // end of block
if (rc == JNI_OK)
break;
else
return RC_FX; return RC_FX;
case JNI_EINVAL: case JNI_EINVAL:
strcpy(g->Message, "Invalid arguments"); strcpy(g->Message, "Invalid arguments");
return RC_FX; return RC_FX;
...@@ -958,6 +953,8 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -958,6 +953,8 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
return RC_FX; return RC_FX;
} // endswitch rc } // endswitch rc
} // endif rc
//=============== Display JVM version ======================================= //=============== Display JVM version =======================================
//jint ver = env->GetVersion(); //jint ver = env->GetVersion();
//cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl; //cout << ((ver>>16)&0x0f) << "."<<(ver&0x0f) << endl;
...@@ -970,6 +967,44 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -970,6 +967,44 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
return RC_FX; return RC_FX;
} // endif jdi } // endif jdi
#if 0 // Suppressed because it does not make any usable change
if (b && jpath && *jpath) {
// Try to add that path the the jvm class path
jmethodID alp = env->GetStaticMethodID(jdi, "addLibraryPath",
"(Ljava/lang/String;)I");
if (alp == nullptr) {
env->ExceptionDescribe();
env->ExceptionClear();
} else {
char *msg;
jstring path = env->NewStringUTF(jpath);
rc = env->CallStaticIntMethod(jdi, alp, path);
if ((msg = Check())) {
strcpy(g->Message, msg);
env->DeleteLocalRef(path);
return RC_FX;
} else switch (rc) {
case JNI_OK:
printf("jpath added\n");
break;
case JNI_EEXIST:
printf("jpath already exist\n");
break;
case JNI_ERR:
default:
strcpy(g->Message, "Error adding jpath");
env->DeleteLocalRef(path);
return RC_FX;
} // endswitch rc
env->DeleteLocalRef(path);
} // endif alp
} // endif jpath
#endif // 0
// if class found, continue // if class found, continue
jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V"); jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V");
...@@ -1003,6 +1038,18 @@ int JDBConn::Open(PSZ jpath, PJPARM sop) ...@@ -1003,6 +1038,18 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
jobjectArray parms = env->NewObjectArray(4, // constructs java array of 4 jobjectArray parms = env->NewObjectArray(4, // constructs java array of 4
env->FindClass("java/lang/String"), NULL); // Strings env->FindClass("java/lang/String"), NULL); // Strings
if (sop) {
m_Driver = sop->Driver;
m_Url = sop->Url;
m_User = sop->User;
m_Pwd = sop->Pwd;
m_Scrollable = sop->Scrollable;
m_RowsetSize = sop->Fsize;
//m_LoginTimeout = sop->Cto;
//m_QueryTimeout = sop->Qto;
//m_UseCnc = sop->UseCnc;
} // endif sop
// change some elements // change some elements
if (m_Driver) if (m_Driver)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(m_Driver)); env->SetObjectArrayElement(parms, 0, env->NewStringUTF(m_Driver));
......
...@@ -32,15 +32,6 @@ ...@@ -32,15 +32,6 @@
typedef unsigned char *PUCHAR; typedef unsigned char *PUCHAR;
#endif // !__WIN__ #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 { enum JCATINFO {
CAT_TAB = 1, // JDBC Tables CAT_TAB = 1, // JDBC Tables
CAT_COL = 2, // JDBC Columns CAT_COL = 2, // JDBC Columns
...@@ -82,7 +73,7 @@ class JDBConn : public BLOCK { ...@@ -82,7 +73,7 @@ class JDBConn : public BLOCK {
public: public:
JDBConn(PGLOBAL g, TDBJDBC *tdbp); JDBConn(PGLOBAL g, TDBJDBC *tdbp);
int Open(PSZ jpath, PJPARM sop); int Open(PJPARM sop);
int Rewind(char *sql); int Rewind(char *sql);
void Close(void); void Close(void);
PQRYRES AllocateResult(PGLOBAL g); PQRYRES AllocateResult(PGLOBAL g);
......
...@@ -5027,3 +5027,30 @@ void json_serialize_deinit(UDF_INIT* initid) ...@@ -5027,3 +5027,30 @@ void json_serialize_deinit(UDF_INIT* initid)
{ {
JsonFreeMem((PGLOBAL)initid->ptr); JsonFreeMem((PGLOBAL)initid->ptr);
} // end of json_serialize_deinit } // 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" { ...@@ -218,8 +218,12 @@ extern "C" {
DllExport my_bool json_serialize_init(UDF_INIT*, UDF_ARGS*, char*); DllExport my_bool json_serialize_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *json_serialize(UDF_EXEC_ARGS); DllExport char *json_serialize(UDF_EXEC_ARGS);
DllExport void json_serialize_deinit(UDF_INIT*); 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" } // extern "C"
/*********************************************************************************/ /*********************************************************************************/
/* Structure JPN. Used to make the locate path. */ /* Structure JPN. Used to make the locate path. */
/*********************************************************************************/ /*********************************************************************************/
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */ /* (C) Copyright to the author Olivier BERTRAND 1998-2016 */
/* */ /* */
/* WHAT THIS PROGRAM DOES: */ /* WHAT THIS PROGRAM DOES: */
/* ----------------------- */ /* ----------------------- */
......
...@@ -95,7 +95,7 @@ bool ExactInfo(void); ...@@ -95,7 +95,7 @@ bool ExactInfo(void);
/***********************************************************************/ /***********************************************************************/
JDBCDEF::JDBCDEF(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; 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;
...@@ -106,7 +106,6 @@ JDBCDEF::JDBCDEF(void) ...@@ -106,7 +106,6 @@ JDBCDEF::JDBCDEF(void)
/***********************************************************************/ /***********************************************************************/
bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{ {
Jpath = GetStringCatInfo(g, "Jpath", "");
Driver = GetStringCatInfo(g, "Driver", NULL); Driver = GetStringCatInfo(g, "Driver", NULL);
Desc = Url = GetStringCatInfo(g, "Connect", NULL); Desc = Url = GetStringCatInfo(g, "Connect", NULL);
...@@ -222,7 +221,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp) ...@@ -222,7 +221,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Cnp = NULL; Cnp = NULL;
if (tdp) { if (tdp) {
Jpath = tdp->Jpath;
Ops.Driver = tdp->Driver; Ops.Driver = tdp->Driver;
Ops.Url = tdp->Url; Ops.Url = tdp->Url;
TableName = tdp->Tabname; TableName = tdp->Tabname;
...@@ -241,7 +239,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp) ...@@ -241,7 +239,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Memory = tdp->Memory; Memory = tdp->Memory;
Ops.Scrollable = tdp->Scrollable; Ops.Scrollable = tdp->Scrollable;
} else { } else {
Jpath = NULL;
TableName = NULL; TableName = NULL;
Schema = NULL; Schema = NULL;
Ops.Driver = NULL; Ops.Driver = NULL;
...@@ -286,7 +283,6 @@ TDBJDBC::TDBJDBC(PTDBJDBC tdbp) : TDBASE(tdbp) ...@@ -286,7 +283,6 @@ TDBJDBC::TDBJDBC(PTDBJDBC tdbp) : TDBASE(tdbp)
{ {
Jcp = tdbp->Jcp; // is that right ? Jcp = tdbp->Jcp; // is that right ?
Cnp = tdbp->Cnp; Cnp = tdbp->Cnp;
Jpath = tdbp->Jpath;
TableName = tdbp->TableName; TableName = tdbp->TableName;
Schema = tdbp->Schema; Schema = tdbp->Schema;
Ops = tdbp->Ops; Ops = tdbp->Ops;
...@@ -684,7 +680,7 @@ int TDBJDBC::Cardinality(PGLOBAL g) ...@@ -684,7 +680,7 @@ int TDBJDBC::Cardinality(PGLOBAL g)
char qry[96], tbn[64]; char qry[96], tbn[64];
JDBConn *jcp = new(g)JDBConn(g, this); JDBConn *jcp = new(g)JDBConn(g, this);
if (jcp->Open(Jpath, &Ops) == RC_FX) if (jcp->Open(&Ops) == RC_FX)
return -1; return -1;
// Table name can be encoded in UTF-8 // Table name can be encoded in UTF-8
...@@ -795,7 +791,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g) ...@@ -795,7 +791,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g)
else if (Jcp->IsOpen()) else if (Jcp->IsOpen())
Jcp->Close(); Jcp->Close();
if (Jcp->Open(Jpath, &Ops) == RC_FX) if (Jcp->Open(&Ops) == RC_FX)
return true; return true;
else if (Quoted) else if (Quoted)
Quote = Jcp->GetQuoteChar(); Quote = Jcp->GetQuoteChar();
...@@ -1545,7 +1541,7 @@ bool TDBXJDC::OpenDB(PGLOBAL g) ...@@ -1545,7 +1541,7 @@ bool TDBXJDC::OpenDB(PGLOBAL g)
} else if (Jcp->IsOpen()) } else if (Jcp->IsOpen())
Jcp->Close(); Jcp->Close();
if (Jcp->Open(Jpath, &Ops) == RC_FX) if (Jcp->Open(&Ops) == RC_FX)
return true; return true;
Use = USE_OPEN; // Do it now in case we are recursively called Use = USE_OPEN; // Do it now in case we are recursively called
...@@ -1657,7 +1653,7 @@ void JSRCCOL::WriteColumn(PGLOBAL g) ...@@ -1657,7 +1653,7 @@ void JSRCCOL::WriteColumn(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBJDRV::GetResult(PGLOBAL g) PQRYRES TDBJDRV::GetResult(PGLOBAL g)
{ {
return JDBCDrivers(g, Jpath, Maxres, false); return JDBCDrivers(g, Maxres, false);
} // end of GetResult } // end of GetResult
/* ---------------------------TDBJTB class --------------------------- */ /* ---------------------------TDBJTB class --------------------------- */
...@@ -1667,7 +1663,6 @@ PQRYRES TDBJDRV::GetResult(PGLOBAL g) ...@@ -1667,7 +1663,6 @@ PQRYRES TDBJDRV::GetResult(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp) TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
{ {
Jpath = tdp->Jpath;
Schema = tdp->Tabschema; Schema = tdp->Tabschema;
Tab = tdp->Tabname; Tab = tdp->Tabname;
Tabtype = tdp->Tabtype; Tabtype = tdp->Tabtype;
...@@ -1684,7 +1679,7 @@ TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp) ...@@ -1684,7 +1679,7 @@ TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBJTB::GetResult(PGLOBAL g) 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 } // end of GetResult
/* --------------------------TDBJDBCL class -------------------------- */ /* --------------------------TDBJDBCL class -------------------------- */
...@@ -1694,7 +1689,7 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g) ...@@ -1694,7 +1689,7 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBJDBCL::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 } // end of GetResult
#if 0 #if 0
......
...@@ -31,7 +31,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */ ...@@ -31,7 +31,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
// Implementation // Implementation
virtual const char *GetType(void) { return "JDBC"; } virtual const char *GetType(void) { return "JDBC"; }
PSZ GetJpath(void) { return Jpath; }
PSZ GetTabname(void) { return Tabname; } PSZ GetTabname(void) { return Tabname; }
PSZ GetTabschema(void) { return Tabschema; } PSZ GetTabschema(void) { return Tabschema; }
PSZ GetTabcat(void) { return Tabcat; } PSZ GetTabcat(void) { return Tabcat; }
...@@ -48,7 +47,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */ ...@@ -48,7 +47,6 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
protected: protected:
// Members // Members
PSZ Jpath; /* Java class path */
PSZ Driver; /* JDBC driver */ PSZ Driver; /* JDBC driver */
PSZ Url; /* JDBC driver URL */ PSZ Url; /* JDBC driver URL */
PSZ Tabname; /* External table name */ PSZ Tabname; /* External table name */
...@@ -130,7 +128,6 @@ class TDBJDBC : public TDBASE { ...@@ -130,7 +128,6 @@ class TDBJDBC : public TDBASE {
JDBCCOL *Cnp; // Points to count(*) column JDBCCOL *Cnp; // Points to count(*) column
JDBCPARM Ops; // Additional parameters JDBCPARM Ops; // Additional parameters
PSTRG Query; // Constructed SQL query PSTRG Query; // Constructed SQL query
char *Jpath; // Java class path
char *TableName; // Points to JDBC table name char *TableName; // Points to JDBC table name
char *Schema; // Points to JDBC table Schema char *Schema; // Points to JDBC table Schema
char *User; // User connect info char *User; // User connect info
...@@ -282,7 +279,7 @@ class JSRCCOL : public JDBCCOL { ...@@ -282,7 +279,7 @@ class JSRCCOL : public JDBCCOL {
class TDBJDRV : public TDBCAT { class TDBJDRV : public TDBCAT {
public: public:
// Constructor // Constructor
TDBJDRV(PJDBCDEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres; Jpath = tdp->Jpath;} TDBJDRV(PJDBCDEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres;}
protected: protected:
// Specific routines // Specific routines
...@@ -290,7 +287,6 @@ class TDBJDRV : public TDBCAT { ...@@ -290,7 +287,6 @@ class TDBJDRV : public TDBCAT {
// Members // Members
int Maxres; // Returned lines limit int Maxres; // Returned lines limit
char *Jpath; // Java class path
}; // end of class TDBJDRV }; // end of class TDBJDRV
/***********************************************************************/ /***********************************************************************/
...@@ -306,7 +302,6 @@ class TDBJTB : public TDBJDRV { ...@@ -306,7 +302,6 @@ class TDBJTB : public TDBJDRV {
virtual PQRYRES GetResult(PGLOBAL g); virtual PQRYRES GetResult(PGLOBAL g);
// Members // Members
char *Jpath; // Points to Java classpath
char *Schema; // Points to schema name or NULL char *Schema; // Points to schema name or NULL
char *Tab; // Points to JDBC table name or pattern char *Tab; // Points to JDBC table name or pattern
char *Tabtype; // Points to JDBC table type 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