Skip to content

Commit 7b7414c

Browse files
committed
- Add the JDBC table type compilation for CMAKE.
modified: storage/connect/CMakeLists.txt - Fix MDEV-9993 modified: storage/connect/jsonudf.cpp
1 parent 4a62480 commit 7b7414c

File tree

2 files changed

+86
-55
lines changed

2 files changed

+86
-55
lines changed

storage/connect/CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,17 @@ OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
265265

266266
IF(CONNECT_WITH_JDBC)
267267
# TODO: detect Java SDK and the presence of JDBC connectors
268+
# TODO: Find how to compile and install the JdbcInterface.java class
268269
# Find required libraries and include directories
269-
# Find how to compile and install the JdbcInterface.java class
270270

271-
IF(JDBC_OK)
272-
INCLUDE_DIRECTORIES(${JDBC_INCLUDE_DIR})
271+
FIND_PACKAGE(JAVA)
272+
FIND_PACKAGE(JNI)
273+
IF (JAVA_FOUND AND JNI_FOUND)
274+
INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIR})
275+
SET(JNI_LIBRARY ${JNI_LIBRARIES})
276+
SET(CONNECT_SOURCES ${CONNECT_SOURCES} JdbcInterface.java
277+
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h)
273278
add_definitions(-DJDBC_SUPPORT)
274-
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
275-
JdbcInterface.java tabjdbc.cpp jdbconn.cpp jdbccat.h jdbconn.h tabjdbc.h)
276279
ELSE()
277280
SET(JDBC_LIBRARY "")
278281
ENDIF()

storage/connect/jsonudf.cpp

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,37 +3538,9 @@ void jsoncontains_path_deinit(UDF_INIT* initid)
35383538
} // end of jsoncontains_path_deinit
35393539

35403540
/*********************************************************************************/
3541-
/* Set Json items of a Json document according to path. */
3541+
/* This function is used by the json_set/insert/update_item functions. */
35423542
/*********************************************************************************/
3543-
my_bool json_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
3544-
{
3545-
unsigned long reslen, memlen;
3546-
int n = IsJson(args, 0);
3547-
3548-
if (!(args->arg_count % 2)) {
3549-
strcpy(message, "This function must have an odd number of arguments");
3550-
return true;
3551-
} else if (!n && args->arg_type[0] != STRING_RESULT) {
3552-
strcpy(message, "First argument must be a json item");
3553-
return true;
3554-
} else
3555-
CalcLen(args, false, reslen, memlen);
3556-
3557-
if (n == 2 && args->args[0]) {
3558-
char fn[_MAX_PATH];
3559-
long fl;
3560-
3561-
memcpy(fn, args->args[0], args->lengths[0]);
3562-
fn[args->lengths[0]] = 0;
3563-
fl = GetFileLength(fn);
3564-
memlen += fl * 3;
3565-
} else if (n != 3)
3566-
memlen += args->lengths[0] * 3;
3567-
3568-
return JsonInit(initid, args, message, true, reslen, memlen);
3569-
} // end of json_set_item_init
3570-
3571-
char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3543+
char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
35723544
unsigned long *res_length, char *is_null, char *error)
35733545
{
35743546
char *p, *path, *str = NULL;
@@ -3586,12 +3558,16 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
35863558
} else if (initid->const_item)
35873559
g->N = 1;
35883560

3589-
if (!strcmp(result, "$insert"))
3561+
if (!strcmp(result, "$set"))
3562+
w = 0;
3563+
else if (!strcmp(result, "$insert"))
35903564
w = 1;
35913565
else if (!strcmp(result, "$update"))
35923566
w = 2;
3593-
else
3594-
w = 0;
3567+
else {
3568+
PUSH_WARNING("Logical error, please contact CONNECT developer");
3569+
goto err;
3570+
} // endelse
35953571

35963572
// Save stack and allocation environment and prepare error return
35973573
if (g->jump_level == MAX_JUMP) {
@@ -3660,17 +3636,55 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
36603636
// Keep result of constant function
36613637
g->Activityp = (PACTIVITY)str;
36623638

3663-
err:
3639+
err:
36643640
g->jump_level--;
36653641

3666-
fin:
3642+
fin:
36673643
if (!str) {
36683644
*is_null = 1;
36693645
*res_length = 0;
36703646
} else
36713647
*res_length = strlen(str);
36723648

36733649
return str;
3650+
} // end of handle_item
3651+
3652+
/*********************************************************************************/
3653+
/* Set Json items of a Json document according to path. */
3654+
/*********************************************************************************/
3655+
my_bool json_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
3656+
{
3657+
unsigned long reslen, memlen;
3658+
int n = IsJson(args, 0);
3659+
3660+
if (!(args->arg_count % 2)) {
3661+
strcpy(message, "This function must have an odd number of arguments");
3662+
return true;
3663+
} else if (!n && args->arg_type[0] != STRING_RESULT) {
3664+
strcpy(message, "First argument must be a json item");
3665+
return true;
3666+
} else
3667+
CalcLen(args, false, reslen, memlen);
3668+
3669+
if (n == 2 && args->args[0]) {
3670+
char fn[_MAX_PATH];
3671+
long fl;
3672+
3673+
memcpy(fn, args->args[0], args->lengths[0]);
3674+
fn[args->lengths[0]] = 0;
3675+
fl = GetFileLength(fn);
3676+
memlen += fl * 3;
3677+
} else if (n != 3)
3678+
memlen += args->lengths[0] * 3;
3679+
3680+
return JsonInit(initid, args, message, true, reslen, memlen);
3681+
} // end of json_set_item_init
3682+
3683+
char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3684+
unsigned long *res_length, char *is_null, char *p)
3685+
{
3686+
strcpy(result, "$set");
3687+
return handle_item(initid, args, result, res_length, is_null, p);
36743688
} // end of json_set_item
36753689

