Commit 80a204f2 authored by Olivier Bertrand's avatar Olivier Bertrand

- Try to fix MDEV-9950 (not tested yet)

  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/plgdbutl.cpp

- Fix Mdev-9997 (Sergey Vojtovitch)
  modified:   storage/connect/inihandl.c

- Try to have the JDBC type compiled by CMake
  modified:   storage/connect/CMakeLists.txt

- Fixing some bugs in the JDBC table type
  Use the CONNECTION option for the URL
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h
  modified:   storage/connect/tabjdbc.cpp

- Add the JdbcInterface.class to the project
  new file:   storage/connect/JdbcInterface.class
parent bbdeb911
......@@ -268,12 +268,14 @@ IF(CONNECT_WITH_JDBC)
# TODO: Find how to compile and install the JdbcInterface.java class
# Find required libraries and include directories
FIND_PACKAGE(JAVA)
FIND_PACKAGE(JNI)
FIND_PACKAGE(Java REQUIRED)
FIND_PACKAGE(JNI REQUIRED)
IF (JAVA_FOUND AND JNI_FOUND)
INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIR})
SET(JNI_LIBRARY ${JNI_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES} JdbcInterface.java
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY})
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
JdbcInterface.java JdbcInterface.class
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h)
add_definitions(-DJDBC_SUPPORT)
ELSE()
......
This diff was suppressed by a .gitattributes entry.
......@@ -536,7 +536,7 @@ public class JdbcInterface {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : null;
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
System.out.println(se);
} //end try/catch
......
......@@ -190,6 +190,12 @@ extern "C" {
} // extern "C"
#endif // XMSG
#if defined(__WIN__)
CRITICAL_SECTION parsec; // Used calling the Flex parser
#else // !__WIN__
pthread_mutex_t parmut;
#endif // !__WIN__
/***********************************************************************/
/* Utility functions. */
/***********************************************************************/
......@@ -634,6 +640,7 @@ static int connect_init_func(void *p)
#if defined(__WIN__)
sql_print_information("CONNECT: %s", compver);
InitializeCriticalSection((LPCRITICAL_SECTION)&parsec);
#else // !__WIN__
sql_print_information("CONNECT: %s", version);
#endif // !__WIN__
......@@ -678,8 +685,10 @@ static int connect_done_func(void *)
XmlCleanupParserLib();
#endif // LIBXML2_SUPPORT
#if !defined(__WIN__)
//PROFILE_End(); Causes signal 11
#if defined(__WIN__)
DeleteCriticalSection((LPCRITICAL_SECTION)&parsec);
#else // !__WIN__
PROFILE_End();
#endif // !__WIN__
for (pc= user_connect::to_users; pc; pc= pn) {
......@@ -5172,7 +5181,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
spc= (!sep) ? ',' : *sep;
qch= topt->qchar ? *topt->qchar : (signed)topt->quoted >= 0 ? '"' : 0;
hdr= (int)topt->header;
tbl= topt->tablist;
tbl= topt->tablist;
col= topt->colist;
if (topt->oplist) {
......@@ -5305,8 +5314,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_JDBC:
if (fnc & FNC_DRIVER) {
ok= true;
} else if (!url) {
strcpy(g->Message, "Missing URL");
} else if (!url && !(url= strz(g, create_info->connect_string))) {
strcpy(g->Message, "Missing URL");
} else {
// Store ODBC additional parameters
sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM));
......
......@@ -622,13 +622,16 @@ void PROFILE_End(void)
if (trace)
htrc("PROFILE_End: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES);
if (!CurProfile) // Sergey Vojtovich
return;
/* Close all opened files and free the cache structure */
for (i = 0; i < N_CACHED_PROFILES; i++) {
if (trace)
htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i);
CurProfile = MRUProfile[i];
PROFILE_ReleaseFile();
// CurProfile = MRUProfile[i]; Sergey Vojtovich
// PROFILE_ReleaseFile(); see MDEV-9997
free(MRUProfile[i]);
} // endfor i
......
......@@ -741,32 +741,33 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
// } // end of ~JDBConn
#if 0
/***********************************************************************/
/* Screen for errors. */
/***********************************************************************/
bool JDBConn::Check(RETCODE rc)
char *JDBConn::Check(void)
{
switch (rc) {
case SQL_SUCCESS_WITH_INFO:
if (trace) {
DJX x(rc);
if (x.BuildErrorMessage(this, m_hstmt))
htrc("JDBC Success With Info, hstmt=%p %s\n",
m_hstmt, x.GetErrorMessage(0));
} // endif trace
if (env->ExceptionCheck()) {
char *msg;
jthrowable exc = env->ExceptionOccurred();
jmethodID tid = env->GetMethodID(env->FindClass("java/lang/Object"),
"toString", "()Ljava/lang/String;");
if (exc != nullptr && tid != nullptr) {
jstring s = (jstring)env->CallObjectMethod(exc, tid);
const char *utf = env->GetStringUTFChars(s, (jboolean)false);
env->DeleteLocalRef(s);
msg = PlugDup(m_G, utf);
} else
msg = "Exception occured";
// Fall through
case SQL_SUCCESS:
case SQL_NO_DATA_FOUND:
return true;
} // endswitch rc
env->ExceptionClear();
return msg;
} // endif Check
return false;
return NULL;
} // end of Check
#if 0
/***********************************************************************/
/* Utility routine. */
/***********************************************************************/
......@@ -911,14 +912,10 @@ int JDBConn::Open(PSZ jpath, PJPARM sop)
rc = JNI_GetCreatedJavaVMs(jvms, 1, &jsz);
if (rc == JNI_OK && jsz == 1) {
JavaVMAttachArgs args;
args.version = JNI_VERSION_1_6;
args.name = NULL;
args.group = NULL;
jvm = jvms[0];
rc = jvm->AttachCurrentThread((void**)&env, &args);
rc = jvm->AttachCurrentThread((void**)&env, nullptr);
} // endif rc
} // end of block
if (rc == JNI_OK)
......@@ -1176,11 +1173,11 @@ void JDBConn::Close()
void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
{
PGLOBAL& g = m_G;
char *msg;
jint ctyp;
jlong dtv;
jstring cn, jn = nullptr;
jobject dob;
jthrowable exc;
jmethodID fldid = nullptr;
if (rank == 0)
......@@ -1191,14 +1188,8 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
ctyp = env->CallIntMethod(job, typid, rank, jn);
if ((exc = env->ExceptionOccurred()) != nullptr) {
jboolean isCopy = false;
jmethodID tid = env->GetMethodID(env->FindClass("java/lang/Object"), "toString", "()Ljava/lang/String;");
jstring s = (jstring)env->CallObjectMethod(exc, tid);
const char* utf = env->GetStringUTFChars(s, &isCopy);
sprintf(g->Message, "SetColumnValue: %s", utf);
env->DeleteLocalRef(s);
env->ExceptionClear();
if ((msg = Check())) {
sprintf(g->Message, "Getting ctyp: %s", msg);
longjmp(g->jumper[g->jump_level], TYPE_AM_JDBC);
} // endif Check
......@@ -1305,6 +1296,14 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
val->Reset();
} // endswitch Type
if ((msg = Check())) {
if (rank == 0)
env->DeleteLocalRef(jn);
sprintf(g->Message, "SetColumnValue: %s rank=%d ctyp=%d", msg, rank, (int)ctyp);
longjmp(g->jumper[g->jump_level], TYPE_AM_JDBC);
} // endif Check
if (rank == 0)
env->DeleteLocalRef(jn);
......@@ -1467,6 +1466,7 @@ int JDBConn::ExecuteSQL(void)
bool JDBConn::SetParam(JDBCCOL *colp)
{
PGLOBAL& g = m_G;
char *msg;
int rc = false;
PVAL val = colp->GetValue();
jint n, i = (jint)colp->GetRank();
......@@ -1477,7 +1477,6 @@ bool JDBConn::SetParam(JDBCCOL *colp)
jclass dat;
jobject datobj;
jstring jst = nullptr;
jthrowable exc;
jmethodID dtc, setid = nullptr;
switch (val->GetType()) {
......@@ -1531,7 +1530,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
setid = env->GetMethodID(jdi, "SetDoubleParm", "(ID)V");
if (setid == nullptr) {
strcpy(g->Message, "Cannot fing method SetDoubleParm");
strcpy(g->Message, "Cannot find method SetDoubleParm");
return true;
} // endif setid
......@@ -1565,16 +1564,10 @@ bool JDBConn::SetParam(JDBCCOL *colp)
return true;
} // endswitch Type
if ((exc = env->ExceptionOccurred()) != nullptr) {
jboolean isCopy = false;
jmethodID tid = env->GetMethodID(env->FindClass("java/lang/Object"), "toString", "()Ljava/lang/String;");
jstring s = (jstring)env->CallObjectMethod(exc, tid);
const char* utf = env->GetStringUTFChars(s, &isCopy);
sprintf(g->Message, "SetParam: %s", utf);
env->DeleteLocalRef(s);
env->ExceptionClear();
if ((msg = Check())) {
sprintf(g->Message, "SetParam: col=%s msg=%s", colp->GetName(), msg);
rc = true;
} // endif exc
} // endif msg
if (jst)
env->DeleteLocalRef(jst);
......@@ -1987,7 +1980,6 @@ bool JDBConn::SetParam(JDBCCOL *colp)
} // endfor n
// Now fetch the result
// Extended fetch cannot be used because of STRBLK's
for (i = 0; i < qrp->Maxres; i++) {
if ((rc = Fetch(0)) == 0)
break;
......@@ -2001,7 +1993,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
} // endfor i
if (rc == RC_OK)
if (rc > 0)
qrp->Truncated = true;
return i;
......
......@@ -123,7 +123,7 @@ class JDBConn : public BLOCK {
// JDBC operations
protected:
//bool Check(RETCODE rc);
char *Check(void);
//void ThrowDJX(int rc, PSZ msg/*, HSTMT hstmt = SQL_NULL_HSTMT*/);
//void ThrowDJX(PSZ msg);
//void AllocConnect(DWORD dwOptions);
......
......@@ -46,9 +46,9 @@
#else // !__WIN__
#include <unistd.h>
#include <fcntl.h>
#if defined(THREAD)
//#if defined(THREAD)
#include <pthread.h>
#endif // THREAD
//#endif // THREAD
#include <stdarg.h>
#define BIGMEM 2147483647 // Max int value
#endif // !__WIN__
......@@ -69,17 +69,6 @@
#include "valblk.h"
#include "rcmsg.h"
/***********************************************************************/
/* Macro or external routine definition */
/***********************************************************************/
#if defined(THREAD)
#if defined(__WIN__)
extern CRITICAL_SECTION parsec; // Used calling the Flex parser
#else // !__WIN__
extern pthread_mutex_t parmut;
#endif // !__WIN__
#endif // THREAD
/***********************************************************************/
/* DB static variables. */
/***********************************************************************/
......@@ -90,6 +79,12 @@ extern "C" {
extern char version[];
} // extern "C"
#if defined(__WIN__)
extern CRITICAL_SECTION parsec; // Used calling the Flex parser
#else // !__WIN__
extern pthread_mutex_t parmut;
#endif // !__WIN__
// The debug trace used by the main thread
FILE *pfile = NULL;
......@@ -702,21 +697,21 @@ PDTP MakeDateFormat(PGLOBAL g, PSZ dfmt, bool in, bool out, int flag)
/* Call the FLEX generated parser. In multi-threading mode the next */
/* instruction is included in an Enter/LeaveCriticalSection bracket. */
/*********************************************************************/
#if defined(THREAD)
//#if defined(THREAD)
#if defined(__WIN__)
EnterCriticalSection((LPCRITICAL_SECTION)&parsec);
#else // !__WIN__
pthread_mutex_lock(&parmut);
#endif // !__WIN__
#endif // THREAD
//#endif // THREAD
rc = fmdflex(pdp);
#if defined(THREAD)
//#if defined(THREAD)
#if defined(__WIN__)
LeaveCriticalSection((LPCRITICAL_SECTION)&parsec);
#else // !__WIN__
pthread_mutex_unlock(&parmut);
#endif // !__WIN__
#endif // THREAD
//#endif // THREAD
if (trace)
htrc("Done: in=%s out=%s rc=%d\n", SVP(pdp->InFmt), SVP(pdp->OutFmt), rc);
......
......@@ -108,11 +108,17 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
Jpath = GetStringCatInfo(g, "Jpath", "");
Driver = GetStringCatInfo(g, "Driver", NULL);
Desc = Url = GetStringCatInfo(g, "Url", NULL);
Desc = Url = GetStringCatInfo(g, "Connect", NULL);
if (!Url && !Catfunc) {
sprintf(g->Message, "Missing URL for JDBC table %s", Name);
return true;
// Look in the option list (deprecated)
Url = GetStringCatInfo(g, "Url", NULL);
if (!Url) {
sprintf(g->Message, "Missing URL for JDBC table %s", Name);
return true;
} // endif Url
} // endif Connect
Tabname = GetStringCatInfo(g, "Name",
......@@ -198,7 +204,7 @@ int JDBCPARM::CheckSize(int rows)
if (Url && rows == 1) {
// Are we connected to a MySQL JDBC connector?
bool b = (!strncmp(Url, "jdbc:mysql:", 11) ||
!strncmp(Url, "jdbc:mariadb:", 13));
!strncmp(Url, "jdbc:mariadb:", 13));
return b ? INT_MIN32 : rows;
} else
return rows;
......@@ -1669,6 +1675,8 @@ TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
Ops.Url = tdp->Url;
Ops.User = tdp->Username;
Ops.Pwd = tdp->Password;
Ops.Fsize = 0;
Ops.Scrollable = false;
} // end of TDBJTB constructor
/***********************************************************************/
......
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