mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
- Fix MDEV-13136: enhance CREATE SERVER MyServerName
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
This commit is contained in:
parent
bece44be4f
commit
a0e26599a3
4 changed files with 88 additions and 8 deletions
|
@ -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. */
|
||||
/***********************************************************************/
|
||||
|
|
|
@ -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])))
|
||||
|
@ -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. */
|
||||
/*********************************************************************************/
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
@ -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 -------------------------- */
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue