Commit bc65996b authored by Olivier Bertrand's avatar Olivier Bertrand

- 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
parent cde07461
This diff was suppressed by a .gitattributes entry.
...@@ -20,25 +20,25 @@ SET(CONNECT_SOURCES ...@@ -20,25 +20,25 @@ SET(CONNECT_SOURCES
ha_connect.cc connect.cc user_connect.cc mycat.cc ha_connect.cc connect.cc user_connect.cc mycat.cc
fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h
array.cpp blkfil.cpp colblk.cpp csort.cpp array.cpp blkfil.cpp colblk.cpp csort.cpp
filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamvct.cpp filamzip.cpp filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamzip.cpp
filter.cpp json.cpp jsonudf.cpp maputil.cpp myconn.cpp myutil.cpp plgdbutl.cpp filter.cpp json.cpp jsonudf.cpp maputil.cpp myconn.cpp myutil.cpp plgdbutl.cpp
reldef.cpp tabcol.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp reldef.cpp tabcol.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp
tabmul.cpp tabmysql.cpp taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp tabmul.cpp tabmysql.cpp taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp
tabvct.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h
engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamzip.h
filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h
mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h
resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h
taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvct.h tabvir.h tabxcl.h taboccur.h tabpivot.h tabsys.h tabtbl.h tabutil.h tabvir.h tabxcl.h
user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
# #
# Definitions that are shared for all OSes # Definitions that are shared for all OSes
# #
add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS) add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS)
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT -DVCT_SUPPORT ) add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT )
# #
...@@ -89,6 +89,18 @@ ELSE(NOT UNIX) ...@@ -89,6 +89,18 @@ ELSE(NOT UNIX)
ENDIF(UNIX) ENDIF(UNIX)
#
# VCT: the VEC format might be not supported in future versions
#
OPTION(CONNECT_WITH_VCT "Compile CONNECT storage engine with VCT support" ON)
IF(CONNECT_WITH_VCT)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} filamvct.cpp tabvct.cpp filamvct.h tabvct.h)
add_definitions(-DVCT_SUPPORT)
ENDIF(CONNECT_WITH_VCT)
# #
# XML # XML
# #
...@@ -236,9 +248,9 @@ ENDIF(CONNECT_WITH_ODBC) ...@@ -236,9 +248,9 @@ ENDIF(CONNECT_WITH_ODBC)
# JDBC # JDBC
# #
IF(APPLE) IF(APPLE)
OPTION(CONNECT_WITH_JDBC "some comment" OFF) OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine without JDBC support" OFF)
ELSE() ELSE()
OPTION(CONNECT_WITH_JDBC "some comment" ON) OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
ENDIF() ENDIF()
IF(CONNECT_WITH_JDBC) IF(CONNECT_WITH_JDBC)
...@@ -252,12 +264,18 @@ IF(CONNECT_WITH_JDBC) ...@@ -252,12 +264,18 @@ IF(CONNECT_WITH_JDBC)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} SET(CONNECT_SOURCES ${CONNECT_SOURCES}
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h
JdbcInterface.java ApacheInterface.java MariadbInterface.java JdbcInterface.java ApacheInterface.java MariadbInterface.java
MysqlInterface.java OracleInterface.java PostgresqlInterface.java) MysqlInterface.java OracleInterface.java PostgresqlInterface.java
JdbcInterface.class ApacheInterface.class MariadbInterface.class
MysqlInterface.class OracleInterface.class PostgresqlInterface.class)
# TODO: Find how to compile and install the java wrapper classes # TODO: Find how to compile and install the java wrapper classes
# Find required libraries and include directories # Find required libraries and include directories
SET (JAVA_SOURCES JdbcInterface.java) SET (JAVA_SOURCES JdbcInterface.java)
add_jar(JdbcInterface ${JAVA_SOURCES}) add_jar(JdbcInterface ${JAVA_SOURCES})
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
SET (JAVA_CLASSES JdbcInterface.class ApacheInterface.class MariadbInterface.class
MysqlInterface.class OracleInterface.class PostgresqlInterface.class)
add_jar(JavaWrappers ${JAVA_CLASSES})
install_jar(JavaWrappers DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
add_definitions(-DJDBC_SUPPORT) add_definitions(-DJDBC_SUPPORT)
ELSE() ELSE()
SET(JDBC_LIBRARY "") SET(JDBC_LIBRARY "")
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
...@@ -220,6 +220,19 @@ public class JdbcInterface { ...@@ -220,6 +220,19 @@ public class JdbcInterface {
} // end of SetTimestampParm } // end of SetTimestampParm
public int SetNullParm(int i, int typ) {
int rc = 0;
try {
pstmt.setNull(i, typ);
} catch (Exception e) {
SetErrmsg(e);
rc = -1;
} // end try/catch
return rc;
} // end of SetNullParm
public int ExecutePrep() { public int ExecutePrep() {
int n = -3; int n = -3;
......
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
...@@ -55,9 +55,8 @@ ...@@ -55,9 +55,8 @@
#if defined(__WIN__) #if defined(__WIN__)
extern "C" HINSTANCE s_hModule; // Saved module handle extern "C" HINSTANCE s_hModule; // Saved module handle
#else // !__WIN__ #endif // __WIN__
#define nullptr 0 #define nullptr 0
#endif // !__WIN__
TYPCONV GetTypeConv(); TYPCONV GetTypeConv();
int GetConvSize(); int GetConvSize();
...@@ -1442,7 +1441,7 @@ bool JDBConn::SetParam(JDBCCOL *colp) ...@@ -1442,7 +1441,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
PGLOBAL& g = m_G; PGLOBAL& g = m_G;
bool rc = false; bool rc = false;
PVAL val = colp->GetValue(); PVAL val = colp->GetValue();
jint n, i = (jint)colp->GetRank(); jint n, jrc = 0, i = (jint)colp->GetRank();
jshort s; jshort s;
jlong lg; jlong lg;
//jfloat f; //jfloat f;
...@@ -1452,69 +1451,74 @@ bool JDBConn::SetParam(JDBCCOL *colp) ...@@ -1452,69 +1451,74 @@ bool JDBConn::SetParam(JDBCCOL *colp)
jstring jst = nullptr; jstring jst = nullptr;
jmethodID dtc, setid = nullptr; jmethodID dtc, setid = nullptr;
switch (val->GetType()) { if (val->GetNullable() && val->IsNull()) {
case TYPE_STRING: if (gmID(g, setid, "SetNullParm", "(II)I"))
if (gmID(g, setid, "SetStringParm", "(ILjava/lang/String;)V"))
return true; return true;
jst = env->NewStringUTF(val->GetCharValue()); jrc = env->CallIntMethod(job, setid, i, (jint)GetJDBCType(val->GetType()));
env->CallVoidMethod(job, setid, i, jst); } else switch (val->GetType()) {
break; case TYPE_STRING:
case TYPE_INT: if (gmID(g, setid, "SetStringParm", "(ILjava/lang/String;)V"))
if (gmID(g, setid, "SetIntParm", "(II)V")) return true;
return true;
n = (jint)val->GetIntValue();
env->CallVoidMethod(job, setid, i, n);
break;
case TYPE_TINY:
case TYPE_SHORT:
if (gmID(g, setid, "SetShortParm", "(IS)V"))
return true;
s = (jshort)val->GetShortValue(); jst = env->NewStringUTF(val->GetCharValue());
env->CallVoidMethod(job, setid, i, s); env->CallVoidMethod(job, setid, i, jst);
break; break;
case TYPE_BIGINT: case TYPE_INT:
if (gmID(g, setid, "SetBigintParm", "(IJ)V")) if (gmID(g, setid, "SetIntParm", "(II)V"))
return true; return true;
lg = (jlong)val->GetBigintValue(); n = (jint)val->GetIntValue();
env->CallVoidMethod(job, setid, i, lg); env->CallVoidMethod(job, setid, i, n);
break; break;
case TYPE_DOUBLE: case TYPE_TINY:
case TYPE_DECIM: case TYPE_SHORT:
if (gmID(g, setid, "SetDoubleParm", "(ID)V")) if (gmID(g, setid, "SetShortParm", "(IS)V"))
return true; return true;
d = (jdouble)val->GetFloatValue(); s = (jshort)val->GetShortValue();
env->CallVoidMethod(job, setid, i, d); env->CallVoidMethod(job, setid, i, s);
break; break;
case TYPE_DATE: case TYPE_BIGINT:
if ((dat = env->FindClass("java/sql/Timestamp")) == nullptr) { if (gmID(g, setid, "SetBigintParm", "(IJ)V"))
strcpy(g->Message, "Cannot find Timestamp class"); return true;
return true;
} else if (!(dtc = env->GetMethodID(dat, "<init>", "(J)V"))) {
strcpy(g->Message, "Cannot find Timestamp class constructor");
return true;
} // endif's
lg = (jlong)val->GetBigintValue() * 1000; lg = (jlong)val->GetBigintValue();
env->CallVoidMethod(job, setid, i, lg);
break;
case TYPE_DOUBLE:
case TYPE_DECIM:
if (gmID(g, setid, "SetDoubleParm", "(ID)V"))
return true;
if ((datobj = env->NewObject(dat, dtc, lg)) == nullptr) { d = (jdouble)val->GetFloatValue();
strcpy(g->Message, "Cannot make Timestamp object"); env->CallVoidMethod(job, setid, i, d);
return true; break;
} else if (gmID(g, setid, "SetTimestampParm", "(ILjava/sql/Timestamp;)V")) case TYPE_DATE:
if ((dat = env->FindClass("java/sql/Timestamp")) == nullptr) {
strcpy(g->Message, "Cannot find Timestamp class");
return true;
} else if (!(dtc = env->GetMethodID(dat, "<init>", "(J)V"))) {
strcpy(g->Message, "Cannot find Timestamp class constructor");
return true;
} // endif's
lg = (jlong)val->GetBigintValue() * 1000;
if ((datobj = env->NewObject(dat, dtc, lg)) == nullptr) {
strcpy(g->Message, "Cannot make Timestamp object");
return true;
} else if (gmID(g, setid, "SetTimestampParm", "(ILjava/sql/Timestamp;)V"))
return true;
env->CallVoidMethod(job, setid, i, datobj);
break;
default:
sprintf(g->Message, "Parm type %d not supported", val->GetType());
return true; return true;
} // endswitch Type
env->CallVoidMethod(job, setid, i, datobj); if (Check(jrc)) {
break;
default:
sprintf(g->Message, "Parm type %d not supported", val->GetType());
return true;
} // endswitch Type
if (Check()) {
sprintf(g->Message, "SetParam: col=%s msg=%s", colp->GetName(), Msg); sprintf(g->Message, "SetParam: col=%s msg=%s", colp->GetName(), Msg);
rc = true; rc = true;
} // endif msg } // endif msg
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# Do not use any TAB characters for whitespace. # Do not use any TAB characters for whitespace.
# #
############################################################################## ##############################################################################
jdbc : Variable settings depend on machine configuration #jdbc : Variable settings depend on machine configuration
jdbc_new : Variable settings depend on machine configuration #jdbc_new : Variable settings depend on machine configuration
jdbc_oracle : Variable settings depend on machine configuration jdbc_oracle : Variable settings depend on machine configuration
jdbc_postgresql : Variable settings depend on machine configuration jdbc_postgresql : Variable settings depend on machine configuration
...@@ -56,7 +56,7 @@ t1 CREATE TABLE `t1` ( ...@@ -56,7 +56,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC' ) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1; SELECT * FROM t1;
a b a b
0 NULL NULL NULL
0 test00 0 test00
1 test01 1 test01
2 test02 2 test02
...@@ -72,7 +72,7 @@ t1 CREATE TABLE `t1` ( ...@@ -72,7 +72,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC `TABNAME`='t1' ) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC `TABNAME`='t1'
SELECT * FROM t1; SELECT * FROM t1;
a b a b
0 NULL NULL NULL
0 test00 0 test00
1 test01 1 test01
2 test02 2 test02
...@@ -104,7 +104,7 @@ t1 CREATE TABLE `t1` ( ...@@ -104,7 +104,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC ) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC
SELECT * FROM t1; SELECT * FROM t1;
a b a b
0 NULL NULL NULL
0 0 0 0
1 0 1 0
2 0 2 0
......
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