36763690
void json_set_item_deinit(UDF_INIT* initid)
@@ -3690,7 +3704,7 @@ char *json_insert_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
36903704
unsigned long *res_length, char *is_null, char *p)
36913705
{
36923706
strcpy(result, "$insert");
3693-
return json_set_item(initid, args, result, res_length, is_null, p);
3707+
return handle_item(initid, args, result, res_length, is_null, p);
36943708
} // end of json_insert_item
36953709

36963710
void json_insert_item_deinit(UDF_INIT* initid)
@@ -3710,7 +3724,7 @@ char *json_update_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
37103724
unsigned long *res_length, char *is_null, char *p)
37113725
{
37123726
strcpy(result, "$update");
3713-
return json_set_item(initid, args, result, res_length, is_null, p);
3727+
return handle_item(initid, args, result, res_length, is_null, p);
37143728
} // end of json_update_item
37153729

37163730
void json_update_item_deinit(UDF_INIT* initid)
@@ -4706,14 +4720,9 @@ void jbin_item_merge_deinit(UDF_INIT* initid)
47064720
} // end of jbin_item_merge_deinit
47074721

47084722
/*********************************************************************************/
4709-
/* Set Json items of a Json document according to path. */
4723+
/* This function is used by the jbin_set/insert/update functions. */
47104724
/*********************************************************************************/
4711-
my_bool jbin_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
4712-
{
4713-
return json_set_item_init(initid, args, message);
4714-
} // end of jbin_set_item_init
4715-
4716-
char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4725+
char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
47174726
unsigned long *res_length, char *is_null, char *error)
47184727
{
47194728
char *p, *path;
@@ -4732,12 +4741,16 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
47324741
} else if (initid->const_item)
47334742
g->N = 1;
47344743

4735-
if (!strcmp(result, "$insert"))
4744+
if (!strcmp(result, "$set"))
4745+
w = 0;
4746+
else if (!strcmp(result, "$insert"))
47364747
w = 1;
47374748
else if (!strcmp(result, "$update"))
47384749
w = 2;
4739-
else
4740-
w = 0;
4750+
else {
4751+
PUSH_WARNING("Logical error, please contact CONNECT developer");
4752+
goto fin;
4753+
} // endelse
47414754

47424755
if (!g->Xchk) {
47434756
if (CheckMemory(g, initid, args, 1, true, false, true)) {
@@ -4791,14 +4804,29 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
47914804
// Keep result of constant function
47924805
g->Activityp = (PACTIVITY)bsp;
47934806

4794-
fin:
4807+
fin:
47954808
if (!bsp) {
47964809
*is_null = 1;
47974810
*res_length = 0;
47984811
} else
47994812
*res_length = sizeof(BSON);
48004813

48014814
return (char*)bsp;
4815+
} // end of bin_handle_item
4816+
4817+
/*********************************************************************************/
4818+
/* Set Json items of a Json document according to path. */
4819+
/*********************************************************************************/
4820+
my_bool jbin_set_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
4821+
{
4822+
return json_set_item_init(initid, args, message);
4823+
} // end of jbin_set_item_init
4824+
4825+
char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4826+
unsigned long *res_length, char *is_null, char *p)
4827+
{
4828+
strcpy(result, "$set");
4829+
return bin_handle_item(initid, args, result, res_length, is_null, p);
48024830
} // end of jbin_set_item
48034831

48044832
void jbin_set_item_deinit(UDF_INIT* initid)
@@ -4818,7 +4846,7 @@ char *jbin_insert_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
48184846
unsigned long *res_length, char *is_null, char *p)
48194847
{
48204848
strcpy(result, "$insert");
4821-
return jbin_set_item(initid, args, result, res_length, is_null, p);
4849+
return bin_handle_item(initid, args, result, res_length, is_null, p);
48224850
} // end of jbin_insert_item
48234851

48244852
void jbin_insert_item_deinit(UDF_INIT* initid)
@@ -4838,7 +4866,7 @@ char *jbin_update_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
48384866
unsigned long *res_length, char *is_null, char *p)
48394867
{
48404868
strcpy(result, "$update");
4841-
return jbin_set_item(initid, args, result, res_length, is_null, p);
4869+
return bin_handle_item(initid, args, result, res_length, is_null, p);
48424870
} // end of jbin_update_item
48434871

48444872
void jbin_update_item_deinit(UDF_INIT* initid)

0 commit comments

Comments
 (0)