Commit 0bfb5bee authored by Olivier Bertrand's avatar Olivier Bertrand

Merge branch 'ob-10.0' into 10.0

parents 7cd94c68 62a5e56c
/* Copyright (C) Olivier Bertrand 2004 - 2015
/* Copyright (C) Olivier Bertrand 2004 - 2016
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -169,7 +169,7 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.04.0005 December 11, 2015";
char version[]= "Version 1.04.0005 January 24, 2016";
#if defined(__WIN__)
char compver[]= "Version 1.04.0005 " __DATE__ " " __TIME__;
char slash= '\\';
......@@ -339,15 +339,22 @@ static MYSQL_THDVAR_ENUM(
&language_typelib); // typelib
#endif // XMSG || NEWMSG
/***********************************************************************/
/* The CONNECT handlerton object. */
/***********************************************************************/
handlerton *connect_hton= NULL;
/***********************************************************************/
/* Function to export session variable values to other source files. */
/***********************************************************************/
extern "C" int GetTraceValue(void) {return THDVAR(current_thd, xtrace);}
extern "C" int GetTraceValue(void)
{return connect_hton ? THDVAR(current_thd, xtrace) : 0;}
bool ExactInfo(void) {return THDVAR(current_thd, exact_info);}
USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);}
int GetConvSize(void) {return THDVAR(current_thd, conv_size);}
TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
uint GetJsonGrpSize(void) {return THDVAR(current_thd, json_grp_size);}
uint GetJsonGrpSize(void)
{return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;}
uint GetWorkSize(void) {return THDVAR(current_thd, work_size);}
void SetWorkSize(uint)
{
......@@ -442,11 +449,6 @@ static int check_msg_path (MYSQL_THD thd, struct st_mysql_sys_var *var,
} // end of check_msg_path
#endif // 0
/***********************************************************************/
/* The CONNECT handlerton object. */
/***********************************************************************/
handlerton *connect_hton;
/**
CREATE TABLE option list (table options)
......@@ -687,6 +689,7 @@ static int connect_done_func(void *)
delete pc;
} // endfor pc
connect_hton= NULL;
DBUG_RETURN(error);
} // end of connect_done_func
......
......@@ -31,6 +31,8 @@ uint GetJsonGrpSize(void);
static int IsJson(UDF_ARGS *args, uint i);
static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i);
static uint JsonGrpSize = 10;
/* ----------------------------------- JSNX ------------------------------------ */
/*********************************************************************************/
......@@ -1039,6 +1041,14 @@ static void SetChanged(PBSON bsp)
bsp->Changed = true;
} /* end of SetChanged */
/*********************************************************************************/
/* Replaces GetJsonGrpSize not usable when CONNECT is not installed. */
/*********************************************************************************/
static uint GetJsonGroupSize(void)
{
return (JsonGrpSize) ? JsonGrpSize : GetJsonGrpSize();
} // end of GetJsonGroupSize
/*********************************************************************************/
/* Program for SubSet re-initialization of the memory pool. */
/*********************************************************************************/
......@@ -2393,12 +2403,51 @@ void json_object_list_deinit(UDF_INIT* initid)
JsonFreeMem((PGLOBAL)initid->ptr);
} // end of json_object_list_deinit
/*********************************************************************************/
/* Set the value of JsonGrpSize. */
/*********************************************************************************/
my_bool jsonset_grp_size_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) {
strcpy(message, "This function must have 1 integer argument");
return true;
} else
return false;
} // end of jsonset_grp_size_init
long long jsonset_grp_size(UDF_INIT *initid, UDF_ARGS *args, char *, char *)
{
long long n = *(long long*)args->args[0];
JsonGrpSize = (uint)n;
return (long long)GetJsonGroupSize();
} // end of jsonset_grp_size
/*********************************************************************************/
/* Get the value of JsonGrpSize. */
/*********************************************************************************/
my_bool jsonget_grp_size_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
if (args->arg_count != 0) {
strcpy(message, "This function must have no arguments");
return true;
} else
return false;
} // end of jsonget_grp_size_init
long long jsonget_grp_size(UDF_INIT *initid, UDF_ARGS *args, char *, char *)
{
return (long long)GetJsonGroupSize();
} // end of jsonget_grp_size
/*********************************************************************************/
/* Make a Json array from values coming from rows. */
/*********************************************************************************/
my_bool json_array_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
unsigned long reslen, memlen, n = GetJsonGrpSize();
unsigned long reslen, memlen, n = GetJsonGroupSize();
if (args->arg_count != 1) {
strcpy(message, "This function can only accept 1 argument");
......@@ -2458,7 +2507,7 @@ void json_array_grp_clear(UDF_INIT *initid, char*, char*)
PlugSubSet(g, g->Sarea, g->Sarea_Size);
g->Activityp = (PACTIVITY)new(g) JARRAY;
g->N = GetJsonGrpSize();
g->N = GetJsonGroupSize();
} // end of json_array_grp_clear
void json_array_grp_deinit(UDF_INIT* initid)
......@@ -2471,7 +2520,7 @@ void json_array_grp_deinit(UDF_INIT* initid)
/*********************************************************************************/
my_bool json_object_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
unsigned long reslen, memlen, n = GetJsonGrpSize();
unsigned long reslen, memlen, n = GetJsonGroupSize();
if (args->arg_count != 2) {
strcpy(message, "This function requires 2 arguments (key, value)");
......@@ -2529,7 +2578,7 @@ void json_object_grp_clear(UDF_INIT *initid, char*, char*)
PlugSubSet(g, g->Sarea, g->Sarea_Size);
g->Activityp = (PACTIVITY)new(g) JOBJECT;
g->N = GetJsonGrpSize();
g->N = GetJsonGroupSize();
} // end of json_object_grp_clear
void json_object_grp_deinit(UDF_INIT* initid)
......
......@@ -77,6 +77,12 @@ extern "C" {
DllExport char *json_object_list(UDF_EXEC_ARGS);
DllExport void json_object_list_deinit(UDF_INIT*);
DllExport my_bool jsonset_grp_size_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport long long jsonset_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*);
DllExport my_bool jsonget_grp_size_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport long long jsonget_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*);
DllExport my_bool json_array_grp_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport void json_array_grp_add(UDF_INIT *, UDF_ARGS *, char *, char *);
DllExport char *json_array_grp(UDF_EXEC_ARGS);
......
......@@ -217,7 +217,9 @@ DEPARTMENT Json_Array_Grp(NAME)
2452 ["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"]
Warnings:
Warning 1105 Result truncated to json_grp_size values
SET connect_json_grp_size=30;
SELECT JsonSet_Grp_Size(30);
JsonSet_Grp_Size(30)
30
SELECT Json_Object(title, Json_Array_Grp(name) `json_names`) from t3 GROUP BY title;
Json_Object(title, Json_Array_Grp(name) `json_names`)
{"title":"ADMINISTRATOR","names":["GOOSEPEN","FUNNIGUY","SHRINKY"]}
......
......@@ -20,6 +20,8 @@ if (!$HA_CONNECT_SO) {
--eval CREATE FUNCTION json_object_delete RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION json_object_list RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION jsonvalue RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION jsonset_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION jsonget_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO';
--eval CREATE AGGREGATE FUNCTION json_array_grp RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE AGGREGATE FUNCTION json_object_grp RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION jsonget_string RETURNS STRING SONAME '$HA_CONNECT_SO';
......
......@@ -108,7 +108,8 @@ CREATE TABLE t3 (
SELECT Json_Object(SERIALNO, NAME, TITLE, SALARY) FROM t3 WHERE NAME = 'MERCHANT';
SELECT DEPARTMENT, Json_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT;
SET connect_json_grp_size=30;
#SET connect_json_grp_size=30; Deprecated
SELECT JsonSet_Grp_Size(30);
SELECT Json_Object(title, Json_Array_Grp(name) `json_names`) from t3 GROUP BY title;
SELECT Json_Array(DEPARTMENT, Json_Array_Grp(NAME)) FROM t3 GROUP BY DEPARTMENT;
SELECT Json_Object(DEPARTMENT, Json_Array_Grp(NAME) json_NAMES) FROM t3 GROUP BY DEPARTMENT;
......
......@@ -11,6 +11,8 @@ DROP FUNCTION json_object_add;
DROP FUNCTION json_object_delete;
DROP FUNCTION json_object_list;
DROP FUNCTION jsonvalue;
DROP FUNCTION jsonset_grp_size;
DROP FUNCTION jsonget_grp_size;
DROP FUNCTION json_array_grp;
DROP FUNCTION json_object_grp;
DROP FUNCTION jsonget_string;
......
......@@ -2249,7 +2249,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
rc = SQLTables(hstmt, name.ptr(2), name.length(2),
name.ptr(1), name.length(1),
name.ptr(0), name.length(0),
cap->Pat, SQL_NTS);
cap->Pat, cap->Pat ? SQL_NTS : 0);
break;
case CAT_COL:
// rc = SQLSetStmtAttr(hstmt, SQL_ATTR_METADATA_ID,
......@@ -2258,7 +2258,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
rc = SQLColumns(hstmt, name.ptr(2), name.length(2),
name.ptr(1), name.length(1),
name.ptr(0), name.length(0),
cap->Pat, SQL_NTS);
cap->Pat, cap->Pat ? SQL_NTS : 0);
break;
case CAT_KEY:
fnc = "SQLPrimaryKeys";
......
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