Commit 1ed1b779 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

Merge remote-tracking branch 'connect/11.2' into 10.2

parents 564f63cc a0e26599
......@@ -170,9 +170,9 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.06.0008 October 06, 2018";
char version[]= "Version 1.06.0009 January 27, 2019";
#if defined(__WIN__)
char compver[]= "Version 1.06.0008 " __DATE__ " " __TIME__;
char compver[]= "Version 1.06.0009 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
......@@ -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. */
/***********************************************************************/
......@@ -1914,9 +1934,11 @@ int ha_connect::OpenTable(PGLOBAL g, bool del)
break;
} // endswitch xmode
if (xmod != MODE_INSERT || tdbp->GetAmType() == TYPE_AM_MYSQL
|| tdbp->GetAmType() == TYPE_AM_ODBC
|| tdbp->GetAmType() == TYPE_AM_JDBC) {
// g->More is 1 when executing commands from triggers
if (!g->More && (xmod != MODE_INSERT
|| tdbp->GetAmType() == TYPE_AM_MYSQL
|| tdbp->GetAmType() == TYPE_AM_ODBC
|| tdbp->GetAmType() == TYPE_AM_JDBC)) {
// Get the list of used fields (columns)
char *p;
unsigned int k1, k2, n1, n2;
......@@ -4631,7 +4653,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
break;
case SQLCOM_CREATE_VIEW:
case SQLCOM_DROP_VIEW:
newmode= MODE_ANY;
case SQLCOM_CREATE_TRIGGER:
case SQLCOM_DROP_TRIGGER:
newmode= MODE_ANY;
break;
case SQLCOM_ALTER_TABLE:
*chk= true;
......@@ -4674,6 +4698,9 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
PGLOBAL g= GetPlug(thd, xp);
DBUG_ENTER("ha_connect::start_stmt");
if (table->triggers)
g->More= 1; // We don't know which columns are used by the trigger
if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
......@@ -7310,7 +7337,7 @@ maria_declare_plugin(connect)
0x0106, /* version number (1.06) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.06.0008", /* string version */
"1.06.0009", /* string version */
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
}
maria_declare_plugin_end;
......@@ -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"
......
/************* Tabext C++ Functions Source Code File (.CPP) ************/
/* Name: TABEXT.CPP Version 1.0 */
/* Name: TABEXT.CPP Version 1.1 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */
/* */
/* This file contains the TBX, TDB and OPJOIN classes functions. */
/***********************************************************************/
......@@ -445,6 +445,43 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
return false;
} // end of MakeSQL
/***********************************************************************/
/* Remove the NAME_CONST functions that are added by procedures. */
/***********************************************************************/
void TDBEXT::RemoveConst(PGLOBAL g, char *stmt)
{
char *p, *p2;
char val[1025], nval[1025];
int n, nc;
while ((p = strstr(stmt, "NAME_CONST")))
if ((n = sscanf(p, "%*[^,],%1024[^)])%n", val, &nc))) {
if (trace(33))
htrc("p=%s\nn=%d val=%s nc=%d\n", p, n, val, nc);
*p = 0;
if ((p2 = strstr(val, "'"))) {
if ((n = sscanf(p2, "%*['\\]%1024[^'\\]", nval))) {
if (trace(33))
htrc("p2=%s\nn=%d nval=%s\n", p2, n, nval);
strcat(strcat(strcat(strcat(stmt, "'"), nval), "'"), p + nc);
} else
break;
} else
strcat(strcat(strcat(strcat(stmt, "("), val), ")"), p + nc);
if (trace(33))
htrc("stmt=%s\n", stmt);
} else
break;
return;
} // end of RemoveConst
/***********************************************************************/
/* MakeCommand: make the Update or Delete statement to send to the */
/* MySQL server. Limited to remote values and filtering. */
......@@ -524,6 +561,8 @@ bool TDBEXT::MakeCommand(PGLOBAL g)
stmt[i++] = (Qrystr[k] == '`') ? q : Qrystr[k];
} while (Qrystr[k++]);
RemoveConst(g, stmt);
if (body)
strcat(stmt, body);
......
/*************** Tabext H Declares Source Code File (.H) ***************/
/* Name: TABEXT.H Version 1.0 */
/* Name: TABEXT.H Version 1.1 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 */
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */
/* */
/* This is the EXTDEF, TABEXT and EXTCOL classes definitions. */
/***********************************************************************/
......@@ -130,6 +130,7 @@ class DllExport TDBEXT : public TDB {
virtual bool MakeSQL(PGLOBAL g, bool cnt);
//virtual bool MakeInsert(PGLOBAL g);
virtual bool MakeCommand(PGLOBAL g);
void RemoveConst(PGLOBAL g, char *stmt);
int Decode(PCSZ utf, char *buf, size_t n);
// Members
......
/************* TabJDBC C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABJDBC */
/* ------------- */
/* Version 1.2 */
/* Version 1.3 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */
/* (C) Copyright to the author Olivier BERTRAND 2016-2019 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
......@@ -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);
......@@ -185,12 +188,15 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b)
} else // host is a URL
Url = PlugDup(g, server->host);
if (server->username)
if (!Username && server->username)
Username = PlugDup(g, server->username);
if (server->password)
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
......@@ -558,33 +566,42 @@ bool TDBJDBC::OpenDB(PGLOBAL g)
this, Tdb_No, Use, Mode);
if (Use == USE_OPEN) {
/*******************************************************************/
/* Table already open, just replace it at its beginning. */
/*******************************************************************/
if (Memory == 1) {
if ((Qrp = Jcp->AllocateResult(g, this)))
Memory = 2; // Must be filled
else
Memory = 0; // Allocation failed, don't use it
} else if (Memory == 2)
Memory = 3; // Ok to use memory result
if (Memory < 3) {
// Method will depend on cursor type
if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0)
if (Mode != MODE_READX) {
Jcp->Close();
return true;
} else
Rbuf = 0;
if (Mode == MODE_READ || Mode == MODE_READX) {
/*****************************************************************/
/* Table already open, just replace it at its beginning. */
/*****************************************************************/
if (Memory == 1) {
if ((Qrp = Jcp->AllocateResult(g, this)))
Memory = 2; // Must be filled
else
Memory = 0; // Allocation failed, don't use it
} else
Rbuf = Qrp->Nblin;
} else if (Memory == 2)
Memory = 3; // Ok to use memory result
if (Memory < 3) {
// Method will depend on cursor type
if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0)
if (Mode != MODE_READX) {
Jcp->Close();
return true;
} else
Rbuf = 0;
} else
Rbuf = Qrp->Nblin;
CurNum = 0;
Fpos = 0;
Curpos = 1;
} else if (Mode == MODE_UPDATE || Mode == MODE_DELETE) {
// new update coming from a trigger or procedure
Query = NULL;
SetCondFil(NULL);
Qrystr = To_Def->GetStringCatInfo(g, "Query_String", "?");
} else { //if (Mode == MODE_INSERT)
} // endif Mode
CurNum = 0;
Fpos = 0;
Curpos = 1;
return false;
} // endif use
......
/************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.6 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */
/* PROGRAM NAME: tabjson Version 1.7 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2019 */
/* This program are the JSON class DB execution routines. */
/***********************************************************************/
......@@ -110,8 +110,8 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
buftyp, fldtyp, length, false, false);
crp = qrp->Colresp->Next->Next->Next->Next->Next->Next;
crp->Name = "Nullable";
crp->Next->Name = "Jpath";
crp->Name = PlugDup(g, "Nullable");
crp->Next->Name = PlugDup(g, "Jpath");
if (info || !qrp)
return qrp;
......
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