Skip to content

Commit 1ed1b77

Browse files
committed
Merge remote-tracking branch 'connect/11.2' into 10.2
2 parents 564f63c + a0e2659 commit 1ed1b77

File tree

7 files changed

+188
-52
lines changed

7 files changed

+188
-52
lines changed

storage/connect/ha_connect.cc

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@
170170
#define JSONMAX 10 // JSON Default max grp size
171171

172172
extern "C" {
173-
char version[]= "Version 1.06.0008 October 06, 2018";
173+
char version[]= "Version 1.06.0009 January 27, 2019";
174174
#if defined(__WIN__)
175-
char compver[]= "Version 1.06.0008 " __DATE__ " " __TIME__;
175+
char compver[]= "Version 1.06.0009 " __DATE__ " " __TIME__;
176176
char slash= '\\';
177177
#else // !__WIN__
178178
char slash= '/';
@@ -204,6 +204,26 @@ pthread_mutex_t parmut;
204204
pthread_mutex_t usrmut;
205205
pthread_mutex_t tblmut;
206206

207+
#if defined(DEVELOPMENT)
208+
char *GetUserVariable(PGLOBAL g, const uchar *varname);
209+
210+
char *GetUserVariable(PGLOBAL g, const uchar *varname)
211+
{
212+
char buf[1024];
213+
bool b;
214+
THD *thd = current_thd;
215+
CHARSET_INFO *cs = system_charset_info;
216+
String *str = NULL, tmp(buf, sizeof(buf), cs);
217+
HASH uvars = thd->user_vars;
218+
user_var_entry *uvar = (user_var_entry*)my_hash_search(&uvars, varname, 0);
219+
220+
if (uvar)
221+
str = uvar->val_str(&b, &tmp, NOT_FIXED_DEC);
222+
223+
return str ? PlugDup(g, str->ptr()) : NULL;
224+
}; // end of GetUserVariable
225+
#endif // DEVELOPMENT
226+
207227
/***********************************************************************/
208228
/* Utility functions. */
209229
/***********************************************************************/
@@ -1914,9 +1934,11 @@ int ha_connect::OpenTable(PGLOBAL g, bool del)
19141934
break;
19151935
} // endswitch xmode
19161936

1917-
if (xmod != MODE_INSERT || tdbp->GetAmType() == TYPE_AM_MYSQL
1918-
|| tdbp->GetAmType() == TYPE_AM_ODBC
1919-
|| tdbp->GetAmType() == TYPE_AM_JDBC) {
1937+
// g->More is 1 when executing commands from triggers
1938+
if (!g->More && (xmod != MODE_INSERT
1939+
|| tdbp->GetAmType() == TYPE_AM_MYSQL
1940+
|| tdbp->GetAmType() == TYPE_AM_ODBC
1941+
|| tdbp->GetAmType() == TYPE_AM_JDBC)) {
19201942
// Get the list of used fields (columns)
19211943
char *p;
19221944
unsigned int k1, k2, n1, n2;
@@ -4631,7 +4653,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd,
46314653
break;
46324654
case SQLCOM_CREATE_VIEW:
46334655
case SQLCOM_DROP_VIEW:
4634-
newmode= MODE_ANY;
4656+
case SQLCOM_CREATE_TRIGGER:
4657+
case SQLCOM_DROP_TRIGGER:
4658+
newmode= MODE_ANY;
46354659
break;
46364660
case SQLCOM_ALTER_TABLE:
46374661
*chk= true;
@@ -4674,6 +4698,9 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
46744698
PGLOBAL g= GetPlug(thd, xp);
46754699
DBUG_ENTER("ha_connect::start_stmt");
46764700

4701+
if (table->triggers)
4702+
g->More= 1; // We don't know which columns are used by the trigger
4703+
46774704
if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
46784705
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
46794706

@@ -7310,7 +7337,7 @@ maria_declare_plugin(connect)
73107337
0x0106, /* version number (1.06) */
73117338
NULL, /* status variables */
73127339
connect_system_variables, /* system variables */
7313-
"1.06.0008", /* string version */
7340+
"1.06.0009", /* string version */
73147341
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
73157342
}
73167343
maria_declare_plugin_end;

storage/connect/jsonudf.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,8 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i)
16661666
if (args->arg_count > (unsigned)i) {
16671667
int j = 0, n = args->attribute_lengths[i];
16681668
my_bool b; // true if attribute is zero terminated
1669-
PSZ p, s = args->attributes[i];
1669+
PSZ p;
1670+
PCSZ s = args->attributes[i];
16701671

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

5809+
#if defined(DEVELOPMENT)
5810+
extern char *GetUserVariable(PGLOBAL g, const uchar *varname);
5811+
5812+
/*********************************************************************************/
5813+
/* Utility function returning a user variable value. */
5814+
/*********************************************************************************/
5815+
my_bool uvar_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
5816+
{
5817+
unsigned long reslen, memlen;
5818+
5819+
if (args->arg_count != 1) {
5820+
strcpy(message, "Unique argument must be a user variable name");
5821+
return true;
5822+
} else
5823+
CalcLen(args, false, reslen, memlen, true);
5824+
5825+
initid->maybe_null = true;
5826+
return JsonInit(initid, args, message, true, reslen, memlen, 2048);
5827+
} // end of uvar_init
5828+
5829+
char *uvar(UDF_INIT *initid, UDF_ARGS *args, char *result,
5830+
unsigned long *res_length, char *is_null, char *)
5831+
{
5832+
char *str, varname[256];
5833+
PGLOBAL g = (PGLOBAL)initid->ptr;
5834+
int n = MY_MIN(args->lengths[0], sizeof(varname) - 1);
5835+
5836+
PlugSubSet(g->Sarea, g->Sarea_Size);
5837+
memcpy(varname, args->args[0], n);
5838+
varname[n] = 0;
5839+
5840+
if (!(str = GetUserVariable(g, (const uchar*)&varname))) {
5841+
*res_length = 0;
5842+
*is_null = 1;
5843+
} else
5844+
*res_length = strlen(str);
5845+
5846+
return str;
5847+
} // end of uvar
5848+
5849+
void uvar_deinit(UDF_INIT* initid)
5850+
{
5851+
JsonFreeMem((PGLOBAL)initid->ptr);
5852+
} // end of uvar_deinit
5853+
#endif // DEVELOPMENT
5854+
58085855
/*********************************************************************************/
58095856
/* Returns the distinct number of B occurences in A. */
58105857
/*********************************************************************************/

storage/connect/jsonudf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ extern "C" {
238238
DllExport my_bool envar_init(UDF_INIT*, UDF_ARGS*, char*);
239239
DllExport char *envar(UDF_EXEC_ARGS);
240240

241+
#if defined(DEVELOPMENT)
242+
DllExport my_bool uvar_init(UDF_INIT*, UDF_ARGS*, char*);
243+
DllExport char *uvar(UDF_EXEC_ARGS);
244+
#endif // DEVELOPMENT
245+
241246
DllExport my_bool countin_init(UDF_INIT*, UDF_ARGS*, char*);
242247
DllExport long long countin(UDF_EXEC_ARGS);
243248
} // extern "C"

storage/connect/tabext.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************* Tabext C++ Functions Source Code File (.CPP) ************/
2-
/* Name: TABEXT.CPP Version 1.0 */
2+
/* Name: TABEXT.CPP Version 1.1 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2017 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */
55
/* */
66
/* This file contains the TBX, TDB and OPJOIN classes functions. */
77
/***********************************************************************/
@@ -445,6 +445,43 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
445445
return false;
446446
} // end of MakeSQL
447447

