Skip to content

Commit bc65996

Browse files
committed
- Fix MDEV-11267. Insert NULL into JDBC table does not work.
Fixed in JDBConn::SetParam and adding java function SetNullParm. modified: storage/connect/jdbconn.cpp modified: storage/connect/JdbcInterface.java modified: storage/connect/mysql-test/connect/disabled.def modified: storage/connect/mysql-test/connect/r/jdbc_new.result modified: storage/connect/mysql-test/connect/std_data/JdbcMariaDB.jar - MDEV-11067 suggested to add configuration support to the Apache wrapper. Uncommented out to test if it works. modified: storage/connect/CMakeLists.txt added: storage/connect/ApacheInterface.class added: storage/connect/JdbcInterface.class added: storage/connect/MariadbInterface.class added: storage/connect/MysqlInterface.class added: storage/connect/OracleInterface.class added: storage/connect/PostgresqlInterface.class
1 parent cde0746 commit bc65996

13 files changed

+105
-70
lines changed

storage/connect/ApacheInterface.class

2.25 KB
Binary file not shown.

storage/connect/CMakeLists.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ SET(CONNECT_SOURCES
2020
ha_connect.cc connect.cc user_connect.cc mycat.cc
2121
fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h
2222
array.cpp blkfil.cpp colblk.cpp csort.cpp
23-
filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamvct.cpp filamzip.cpp
23+
filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamzip.cpp
2424
filter.cpp json.cpp jsonudf.cpp maputil.cpp myconn.cpp myutil.cpp plgdbutl.cpp
2525
reldef.cpp tabcol.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp
2626
tabmul.cpp tabmysql.cpp taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp
27-
tabvct.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
27+
tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
2828

2929
array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h
30-
engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h
30+
engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamzip.h
3131
filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h
3232
mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h
3333
resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h
34-
taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvct.h tabvir.h tabxcl.h
34+
taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvir.h tabxcl.h
3535
user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
3636

3737
#
3838
# Definitions that are shared for all OSes
3939
#
4040
add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS)
41-
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT -DVCT_SUPPORT )
41+
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT )
4242

4343

4444
#
@@ -89,6 +89,18 @@ ELSE(NOT UNIX)
8989
ENDIF(UNIX)
9090

9191

92+
#
93+
# VCT: the VEC format might be not supported in future versions
94+
#
95+
96+
OPTION(CONNECT_WITH_VCT "Compile CONNECT storage engine with VCT support" ON)
97+
98+
IF(CONNECT_WITH_VCT)
99+
SET(CONNECT_SOURCES ${CONNECT_SOURCES} filamvct.cpp tabvct.cpp filamvct.h tabvct.h)
100+
add_definitions(-DVCT_SUPPORT)
101+
ENDIF(CONNECT_WITH_VCT)
102+
103+
92104
#
93105
# XML
94106
#
@@ -236,9 +248,9 @@ ENDIF(CONNECT_WITH_ODBC)
236248
# JDBC
237249
#
238250
IF(APPLE)
239-
OPTION(CONNECT_WITH_JDBC "some comment" OFF)
251+
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine without JDBC support" OFF)
240252
ELSE()
241-
OPTION(CONNECT_WITH_JDBC "some comment" ON)
253+
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
242254
ENDIF()
243255

