Skip to content

Commit f4fe138

Browse files
committed
Fix assert error for where clause with UDF's
was fixed in HA_CONNECT::CondFilter moving res= pval->val_str(&tmp) but this was wrong. Now res is only used for strings. Change version number modified: storage/connect/ha_connect.cc Add some new UDF's modified: storage/connect/json.cpp modified: storage/connect/json.h modified: storage/connect/jsonudf.cpp modified: storage/connect/jsonudf.h Fix change in tests json_udf modified: storage/connect/mysql-test/connect/r/json_udf.result modified: storage/connect/mysql-test/connect/t/json_udf.inc modified: storage/connect/mysql-test/connect/t/json_udf.test
1 parent 8a154ec commit f4fe138

File tree

8 files changed

+1136
-237
lines changed

8 files changed

+1136
-237
lines changed

storage/connect/ha_connect.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@
169169
#define JSONMAX 10 // JSON Default max grp size
170170

171171
extern "C" {
172-
char version[]= "Version 1.04.0001 June 29, 2015";
172+
char version[]= "Version 1.04.0003 September 15, 2015";
173173
#if defined(__WIN__)
174-
char compver[]= "Version 1.04.0001 " __DATE__ " " __TIME__;
174+
char compver[]= "Version 1.04.0003 " __DATE__ " " __TIME__;
175175
char slash= '\\';
176176
#else // !__WIN__
177177
char slash= '/';
@@ -2544,12 +2544,10 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
25442544
if (!i && (ismul))
25452545
return NULL;
25462546

2547-
if ((res= pval->val_str(&tmp)) == NULL)
2548-
return NULL; // To be clarified
2549-
2550-
switch (args[i]->real_type()) {
2547+
switch (args[i]->real_type()) {
25512548
case COND::STRING_ITEM:
2552-
pp->Value= PlugSubAllocStr(g, NULL, res->ptr(), res->length());
2549+
res= pval->val_str(&tmp);
2550+
pp->Value= PlugSubAllocStr(g, NULL, res->ptr(), res->length());
25532551
pp->Type= (pp->Value) ? TYPE_STRING : TYPE_ERROR;
25542552
break;
25552553
case COND::INT_ITEM:
@@ -2578,8 +2576,8 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond)
25782576
return NULL;
25792577
} // endswitch type
25802578

2581-
if (trace)
2582-
htrc("Value=%.*s\n", res->length(), res->ptr());
2579+
if (trace)
2580+
htrc("Value type=%hd\n", pp->Type);
25832581

25842582
// Append the value to the argument list
25852583
if (pprec)
@@ -6722,7 +6720,7 @@ maria_declare_plugin(connect)
67226720
0x0104, /* version number (1.04) */
67236721
NULL, /* status variables */
67246722
connect_system_variables, /* system variables */
6725-
"1.04.0001", /* string version */
6723+
"1.04.0003", /* string version */
67266724
MariaDB_PLUGIN_MATURITY_BETA /* maturity */
67276725
}
67286726
maria_declare_plugin_end;

storage/connect/json.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,30 @@ PSZ JOBJECT::GetText(PGLOBAL g, PSZ text)
942942
return text + n;
943943
} // end of GetValue;
944944

945+
/***********************************************************************/
946+
/* Merge two objects. */
947+
/***********************************************************************/
948+
bool JOBJECT::Merge(PGLOBAL g, PJSON jsp)
949+
{
950+
if (jsp->GetType() != TYPE_JOB) {
951+
strcpy(g->Message, "Second argument is not an object");
952+
return true;
953+
} // endif Type
954+
955+
PJOB jobp = (PJOB)jsp;
956+
957+
for (PJPR jpp = jobp->First; jpp; jpp = jpp->Next)
958+
SetValue(g, jpp->GetVal(), jpp->GetKey());
959+
960+
return false;
961+
} // end of Marge;
962+
945963
/***********************************************************************/
946964
/* Set or add a value corresponding to the given key. */
947965
/***********************************************************************/
948966
void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PSZ key)
949967
{
950-
PJPR jp;
968+
PJPR jp;
951969

952970
for (jp = First; jp; jp = jp->Next)
953971
if (!strcmp(jp->Key, key)) {
@@ -1063,6 +1081,25 @@ PJVAL JARRAY::AddValue(PGLOBAL g, PJVAL jvp, int *x)
10631081
return jvp;
10641082
} // end of AddValue
10651083

1084+
/***********************************************************************/
1085+
/* Merge two arrays. */
1086+
/***********************************************************************/
1087+
bool JARRAY::Merge(PGLOBAL g, PJSON jsp)
1088+
{
1089+
if (jsp->GetType() != TYPE_JAR) {
1090+
strcpy(g->Message, "Second argument is not an array");
1091+
return true;
1092+
} // endif Type
1093+
1094+
PJAR arp = (PJAR)jsp;
1095+
1096+
for (int i = 0; i < jsp->size(); i++)
1097+
AddValue(g, arp->GetValue(i));
1098+
1099+
InitArray(g);
1100+
return false;
1101+
} // end of Merge
1102+
10661103
/***********************************************************************/
10671104
/* Set the nth Value of the Array Value list. */
10681105
/***********************************************************************/

storage/connect/json.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ class JSON : public BLOCK {
162162
virtual double GetFloat() {X return 0.0;}
163163
virtual PSZ GetString() {X return NULL;}
164164
virtual PSZ GetText(PGLOBAL g, PSZ text) {X return NULL;}
165-
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) {X return true;}
165+
virtual bool Merge(PGLOBAL g, PJSON jsp) { X return true; }
166+
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) { X return true; }
166167
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key) {X}
167168
virtual void SetValue(PVAL valp) {X}
168169
virtual void SetValue(PJSON jsp) {X}
@@ -197,7 +198,8 @@ class JOBJECT : public JSON {
197198
virtual PJVAL GetValue(const char* key);
198199
virtual PJAR GetKeyList(PGLOBAL g);
199200
virtual PSZ GetText(PGLOBAL g, PSZ text);
200-
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key);
201+
virtual bool Merge(PGLOBAL g, PJSON jsp);
202+
virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key);
201203
virtual void DeleteKey(char *k);
202204
virtual bool IsNull(void);
203205

@@ -222,7 +224,8 @@ class JARRAY : public JSON {
222224
virtual PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL);
223225
virtual void InitArray(PGLOBAL g);
224226
virtual PJVAL GetValue(int i);
225-
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
227+
virtual bool Merge(PGLOBAL g, PJSON jsp);
228+
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
226229
virtual bool DeleteValue(int n);
227230
virtual bool IsNull(void);
228231

0 commit comments

Comments
 (0)