Skip to content

Commit

Permalink
- Fix MDEV-13136: enhance CREATE SERVER MyServerName
Browse files Browse the repository at this point in the history
  FOREIGN DATA WRAPPER to work with CONNECT engine
  modified:   storage/connect/tabjdbc.cpp

- Add a function to retrieve User variable value (DEVELOPMENT only)
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h
  modified:   storage/connect/tabjdbc.cpp
  • Loading branch information
Buggynours committed Feb 3, 2019
1 parent bece44b commit a0e2659
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 8 deletions.
20 changes: 20 additions & 0 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ pthread_mutex_t parmut;
pthread_mutex_t usrmut;
pthread_mutex_t tblmut;

#if defined(DEVELOPMENT)
char *GetUserVariable(PGLOBAL g, const uchar *varname);

char *GetUserVariable(PGLOBAL g, const uchar *varname)
{
char buf[1024];
bool b;
THD *thd = current_thd;
CHARSET_INFO *cs = system_charset_info;
String *str = NULL, tmp(buf, sizeof(buf), cs);
HASH uvars = thd->user_vars;
user_var_entry *uvar = (user_var_entry*)my_hash_search(&uvars, varname, 0);

if (uvar)
str = uvar->val_str(&b, &tmp, NOT_FIXED_DEC);

return str ? PlugDup(g, str->ptr()) : NULL;
}; // end of GetUserVariable
#endif // DEVELOPMENT

/***********************************************************************/
/* Utility functions. */
/***********************************************************************/
Expand Down
49 changes: 48 additions & 1 deletion storage/connect/jsonudf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,8 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i)
if (args->arg_count > (unsigned)i) {
int j = 0, n = args->attribute_lengths[i];
my_bool b; // true if attribute is zero terminated
PSZ p, s = args->attributes[i];
PSZ p;
PCSZ s = args->attributes[i];

if (s && *s && (n || *s == '\'')) {
if ((b = (!n || !s[n])))
Expand Down Expand Up @@ -5805,6 +5806,52 @@ char *envar(UDF_INIT *initid, UDF_ARGS *args, char *result,
return str;
} // end of envar

#if defined(DEVELOPMENT)
extern char *GetUserVariable(PGLOBAL g, const uchar *varname);

/*********************************************************************************/
/* Utility function returning a user variable value. */
/*********************************************************************************/
my_bool uvar_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
unsigned long reslen, memlen;

if (args->arg_count != 1) {
strcpy(message, "Unique argument must be a user variable name");
return true;
} else
CalcLen(args, false, reslen, memlen, true);

initid->maybe_null = true;
return JsonInit(initid, args, message, true, reslen, memlen, 2048);
} // end of uvar_init

char *uvar(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *)
{
char *str, varname[256];
PGLOBAL g = (PGLOBAL)initid->ptr;
int n = MY_MIN(args->lengths[0], sizeof(varname) - 1);

PlugSubSet(g->Sarea, g->Sarea_Size);
memcpy(varname, args->args[0], n);
varname[n] = 0;

if (!(str = GetUserVariable(g, (const uchar*)&varname))) {
*res_length = 0;
*is_null = 1;
} else
*res_length = strlen(str);

return str;
} // end of uvar

void uvar_deinit(UDF_INIT* initid)
{
JsonFreeMem((PGLOBAL)initid->ptr);
} // end of uvar_deinit
#endif // DEVELOPMENT

/*********************************************************************************/
/* Returns the distinct number of B occurences in A. */
/*********************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions storage/connect/jsonudf.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ extern "C" {
DllExport my_bool envar_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *envar(UDF_EXEC_ARGS);

#if defined(DEVELOPMENT)
DllExport my_bool uvar_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *uvar(UDF_EXEC_ARGS);
#endif // DEVELOPMENT

DllExport my_bool countin_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport long long countin(UDF_EXEC_ARGS);
} // extern "C"
Expand Down
22 changes: 15 additions & 7 deletions storage/connect/tabjdbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
#include "tabext.h"
#include "tabjdbc.h"
#include "tabmul.h"
//#include "reldef.h"
#include "tabcol.h"
#include "valblk.h"
#include "ha_connect.h"
Expand All @@ -89,6 +88,9 @@ extern int num_read, num_there, num_eq[2]; // Statistics
/* External function. */
/***********************************************************************/
bool ExactInfo(void);
#if defined(DEVELOPMENT)
extern char *GetUserVariable(PGLOBAL g, const uchar *varname);
#endif // DEVELOPMENT

/* -------------------------- Class JDBCDEF -------------------------- */

Expand Down Expand Up @@ -147,10 +149,6 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
return RC_FX;

Tabname = p;
// } else if (b) {
// // Otherwise, straight server name,
// Tabname = GetStringCatInfo(g, "Name", NULL);
// Tabname = GetStringCatInfo(g, "Tabname", Tabname);
} // endif

if (trace(1))
Expand All @@ -165,6 +163,11 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
return RC_FX;
} // endif server

#if defined(DEVELOPMENT)
if (*server->host == '@') {
Url = GetUserVariable(g, (const uchar*)&server->host[1]);
} else
#endif // 0
if (strncmp(server->host, "jdbc:", 5)) {
// Now make the required URL
Url = (PSZ)PlugSubAlloc(g, NULL, 0);
Expand All @@ -191,6 +194,9 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
if (!Password && server->password)
Password = PlugDup(g, server->password);

Driver = PlugDup(g, GetListOption(g, "Driver", server->owner, NULL));
Wrapname = PlugDup(g, GetListOption(g, "Wrapper", server->owner, NULL));
Memory = atoi(GetListOption(g, "Memory", server->owner, "0"));
return RC_NF;
} // endif

Expand All @@ -208,7 +214,6 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if (EXTDEF::DefineAM(g, am, poff))
return true;

Driver = GetStringCatInfo(g, "Driver", NULL);
Desc = Url = GetStringCatInfo(g, "Connect", NULL);

if (!Url && !Catfunc) {
Expand All @@ -228,7 +233,10 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
return true;
} // endif rc

Wrapname = GetStringCatInfo(g, "Wrapper", NULL);
// Default values may have been set in ParseURL
Memory = GetIntCatInfo("Memory", Memory);
Driver = GetStringCatInfo(g, "Driver", Driver);
Wrapname = GetStringCatInfo(g, "Wrapper", Wrapname);
return false;
} // end of DefineAM

Expand Down

0 comments on commit a0e2659

Please sign in to comment.