244256
IF(CONNECT_WITH_JDBC)
@@ -252,12 +264,18 @@ IF(CONNECT_WITH_JDBC)
252264
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
253265
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h
254266
JdbcInterface.java ApacheInterface.java MariadbInterface.java
255-
MysqlInterface.java OracleInterface.java PostgresqlInterface.java)
267+
MysqlInterface.java OracleInterface.java PostgresqlInterface.java
268+
JdbcInterface.class ApacheInterface.class MariadbInterface.class
269+
MysqlInterface.class OracleInterface.class PostgresqlInterface.class)
256270
# TODO: Find how to compile and install the java wrapper classes
257271
# Find required libraries and include directories
258272
SET (JAVA_SOURCES JdbcInterface.java)
259273
add_jar(JdbcInterface ${JAVA_SOURCES})
260274
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
275+
SET (JAVA_CLASSES JdbcInterface.class ApacheInterface.class MariadbInterface.class
276+
MysqlInterface.class OracleInterface.class PostgresqlInterface.class)
277+
add_jar(JavaWrappers ${JAVA_CLASSES})
278+
install_jar(JavaWrappers DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
261279
add_definitions(-DJDBC_SUPPORT)
262280
ELSE()
263281
SET(JDBC_LIBRARY "")

storage/connect/JdbcInterface.class

16.3 KB
Binary file not shown.

storage/connect/JdbcInterface.jar

-14.9 KB
Binary file not shown.

storage/connect/JdbcInterface.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ public void SetTimestampParm(int i, Timestamp t) {
220220

221221
} // end of SetTimestampParm
222222

223+
public int SetNullParm(int i, int typ) {
224+
int rc = 0;
225+
226+
try {
227+
pstmt.setNull(i, typ);
228+
} catch (Exception e) {
229+
SetErrmsg(e);
230+
rc = -1;
231+
} // end try/catch
232+
233+
return rc;
234+
} // end of SetNullParm
235+
223236
public int ExecutePrep() {
224237
int n = -3;
225238

2.19 KB
Binary file not shown.

storage/connect/MysqlInterface.class

2.18 KB
Binary file not shown.

storage/connect/OracleInterface.class

2.19 KB
Binary file not shown.
2.23 KB
Binary file not shown.

storage/connect/jdbconn.cpp

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@
5555

5656
#if defined(__WIN__)
5757
extern "C" HINSTANCE s_hModule; // Saved module handle
58-
#else // !__WIN__
58+
#endif // __WIN__
5959
#define nullptr 0
60-
#endif // !__WIN__
6160

6261
TYPCONV GetTypeConv();
6362
int GetConvSize();
@@ -1442,7 +1441,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
14421441
PGLOBAL& g = m_G;
14431442
bool rc = false;
14441443
PVAL val = colp->GetValue();
1445-
jint n, i = (jint)colp->GetRank();
1444+
jint n, jrc = 0, i = (jint)colp->GetRank();
14461445
jshort s;
14471446
jlong lg;
14481447
//jfloat f;
@@ -1452,69 +1451,74 @@ bool JDBConn::SetParam(JDBCCOL *colp)
14521451
jstring jst = nullptr;
14531452
jmethodID dtc, setid = nullptr;
14541453

1455-
switch (val->GetType()) {
1456-
case TYPE_STRING:
1457-
if (gmID(g, setid, "SetStringParm", "(ILjava/lang/String;)V"))
1454+
if (val->GetNullable() && val->IsNull()) {
1455+
if (gmID(g, setid, "SetNullParm", "(II)I"))
14581456
return true;
14591457

1460-
jst = env->NewStringUTF(val->GetCharValue());
1461-
env->CallVoidMethod(job, setid, i, jst);
1462-
break;
1463-
case TYPE_INT:
1464-
if (gmID(g, setid, "SetIntParm", "(II)V"))
1465-
return true;
1466-
1467-
n = (jint)val->GetIntValue();
1468-
env->CallVoidMethod(job, setid, i, n);
1469-
break;
1470-
case TYPE_TINY:
1471-
case TYPE_SHORT:
1472-
if (gmID(g, setid, "SetShortParm", "(IS)V"))
1473-
return true;
1458+
jrc = env->CallIntMethod(job, setid, i, (jint)GetJDBCType(val->GetType()));
1459+
} else switch (val->GetType()) {
1460+
case TYPE_STRING:
1461+
if (gmID(g, setid, "SetStringParm", "(ILjava/lang/String;)V"))
1462+
return true;
14741463

1475-
s = (jshort)val->GetShortValue();
1476-
env->CallVoidMethod(job, setid, i, s);
1477-
break;
1478-
case TYPE_BIGINT:
1479-
if (gmID(g, setid, "SetBigintParm", "(IJ)V"))
1480-
return true;
1464+
jst = env->NewStringUTF(val->GetCharValue());
1465+
env->CallVoidMethod(job, setid, i, jst);
1466+
break;
1467+
case TYPE_INT:
1468+
if (gmID(g, setid, "SetIntParm", "(II)V"))
1469+
return true;
14811470

1482-
lg = (jlong)val->GetBigintValue();
1483-
env->CallVoidMethod(job, setid, i, lg);
1484-
break;
1485-
case TYPE_DOUBLE:
1486-
case TYPE_DECIM:
1487-
if (gmID(g, setid, "SetDoubleParm", "(ID)V"))
1488-
return true;
1471+
n = (jint)val->GetIntValue();
1472+
env->CallVoidMethod(job, setid, i, n);
1473+
break;
1474+
case TYPE_TINY:
1475+
case TYPE_SHORT:
1476+
if (gmID(g, setid, "SetShortParm", "(IS)V"))
1477+
return true;
14891478

1490-
d = (jdouble)val->GetFloatValue();
1491-
env->CallVoidMethod(job, setid, i, d);
1492-
break;
1493-
case TYPE_DATE:
1494-
if ((dat = env->FindClass("java/sql/Timestamp")) == nullptr) {
1495-
strcpy(g->Message, "Cannot find Timestamp class");
1496-
return true;
1497-
} else if (!(dtc = env->GetMethodID(dat, "<init>", "(J)V"))) {
1498-
strcpy(g->Message, "Cannot find Timestamp class constructor");
1499-
return true;
1500-
} // endif's
1479+
s = (jshort)val->GetShortValue();
1480+
env->CallVoidMethod(job, setid, i, s);
1481+
break;
1482+
case TYPE_BIGINT:
1483+
if (gmID(g, setid, "SetBigintParm", "(IJ)V"))
1484+
return true;
15011485

1502-
lg = (jlong)val->GetBigintValue() * 1000;
1486+
lg = (jlong)val->GetBigintValue();
1487+
env->CallVoidMethod(job, setid, i, lg);
1488+
break;
1489+
case TYPE_DOUBLE:
1490+
case TYPE_DECIM:
1491+
if (gmID(g, setid, "SetDoubleParm", "(ID)V"))
1492+
return true;
15031493

1504-
if ((datobj = env->NewObject(dat, dtc, lg)) == nullptr) {
1505-
strcpy(g->Message, "Cannot make Timestamp object");
1506-
return true;
1507-
} else if (gmID(g, setid, "SetTimestampParm", "(ILjava/sql/Timestamp;)V"))
1494+
d = (jdouble)val->GetFloatValue();
1495+
env->CallVoidMethod(job, setid, i, d);
1496+
break;
1497+
case TYPE_DATE:
1498+
if ((dat = env->FindClass("java/sql/Timestamp")) == nullptr) {
1499+
strcpy(g->Message, "Cannot find Timestamp class");
1500+
return true;
1501+
} else if (!(dtc = env->GetMethodID(dat, "<init>", "(J)V"))) {
1502+
strcpy(g->Message, "Cannot find Timestamp class constructor");
1503+
return true;
1504+
} // endif's
1505+
1506+
lg = (jlong)val->GetBigintValue() * 1000;
1507+
1508+
if ((datobj = env->NewObject(dat, dtc, lg)) == nullptr) {
1509+
strcpy(g->Message, "Cannot make Timestamp object");
1510+
return true;
1511+
} else if (gmID(g, setid, "SetTimestampParm", "(ILjava/sql/Timestamp;)V"))
1512+
return true;
1513+
1514+
env->CallVoidMethod(job, setid, i, datobj);
1515+
break;
1516+
default:
1517+
sprintf(g->Message, "Parm type %d not supported", val->GetType());
15081518
return true;
1519+
} // endswitch Type
15091520

1510-
env->CallVoidMethod(job, setid, i, datobj);
1511-
break;
1512-
default:
1513-
sprintf(g->Message, "Parm type %d not supported", val->GetType());
1514-
return true;
1515-
} // endswitch Type
1516-
1517-
if (Check()) {
1521+
if (Check(jrc)) {
15181522
sprintf(g->Message, "SetParam: col=%s msg=%s", colp->GetName(), Msg);
15191523
rc = true;
15201524
} // endif msg

0 commit comments

Comments
 (0)