Commit c92f2606 authored by Olivier Bertrand's avatar Olivier Bertrand

Commit changes made from 10.1

parent 4a1ffc38
...@@ -119,6 +119,7 @@ ...@@ -119,6 +119,7 @@
#undef OFFSET #undef OFFSET
#define NOPARSE #define NOPARSE
#define NJDBC
#if defined(UNIX) #if defined(UNIX)
#include "osutil.h" #include "osutil.h"
#endif // UNIX #endif // UNIX
...@@ -128,7 +129,7 @@ ...@@ -128,7 +129,7 @@
#include "odbccat.h" #include "odbccat.h"
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
#include "jdbccat.h" #include "tabjdbc.h"
#include "jdbconn.h" #include "jdbconn.h"
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
#include "xtable.h" #include "xtable.h"
...@@ -5224,7 +5225,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5224,7 +5225,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#endif #endif
#if defined(JDBC_SUPPORT) #if defined(JDBC_SUPPORT)
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);
#endif // JDBC_SUPPORT #endif // JDBC_SUPPORT
mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0")); mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
...@@ -5325,18 +5326,31 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5325,18 +5326,31 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_JDBC: case TAB_JDBC:
if (fnc & FNC_DRIVER) { if (fnc & FNC_DRIVER) {
ok= true; ok= true;
} else if (!url && !(url= strz(g, create_info->connect_string))) { } else if (!(url= strz(g, create_info->connect_string))) {
strcpy(g->Message, "Missing URL"); strcpy(g->Message, "Missing URL");
} else { } else {
// Store ODBC additional parameters // Store JDBC additional parameters
int rc;
PJDBCDEF jdef= new(g) JDBCDEF();
jdef->SetName(create_info->alias);
sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM)); sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM));
sjp->Driver= driver; sjp->Driver= driver;
sjp->Url= url;
sjp->User= (char*)user;
sjp->Pwd= (char*)pwd;
sjp->Fsize= 0; sjp->Fsize= 0;
sjp->Scrollable= false; sjp->Scrollable= false;
ok= true;
if ((rc = jdef->ParseURL(g, url, false)) == RC_OK) {
sjp->Url= url;
sjp->User= (char*)user;
sjp->Pwd= (char*)pwd;
ok= true;
} else if (rc == RC_NF) {
if (jdef->GetTabname())
tab= jdef->GetTabname();
ok= jdef->SetParms(sjp);
} // endif rc
} // endif's } // endif's
supfnc |= (FNC_DRIVER | FNC_TABLE); supfnc |= (FNC_DRIVER | FNC_TABLE);
...@@ -5775,12 +5789,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ...@@ -5775,12 +5789,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
switch (typ) { switch (typ) {
case TYPE_DOUBLE: case TYPE_DOUBLE:
case TYPE_DECIM:
// Some data sources do not count dec in length (prec) // Some data sources do not count dec in length (prec)
prec += (dec + 2); // To be safe prec += (dec + 2); // To be safe
break; break;
case TYPE_DECIM:
prec= len;
break;
default: default:
dec= 0; dec= 0;
} // endswitch typ } // endswitch typ
......
This diff is collapsed.
...@@ -53,6 +53,9 @@ typedef struct tagJCATPARM { ...@@ -53,6 +53,9 @@ typedef struct tagJCATPARM {
typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *); typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
typedef jint(JNICALL *GETJVM) (JavaVM **, jsize, jsize *); typedef jint(JNICALL *GETJVM) (JavaVM **, jsize, jsize *);
#if defined(_DEBUG)
typedef jint(JNICALL *GETDEF) (void *);
#endif // _DEBUG
// JDBC connection to a data source // JDBC connection to a data source
class TDBJDBC; class TDBJDBC;
...@@ -109,8 +112,15 @@ class JDBConn : public BLOCK { ...@@ -109,8 +112,15 @@ class JDBConn : public BLOCK {
public: public:
// Set static variables // Set static variables
static void SetJVM(void) static void SetJVM(void) {
{ LibJvm = NULL; CreateJavaVM = NULL; GetCreatedJavaVMs = NULL; } LibJvm = NULL;
CreateJavaVM = NULL;
GetCreatedJavaVMs = NULL;
#if defined(_DEBUG)
GetDefaultJavaVMInitArgs = NULL;
#endif // _DEBUG
} // end of SetJVM
static void ResetJVM(void); static void ResetJVM(void);
static bool GetJVM(PGLOBAL g); static bool GetJVM(PGLOBAL g);
...@@ -120,7 +130,8 @@ class JDBConn : public BLOCK { ...@@ -120,7 +130,8 @@ class JDBConn : public BLOCK {
// JDBC operations // JDBC operations
protected: protected:
char *Check(void); bool gmID(PGLOBAL g, jmethodID& mid, const char *name, const char *sig);
bool Check(jint rc = 0);
//void ThrowDJX(int rc, PSZ msg/*, HSTMT hstmt = SQL_NULL_HSTMT*/); //void ThrowDJX(int rc, PSZ msg/*, HSTMT hstmt = SQL_NULL_HSTMT*/);
//void ThrowDJX(PSZ msg); //void ThrowDJX(PSZ msg);
//void Free(void); //void Free(void);
...@@ -134,6 +145,9 @@ class JDBConn : public BLOCK { ...@@ -134,6 +145,9 @@ class JDBConn : public BLOCK {
#endif // !__WIN__ #endif // !__WIN__
static CRTJVM CreateJavaVM; static CRTJVM CreateJavaVM;
static GETJVM GetCreatedJavaVMs; static GETJVM GetCreatedJavaVMs;
#if defined(_DEBUG)
static GETDEF GetDefaultJavaVMInitArgs;
#endif // _DEBUG
PGLOBAL m_G; PGLOBAL m_G;
TDBJDBC *m_Tdb; TDBJDBC *m_Tdb;
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine) JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
...@@ -150,9 +164,17 @@ class JDBConn : public BLOCK { ...@@ -150,9 +164,17 @@ class JDBConn : public BLOCK {
jmethodID prepid; // The CreatePrepStmt method ID jmethodID prepid; // The CreatePrepStmt method ID
jmethodID xpid; // The ExecutePrep method ID jmethodID xpid; // The ExecutePrep method ID
jmethodID pcid; // The ClosePrepStmt method ID jmethodID pcid; // The ClosePrepStmt method ID
jmethodID errid; // The GetErrmsg method ID
jmethodID chrfldid; // The StringField method ID
jmethodID intfldid; // The IntField method ID
jmethodID dblfldid; // The DoubleField method ID
jmethodID fltfldid; // The FloatField method ID
jmethodID datfldid; // The TimestampField method ID
jmethodID bigfldid; // The BigintField method ID
//DWORD m_LoginTimeout; //DWORD m_LoginTimeout;
//DWORD m_QueryTimeout; //DWORD m_QueryTimeout;
//DWORD m_UpdateOptions; //DWORD m_UpdateOptions;
char *Msg;
char m_IDQuoteChar[2]; char m_IDQuoteChar[2];
PSZ m_Driver; PSZ m_Driver;
PSZ m_Url; PSZ m_Url;
......
/************* TabJDBC C++ Program Source Code File (.CPP) *************/ /************* TabJDBC C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABJDBC */ /* PROGRAM NAME: TABJDBC */
/* ------------- */ /* ------------- */
/* Version 1.0 */ /* Version 1.1 */
/* */ /* */
/* COPYRIGHT: */ /* COPYRIGHT: */
/* ---------- */ /* ---------- */
...@@ -34,8 +34,10 @@ ...@@ -34,8 +34,10 @@
/***********************************************************************/ /***********************************************************************/
/* Include relevant MariaDB header file. */ /* Include relevant MariaDB header file. */
/***********************************************************************/ /***********************************************************************/
#define MYSQL_SERVER 1
#include "my_global.h" #include "my_global.h"
#include "sql_class.h" #include "sql_class.h"
#include "sql_servers.h"
#if defined(__WIN__) #if defined(__WIN__)
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -67,7 +69,6 @@ ...@@ -67,7 +69,6 @@
#include "plgdbsem.h" #include "plgdbsem.h"
#include "mycat.h" #include "mycat.h"
#include "xtable.h" #include "xtable.h"
#include "jdbccat.h"
#include "tabjdbc.h" #include "tabjdbc.h"
#include "tabmul.h" #include "tabmul.h"
#include "reldef.h" #include "reldef.h"
...@@ -101,11 +102,107 @@ JDBCDEF::JDBCDEF(void) ...@@ -101,11 +102,107 @@ JDBCDEF::JDBCDEF(void)
Scrollable = Xsrc = false; Scrollable = Xsrc = false;
} // end of JDBCDEF constructor } // end of JDBCDEF constructor
/***********************************************************************/
/* Called on table construction. */
/***********************************************************************/
bool JDBCDEF::SetParms(PJPARM sjp)
{
sjp->Url= Url;
sjp->User= Username;
sjp->Pwd= Password;
return true;
} // end of SetParms
/***********************************************************************/
/* Parse connection string */
/* */
/* SYNOPSIS */
/* ParseURL() */
/* Url The connection string to parse */
/* */
/* DESCRIPTION */
/* This is used to set the Url in case a wrapper server as been */
/* specified. This is rather experimental yet. */
/* */
/* RETURN VALUE */
/* RC_OK Url was a true URL */
/* RC_NF Url was a server name/table */
/* RC_FX Error */
/* */
/***********************************************************************/
int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
{
if (strncmp(url, "jdbc:", 5)) {
// No "jdbc:" in connection string. Must be a straight
// "server" or "server/table"
// ok, so we do a little parsing, but not completely!
if ((Tabname= strchr(url, '/'))) {
// If there is a single '/' in the connection string,
// this means the user is specifying a table name
*Tabname++= '\0';
// there better not be any more '/'s !
if (strchr(Tabname, '/'))
return RC_FX;
} else if (b) {
// Otherwise, straight server name,
Tabname = GetStringCatInfo(g, "Name", NULL);
Tabname = GetStringCatInfo(g, "Tabname", Tabname);
} // endelse
if (trace)
htrc("server: %s Tabname: %s", url, Tabname);
// Now make the required URL
FOREIGN_SERVER *server, server_buffer;
// get_server_by_name() clones the server if exists
if (!(server= get_server_by_name(current_thd->mem_root, url, &server_buffer))) {
sprintf(g->Message, "Server %s does not exist!", url);
return RC_FX;
} // endif server
if (strncmp(server->host, "jdbc:", 5)) {
// Now make the required URL
Url = (PSZ)PlugSubAlloc(g, NULL, 0);
strcat(strcpy(Url, "jdbc:"), server->scheme);
strcat(strcat(Url, "://"), server->host);
if (server->port) {
char buf[16];
sprintf(buf, "%d", server->port);
strcat(strcat(Url, ":"), buf);
} // endif port
if (server->db)
strcat(strcat(Url, "/"), server->db);
PlugSubAlloc(g, NULL, strlen(Url) + 1);
} else // host is a URL
Url = PlugDup(g, server->host);
if (server->username)
Username = PlugDup(g, server->username);
if (server->password)
Password = PlugDup(g, server->password);
return RC_NF;
} // endif
// Url was a JDBC URL, nothing to do
return RC_OK;
} // end of ParseURL
/***********************************************************************/ /***********************************************************************/
/* DefineAM: define specific AM block values from JDBC file. */ /* DefineAM: define specific AM block values from JDBC file. */
/***********************************************************************/ /***********************************************************************/
bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{ {
int rc = RC_OK;
Driver = GetStringCatInfo(g, "Driver", NULL); Driver = GetStringCatInfo(g, "Driver", NULL);
Desc = Url = GetStringCatInfo(g, "Connect", NULL); Desc = Url = GetStringCatInfo(g, "Connect", NULL);
...@@ -120,28 +217,33 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -120,28 +217,33 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
} // endif Connect } // endif Connect
Tabname = GetStringCatInfo(g, "Name", if (Url)
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); rc = ParseURL(g, Url);
Tabname = GetStringCatInfo(g, "Tabname", Tabname);
Tabschema = GetStringCatInfo(g, "Dbname", NULL); if (rc == RC_FX) // Error
Tabschema = GetStringCatInfo(g, "Schema", Tabschema); return true;
Tabcat = GetStringCatInfo(g, "Qualifier", NULL); else if (rc == RC_OK) { // Url was not a server name
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat); Tabname = GetStringCatInfo(g, "Name",
Tabtype = GetStringCatInfo(g, "Tabtype", NULL); (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
Username = GetStringCatInfo(g, "User", NULL); Tabname = GetStringCatInfo(g, "Tabname", Tabname);
Password = GetStringCatInfo(g, "Password", NULL); Username = GetStringCatInfo(g, "User", NULL);
Password = GetStringCatInfo(g, "Password", NULL);
} // endif rc
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL))) if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Read_Only = true; Read_Only = true;
Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL);
Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
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);
Maxerr = GetIntCatInfo("Maxerr", 0); Maxerr = GetIntCatInfo("Maxerr", 0);
Maxres = GetIntCatInfo("Maxres", 0); Maxres = GetIntCatInfo("Maxres", 0);
Quoted = GetIntCatInfo("Quoted", 0); Quoted = GetIntCatInfo("Quoted", 0);
//Options = JDBConn::noJDBCDialog;
//Options = JDBConn::noJDBCDialog | JDBConn::useCursorLib;
//Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT); //Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT);
//Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT); //Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT);
Scrollable = GetBoolCatInfo("Scrollable", false); Scrollable = GetBoolCatInfo("Scrollable", false);
...@@ -274,6 +376,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp) ...@@ -274,6 +376,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Ncol = 0; Ncol = 0;
Nparm = 0; Nparm = 0;
Placed = false; Placed = false;
Prepared = false;
Werr = false; Werr = false;
Rerr = false; Rerr = false;
Ops.Fsize = Ops.CheckSize(Rows); Ops.Fsize = Ops.CheckSize(Rows);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
/***********************************************************************/ /***********************************************************************/
#include "colblk.h" #include "colblk.h"
#include "resource.h" #include "resource.h"
#include "jdbccat.h"
typedef class JDBCDEF *PJDBCDEF; typedef class JDBCDEF *PJDBCDEF;
typedef class TDBJDBC *PTDBJDBC; typedef class TDBJDBC *PTDBJDBC;
...@@ -44,6 +45,8 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */ ...@@ -44,6 +45,8 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
virtual int Indexable(void) { return 2; } virtual int Indexable(void) { return 2; }
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m); virtual PTDB GetTable(PGLOBAL g, MODE m);
int ParseURL(PGLOBAL g, char *url, bool b = true);
bool SetParms(PJPARM sjp);
protected: protected:
// Members // Members
......
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