mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
- 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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -54,7 +54,8 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
|
||||
#endif // !__WIN__
|
||||
|
||||
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. */
|
||||
@@ -213,8 +214,8 @@ fin:
|
||||
/* JDBCColumns: constructs the result blocks containing all columns */
|
||||
/* of a JDBC table that will be retrieved by GetData commands. */
|
||||
/***********************************************************************/
|
||||
PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
|
||||
char *colpat, int maxres, bool info, PJPARM sjp)
|
||||
PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
|
||||
int maxres, bool info, PJPARM sjp)
|
||||
{
|
||||
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING,
|
||||
TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT,
|
||||
@@ -236,7 +237,7 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
|
||||
if (!info) {
|
||||
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;
|
||||
|
||||
if (table && !strchr(table, '%')) {
|
||||
@@ -315,11 +316,11 @@ PQRYRES JDBCColumns(PGLOBAL g, char *jpath, char *db, char *table,
|
||||
/* JDBCSrcCols: constructs the result blocks containing the */
|
||||
/* 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);
|
||||
|
||||
if (jcp->Open(jpath, sjp))
|
||||
if (jcp->Open(sjp))
|
||||
return NULL;
|
||||
|
||||
return jcp->GetMetaData(g, src);
|
||||
@@ -329,8 +330,8 @@ PQRYRES JDBCSrcCols(PGLOBAL g, char *jpath, char *src, PJPARM sjp)
|
||||
/* JDBCTables: constructs the result blocks containing all tables in */
|
||||
/* an JDBC database that will be retrieved by GetData commands. */
|
||||
/**************************************************************************/
|
||||
PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
|
||||
char *tabtyp, int maxres, bool info, PJPARM sjp)
|
||||
PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
|
||||
int maxres, bool info, PJPARM sjp)
|
||||
{
|
||||
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
|
||||
TYPE_STRING, TYPE_STRING};
|
||||
@@ -352,7 +353,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
|
||||
/**********************************************************************/
|
||||
jcp = new(g)JDBConn(g, NULL);
|
||||
|
||||
if (jcp->Open(jpath, sjp) == RC_FX)
|
||||
if (jcp->Open(sjp) == RC_FX)
|
||||
return NULL;
|
||||
|
||||
if (!maxres)
|
||||
@@ -429,7 +430,7 @@ PQRYRES JDBCTables(PGLOBAL g, char *jpath, char *db, char *tabpat,
|
||||
/* drivers available on the local host. */
|
||||
/* 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};
|
||||
XFLD fldtyp[] ={FLD_NAME, FLD_EXTRA, FLD_DEFAULT, FLD_REM };
|
||||
@@ -446,7 +447,7 @@ PQRYRES JDBCDrivers(PGLOBAL g, char *jpath, int maxres, bool info)
|
||||
if (!info) {
|
||||
jcp = new(g) JDBConn(g, NULL);
|
||||
|
||||
if (jcp->Open(jpath, NULL) != RC_OK)
|
||||
if (jcp->Open(NULL) != RC_OK)
|
||||
return NULL;
|
||||
|
||||
if (!maxres)
|
||||
@@ -796,12 +797,12 @@ bool JDBConn::GetJVM(PGLOBAL g)
|
||||
if (!LibJvm) {
|
||||
char soname[512];
|
||||
|
||||
#if defined(__WIN__)
|
||||
if (JvmPath)
|
||||
strcat(strcpy(soname, JvmPath), "\\jvm.dll");
|
||||
else
|
||||
strcpy(soname, "jvm.dll");
|
||||
|
||||
#if defined(__WIN__)
|
||||
// Load the desired shared library
|
||||
if (!(LibJvm = LoadLibrary(soname))) {
|
||||
char buf[256];
|
||||
@@ -826,6 +827,11 @@ bool JDBConn::GetJVM(PGLOBAL g)
|
||||
#else // !__WIN__
|
||||
const char *error = NULL;
|
||||
|
||||
if (JvmPath)
|
||||
strcat(strcpy(soname, JvmPath), "/libjvm.so");
|
||||
else
|
||||
strcpy(soname, "libjvm.so");
|
||||
|
||||
// Load the desired shared library
|
||||
if (!(LibJvm = dlopen(soname, RTLD_LAZY))) {
|
||||
error = dlerror();
|
||||
@@ -835,7 +841,7 @@ bool JDBConn::GetJVM(PGLOBAL g)
|
||||
sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_CreateJavaVM", SVP(error));
|
||||
dlclose(LibJvm);
|
||||
LibJvm = NULL;
|
||||
} else if (!(GetCreatedJavaVMs = (CRTJVM)dlsym(LibJvm, "JNI_GetCreatedJavaVMs"))) {
|
||||
} else if (!(GetCreatedJavaVMs = (GETJVM)dlsym(LibJvm, "JNI_GetCreatedJavaVMs"))) {
|
||||
error = dlerror();
|
||||
sprintf(g->Message, MSG(GET_FUNC_ERR), "JNI_GetCreatedJavaVMs", SVP(error));
|
||||
dlclose(LibJvm);
|
||||
@@ -851,112 +857,103 @@ bool JDBConn::GetJVM(PGLOBAL g)
|
||||
/***********************************************************************/
|
||||
/* Open: connect to a data source. */
|
||||
/***********************************************************************/
|
||||
int JDBConn::Open(PSZ jpath, PJPARM sop)
|
||||
int JDBConn::Open(PJPARM sop)
|
||||
{
|
||||
PGLOBAL& g = m_G;
|
||||
|
||||
// Link or check whether jvm library was linked
|
||||
if (GetJVM(g))
|
||||
return true;
|
||||
|
||||
PSTRG jpop = new(g) STRING(g, 512, "-Djava.class.path=");
|
||||
char *cp = NULL;
|
||||
char sep;
|
||||
// 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 sep;
|
||||
|
||||
#if defined(__WIN__)
|
||||
sep = ';';
|
||||
sep = ';';
|
||||
#else
|
||||
sep = ':';
|
||||
sep = ':';
|
||||
#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 ============================
|
||||
JavaVMInitArgs vm_args; // Initialization arguments
|
||||
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
|
||||
|
||||
//================== prepare loading of Java VM ============================
|
||||
JavaVMInitArgs vm_args; // Initialization arguments
|
||||
JavaVMOption* options = new JavaVMOption[1]; // JVM invocation options
|
||||
|
||||
// where to find java .class
|
||||
if ((cp = PlugDup(m_G, getenv("CLASSPATH"))))
|
||||
jpop->Append(cp);
|
||||
|
||||
if (trace) {
|
||||
htrc("CLASSPATH=%s\n", cp);
|
||||
htrc("jpath=%s\n", jpath);
|
||||
} // endif trace
|
||||
// where to find java .class
|
||||
if ((cp = PlugDup(m_G, getenv("CLASSPATH"))))
|
||||
jpop->Append(cp);
|
||||
|
||||
if (jpath && *jpath) {
|
||||
if (cp)
|
||||
jpop->Append(sep);
|
||||
if (trace) {
|
||||
htrc("CLASSPATH=%s\n", getenv("CLASSPATH"));
|
||||
htrc("ClassPath=%s\n", ClassPath);
|
||||
} // endif trace
|
||||
|
||||
jpop->Append(jpath);
|
||||
} // endif jpath
|
||||
if (ClassPath && *ClassPath) {
|
||||
if (cp)
|
||||
jpop->Append(sep);
|
||||
|
||||
if (trace)
|
||||
htrc("%s\n", jpop->GetStr());
|
||||
jpop->Append(ClassPath);
|
||||
} // endif ClassPath
|
||||
|
||||
options[0].optionString = jpop->GetStr();
|
||||
//options[1].optionString = "-verbose:jni";
|
||||
vm_args.version = JNI_VERSION_1_6; // minimum Java version
|
||||
vm_args.nOptions = 1; // number of options
|
||||
vm_args.options = options;
|
||||
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
|
||||
if (trace)
|
||||
htrc("%s\n", jpop->GetStr());
|
||||
|
||||
//=============== load and initialize Java VM and JNI interface =============
|
||||
jint rc = CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
|
||||
delete options; // we then no longer need the initialisation options.
|
||||
options[0].optionString = jpop->GetStr();
|
||||
//options[1].optionString = "-verbose:jni";
|
||||
vm_args.version = JNI_VERSION_1_6; // minimum Java version
|
||||
vm_args.nOptions = 1; // number of options
|
||||
vm_args.options = options;
|
||||
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
|
||||
|
||||
switch (rc) {
|
||||
case JNI_OK:
|
||||
strcpy(g->Message, "VM successfully created");
|
||||
break;
|
||||
case JNI_ERR:
|
||||
strcpy(g->Message, "Initialising JVM failed: unknown error");
|
||||
return RC_FX;
|
||||
case JNI_EDETACHED:
|
||||
strcpy(g->Message, "Thread detached from the VM");
|
||||
return RC_FX;
|
||||
case JNI_EVERSION:
|
||||
strcpy(g->Message, "JNI version error");
|
||||
return RC_FX;
|
||||
case JNI_ENOMEM:
|
||||
strcpy(g->Message, "Not enough memory");
|
||||
return RC_FX;
|
||||
case JNI_EEXIST:
|
||||
strcpy(g->Message, "VM already created");
|
||||
{
|
||||
JavaVM* jvms[1];
|
||||
jsize jsz;
|
||||
//=============== load and initialize Java VM and JNI interface =============
|
||||
rc = CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !!
|
||||
delete options; // we then no longer need the initialisation options.
|
||||
|
||||
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)
|
||||
switch (rc) {
|
||||
case JNI_OK:
|
||||
strcpy(g->Message, "VM successfully created");
|
||||
break;
|
||||
else
|
||||
case JNI_ERR:
|
||||
strcpy(g->Message, "Initialising JVM failed: unknown error");
|
||||
return RC_FX;
|
||||
case JNI_EDETACHED:
|
||||
strcpy(g->Message, "Thread detached from the VM");
|
||||
return RC_FX;
|
||||
case JNI_EVERSION:
|
||||
strcpy(g->Message, "JNI version error");
|
||||
return RC_FX;
|
||||
case JNI_ENOMEM:
|
||||
strcpy(g->Message, "Not enough memory");
|
||||
return RC_FX;
|
||||
case JNI_EEXIST:
|
||||
strcpy(g->Message, "VM already created");
|
||||
return RC_FX;
|
||||
case JNI_EINVAL:
|
||||
strcpy(g->Message, "Invalid arguments");
|
||||
return RC_FX;
|
||||
default:
|
||||
sprintf(g->Message, "Unknown return code %d", rc);
|
||||
return RC_FX;
|
||||
} // endswitch rc
|
||||
|
||||
case JNI_EINVAL:
|
||||
strcpy(g->Message, "Invalid arguments");
|
||||
return RC_FX;
|
||||
default:
|
||||
sprintf(g->Message, "Unknown return code %d", rc);
|
||||
return RC_FX;
|
||||
} // endswitch rc
|
||||
} // endif rc
|
||||
|
||||
//=============== Display JVM version =======================================
|
||||
//jint ver = env->GetVersion();
|
||||
@@ -970,6 +967,44 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
|
||||
return RC_FX;
|
||||
} // 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
|
||||
jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V");
|
||||
|
||||
@@ -1003,6 +1038,18 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
|
||||
jobjectArray parms = env->NewObjectArray(4, // constructs java array of 4
|
||||
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
|
||||
if (m_Driver)
|
||||
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(m_Driver));
|
||||
|
||||
@@ -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 @@ private:
|
||||
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 @@ public:
|
||||
|
||||
// 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 @@ public:
|
||||
|
||||
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 @@ protected:
|
||||
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 @@ protected:
|
||||
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 @@ protected:
|
||||
|
||||
// Members
|
||||
int Maxres; // Returned lines limit
|
||||
char *Jpath; // Java class path
|
||||
}; // end of class TDBJDRV
|
||||
|
||||
/***********************************************************************/
|
||||
@@ -306,7 +302,6 @@ protected:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user