448+
/***********************************************************************/
449+
/* Remove the NAME_CONST functions that are added by procedures. */
450+
/***********************************************************************/
451+
void TDBEXT::RemoveConst(PGLOBAL g, char *stmt)
452+
{
453+
char *p, *p2;
454+
char val[1025], nval[1025];
455+
int n, nc;
456+
457+
while ((p = strstr(stmt, "NAME_CONST")))
458+
if ((n = sscanf(p, "%*[^,],%1024[^)])%n", val, &nc))) {
459+
if (trace(33))
460+
htrc("p=%s\nn=%d val=%s nc=%d\n", p, n, val, nc);
461+
462+
*p = 0;
463+
464+
if ((p2 = strstr(val, "'"))) {
465+
if ((n = sscanf(p2, "%*['\\]%1024[^'\\]", nval))) {
466+
if (trace(33))
467+
htrc("p2=%s\nn=%d nval=%s\n", p2, n, nval);
468+
469+
strcat(strcat(strcat(strcat(stmt, "'"), nval), "'"), p + nc);
470+
} else
471+
break;
472+
473+
} else
474+
strcat(strcat(strcat(strcat(stmt, "("), val), ")"), p + nc);
475+
476+
if (trace(33))
477+
htrc("stmt=%s\n", stmt);
478+
479+
} else
480+
break;
481+
482+
return;
483+
} // end of RemoveConst
484+
448485
/***********************************************************************/
449486
/* MakeCommand: make the Update or Delete statement to send to the */
450487
/* MySQL server. Limited to remote values and filtering. */
@@ -524,6 +561,8 @@ bool TDBEXT::MakeCommand(PGLOBAL g)
524561
stmt[i++] = (Qrystr[k] == '`') ? q : Qrystr[k];
525562
} while (Qrystr[k++]);
526563

564+
RemoveConst(g, stmt);
565+
527566
if (body)
528567
strcat(stmt, body);
529568

storage/connect/tabext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*************** Tabext H Declares Source Code File (.H) ***************/
2-
/* Name: TABEXT.H Version 1.0 */
2+
/* Name: TABEXT.H Version 1.1 */
33
/* */
4-
/* (C) Copyright to the author Olivier BERTRAND 2017 */
4+
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */
55
/* */
66
/* This is the EXTDEF, TABEXT and EXTCOL classes definitions. */
77
/***********************************************************************/
@@ -130,6 +130,7 @@ class DllExport TDBEXT : public TDB {
130130
virtual bool MakeSQL(PGLOBAL g, bool cnt);
131131
//virtual bool MakeInsert(PGLOBAL g);
132132
virtual bool MakeCommand(PGLOBAL g);
133+
void RemoveConst(PGLOBAL g, char *stmt);
133134
int Decode(PCSZ utf, char *buf, size_t n);
134135

135136
// Members

0 commit comments

Comments
 (0)