summaryrefslogtreecommitdiff
path: root/storage/connect/tabjdbc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage/connect/tabjdbc.cpp')
-rw-r--r--storage/connect/tabjdbc.cpp180
1 files changed, 150 insertions, 30 deletions
diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp
index 97168646ba0..e6782e71753 100644
--- a/storage/connect/tabjdbc.cpp
+++ b/storage/connect/tabjdbc.cpp
@@ -1,7 +1,7 @@
/************* TabJDBC C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABJDBC */
/* ------------- */
-/* Version 1.0 */
+/* Version 1.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
@@ -34,8 +34,10 @@
/***********************************************************************/
/* Include relevant MariaDB header file. */
/***********************************************************************/
+#define MYSQL_SERVER 1
#include "my_global.h"
#include "sql_class.h"
+#include "sql_servers.h"
#if defined(__WIN__)
#include <io.h>
#include <fcntl.h>
@@ -67,7 +69,6 @@
#include "plgdbsem.h"
#include "mycat.h"
#include "xtable.h"
-#include "jdbccat.h"
#include "tabjdbc.h"
#include "tabmul.h"
#include "reldef.h"
@@ -95,48 +96,160 @@ bool ExactInfo(void);
/***********************************************************************/
JDBCDEF::JDBCDEF(void)
{
- Jpath = Driver = Url = Tabname = Tabschema = Username = NULL;
+ Driver = Url = Tabname = Tabschema = Username = Colpat = NULL;
Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false;
} // 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, "%ld", 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. */
/***********************************************************************/
bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
- Jpath = GetStringCatInfo(g, "Jpath", "");
+ int rc = RC_OK;
+
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",
- (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
- Tabname = GetStringCatInfo(g, "Tabname", Tabname);
- Tabschema = GetStringCatInfo(g, "Dbname", NULL);
- Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
- Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
- Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
- Tabtype = GetStringCatInfo(g, "Tabtype", NULL);
- Username = GetStringCatInfo(g, "User", NULL);
- Password = GetStringCatInfo(g, "Password", NULL);
+ if (Url)
+ rc = ParseURL(g, Url);
+
+ if (rc == RC_FX) // Error
+ return true;
+ else if (rc == RC_OK) { // Url was not a server name
+ Tabname = GetStringCatInfo(g, "Name",
+ (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
+ Tabname = GetStringCatInfo(g, "Tabname", Tabname);
+ Username = GetStringCatInfo(g, "User", NULL);
+ Password = GetStringCatInfo(g, "Password", NULL);
+ } // endif rc
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Read_Only = true;
+ Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
+ Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
+ Tabschema = GetStringCatInfo(g, "Dbname", NULL);
+ Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
+
+ if (Catfunc == FNC_COL)
+ Colpat = GetStringCatInfo(g, "Colpat", NULL);
+
+ if (Catfunc == FNC_TABLE)
+ Tabtype = GetStringCatInfo(g, "Tabtype", NULL);
+
Qrystr = GetStringCatInfo(g, "Query_String", "?");
Sep = GetStringCatInfo(g, "Separator", NULL);
Xsrc = GetBoolCatInfo("Execsrc", FALSE);
Maxerr = GetIntCatInfo("Maxerr", 0);
Maxres = GetIntCatInfo("Maxres", 0);
Quoted = GetIntCatInfo("Quoted", 0);
-//Options = JDBConn::noJDBCDialog;
-//Options = JDBConn::noJDBCDialog | JDBConn::useCursorLib;
//Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT);
//Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT);
Scrollable = GetBoolCatInfo("Scrollable", false);
@@ -198,7 +311,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;
@@ -216,7 +329,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;
@@ -235,7 +347,6 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Memory = tdp->Memory;
Ops.Scrollable = tdp->Scrollable;
} else {
- Jpath = NULL;
TableName = NULL;
Schema = NULL;
Ops.Driver = NULL;
@@ -271,6 +382,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Ncol = 0;
Nparm = 0;
Placed = false;
+ Prepared = false;
Werr = false;
Rerr = false;
Ops.Fsize = Ops.CheckSize(Rows);
@@ -280,7 +392,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;
@@ -678,7 +789,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
@@ -789,7 +900,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();
@@ -1539,7 +1650,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
@@ -1651,7 +1762,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 --------------------------- */
@@ -1661,7 +1772,6 @@ PQRYRES TDBJDRV::GetResult(PGLOBAL g)
/***********************************************************************/
TDBJTB::TDBJTB(PJDBCDEF tdp) : TDBJDRV(tdp)
{
- Jpath = tdp->Jpath;
Schema = tdp->Tabschema;
Tab = tdp->Tabname;
Tabtype = tdp->Tabtype;
@@ -1669,6 +1779,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
/***********************************************************************/
@@ -1676,17 +1788,25 @@ 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 -------------------------- */
/***********************************************************************/
+/* TDBJDBCL class constructor. */
+/***********************************************************************/
+TDBJDBCL::TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp)
+{
+ Colpat = tdp->Colpat;
+} // end of TDBJDBCL constructor
+
+/***********************************************************************/
/* GetResult: Get the list of JDBC table columns. */
/***********************************************************************/
PQRYRES TDBJDBCL::GetResult(PGLOBAL g)
{
- return JDBCColumns(g, Jpath, Schema, Tab, NULL, Maxres, false, &Ops);
+ return JDBCColumns(g, Schema, Tab, Colpat, Maxres, false, &Ops);
} // end of GetResult
#if 0