1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

- Reconize the JDBC type -7 (BIT)

modified:   storage/connect/jdbconn.cpp

- Add the global variable connect_java_wrapper
  This enables to use different wrappers
  modified:   storage/connect/CMakeLists.txt
  renamed:    storage/connect/java/ap/JdbcInterface.class -> storage/connect/JdbcApacheInterface.class
  renamed:    storage/connect/java/ap/JdbcInterface.java -> storage/connect/JdbcApacheInterface.java
  renamed:    storage/connect/java/ds/JdbcInterface.class -> storage/connect/JdbcDSInterface.class
  renamed:    storage/connect/java/ds/JdbcInterface.java -> storage/connect/JdbcDSInterface.java
  modified:   storage/connect/ha_connect.cc
  deleted:    storage/connect/java/std/JdbcInterface.class
  deleted:    storage/connect/java/std/JdbcInterface.java
  modified:   storage/connect/jdbconn.cpp
  modified:   storage/connect/jdbconn.h

- Add JDBC tests (disabled)
  modified:   storage/connect/mysql-test/connect/disabled.def
  new file:   storage/connect/mysql-test/connect/r/jdbc.result
  new file:   storage/connect/mysql-test/connect/r/jdbc_new.result
  new file:   storage/connect/mysql-test/connect/r/jdbc_oracle.result
  new file:   storage/connect/mysql-test/connect/r/jdbc_postgresql.result
  new file:   storage/connect/mysql-test/connect/std_data/girls.txt
  new file:   storage/connect/mysql-test/connect/t/jdbc.test
  new file:   storage/connect/mysql-test/connect/t/jdbc_new.test
  new file:   storage/connect/mysql-test/connect/t/jdbc_oracle.test
  new file:   storage/connect/mysql-test/connect/t/jdbc_postgresql.test
  new file:   storage/connect/mysql-test/connect/t/jdbconn.inc
  new file:   storage/connect/mysql-test/connect/t/jdbconn_cleanup.inc

- Typo
  modified:   storage/connect/jsonudf.cpp
This commit is contained in:
Olivier Bertrand
2016-05-26 18:48:47 +02:00
parent afa4657fd3
commit ead4147b13
23 changed files with 1153 additions and 737 deletions

View File

@@ -240,7 +240,7 @@ OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
IF(CONNECT_WITH_JDBC)
# TODO: detect Java SDK and the presence of JDBC connectors
# TODO: Find how to compile and install the JdbcInterface.java class
# TODO: Find how to compile and install the java wrapper class
# Find required libraries and include directories
FIND_PACKAGE(Java)
@@ -251,6 +251,8 @@ IF(CONNECT_WITH_JDBC)
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY})
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
JdbcInterface.java JdbcInterface.class
JdbcDSInterface.java JdbcDSInterface.class
JdbcApacheInterface.java JdbcApacheInterface.class
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h)
add_definitions(-DJDBC_SUPPORT)
ELSE()

View File

@@ -6,7 +6,7 @@ import java.util.List;
import org.apache.commons.dbcp2.BasicDataSource;
public class JdbcInterface {
public class JdbcApacheInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
@@ -18,11 +18,11 @@ public class JdbcInterface {
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
// === Constructors/finalize =========================================
public JdbcInterface() {
public JdbcApacheInterface() {
this(true);
} // end of default constructor
public JdbcInterface(boolean b) {
public JdbcApacheInterface(boolean b) {
DEBUG = b;
} // end of constructor
@@ -706,4 +706,4 @@ public class JdbcInterface {
} // end of addLibraryPath
*/
} // end of class JdbcInterface
} // end of class JdbcApacheInterface

View File

@@ -11,7 +11,7 @@ import org.postgresql.jdbc2.optional.PoolingDataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
import oracle.jdbc.pool.OracleDataSource;
public class JdbcInterface {
public class JdbcDSInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
@@ -23,11 +23,11 @@ public class JdbcInterface {
Hashtable<String,DataSource> dst = null;
// === Constructors/finalize =========================================
public JdbcInterface() {
public JdbcDSInterface() {
this(true);
} // end of default constructor
public JdbcInterface(boolean b) {
public JdbcDSInterface(boolean b) {
DEBUG = b;
dst = new Hashtable<String, DataSource>();
} // end of constructor
@@ -740,4 +740,4 @@ public class JdbcInterface {
} // end of addLibraryPath
*/
} // end of class JdbcInterface
} // end of class JdbcDSInterface

View File

@@ -195,6 +195,7 @@ extern "C" {
#if defined(JDBC_SUPPORT)
char *JvmPath;
char *ClassPath;
char *Wrapper;
#endif // JDBC_SUPPORT
#if defined(__WIN__)
@@ -6874,6 +6875,12 @@ static MYSQL_SYSVAR_STR(class_path, ClassPath,
"Java class path",
// check_class_path, update_class_path,
NULL, NULL, NULL);
static MYSQL_SYSVAR_STR(java_wrapper, Wrapper,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java wrapper class",
// check_class_path, update_class_path,
NULL, NULL, "JdbcInterface");
#endif // JDBC_SUPPORT
@@ -6897,6 +6904,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
#if defined(JDBC_SUPPORT)
MYSQL_SYSVAR(jvm_path),
MYSQL_SYSVAR(class_path),
MYSQL_SYSVAR(java_wrapper),
#endif // JDBC_SUPPORT
NULL
};

View File

@@ -1,712 +0,0 @@
import java.math.*;
import java.sql.*;
//import java.util.Arrays;
import java.util.Collections;
import java.util.List;
//import java.io.File;
//import java.lang.reflect.Field;
public class JdbcInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
// === Constructors/finalize =========================================
public JdbcInterface() {
this(true);
} // end of default constructor
public JdbcInterface(boolean b) {
DEBUG = b;
} // end of constructor
private void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
if (DEBUG)
System.out.println("In JdbcInterface: driver=" + parms[0]);
try {
if (DEBUG)
System.out.println("In try block");
if (parms[0] != null && !parms[0].isEmpty()) {
if (DEBUG)
System.out.println("Loading class" + parms[0]);
Class.forName(parms[0]); //loads the driver
} // endif driver
if (DEBUG)
System.out.println("URL=" + parms[1]);
if (parms[2] != null && !parms[2].isEmpty()) {
if (DEBUG)
System.out.println("user=" + parms[2] + " pwd=" + parms[3]);
conn = DriverManager.getConnection(parms[1], parms[2], parms[3]);
} else
conn = DriverManager.getConnection(parms[1]);
if (DEBUG)
System.out.println("Connection " + conn.toString() + " established");
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
} catch(ClassNotFoundException e) {
SetErrmsg(e);
rc = -1;
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
public int CreatePrepStmt(String sql) {
int rc = 0;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException se) {
SetErrmsg(se);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -2;
} // end try/catch
return rc;
} // end of CreatePrepStmt
public void SetStringParm(int i, String s) {
try {
pstmt.setString(i, s);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetStringParm
public void SetIntParm(int i, int n) {
try {
pstmt.setInt(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetIntParm
public void SetShortParm(int i, short n) {
try {
pstmt.setShort(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetShortParm
public void SetBigintParm(int i, long n) {
try {
pstmt.setLong(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetBigintParm
public void SetFloatParm(int i, float f) {
try {
pstmt.setFloat(i, f);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetFloatParm
public void SetDoubleParm(int i, double d) {
try {
pstmt.setDouble(i, d);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetDoubleParm
public void SetTimestampParm(int i, Timestamp t) {
try {
pstmt.setTimestamp(i, t);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetTimestampParm
public int ExecutePrep() {
int n = -3;
if (pstmt != null) try {
n = pstmt.executeUpdate();
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecutePrep
public boolean ClosePrepStmt() {
boolean b = false;
if (pstmt != null) try {
pstmt.close();
pstmt = null;
} catch (SQLException se) {
SetErrmsg(se);
b = true;
} catch (Exception e) {
SetErrmsg(e);
b = true;
} // end try/catch
return b;
} // end of ClosePrepStmt
public int JdbcDisconnect() {
int rc = 0;
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
rc += 1;
} // nothing more we can do
// Close the statement and the connection
if (rs != null)
try {
if (DEBUG)
System.out.println("Closing result set");
rs.close();
} catch(SQLException se) {
SetErrmsg(se);
rc = 2;
} // nothing more we can do
if (stmt != null)
try {
if (DEBUG)
System.out.println("Closing statement");
stmt.close();
} catch(SQLException se) {
SetErrmsg(se);
rc += 4;
} // nothing more we can do
ClosePrepStmt();
if (conn != null)
try {
if (DEBUG)
System.out.println("Closing connection");
conn.close();
} catch (SQLException se) {
SetErrmsg(se);
rc += 8;
} //end try/catch
if (DEBUG)
System.out.println("All closed");
return rc;
} // end of JdbcDisconnect
public int GetMaxValue(int n) {
int m = 0;
try {
switch (n) {
case 1: // Max columns in table
m = dbmd.getMaxColumnsInTable();
break;
case 2: // Max catalog name length
m = dbmd.getMaxCatalogNameLength();
break;
case 3: // Max schema name length
m = dbmd.getMaxSchemaNameLength();
break;
case 4: // Max table name length
m = dbmd.getMaxTableNameLength();
break;
case 5: // Max column name length
m = dbmd.getMaxColumnNameLength();
break;
} // endswitch n
} catch(Exception e) {
SetErrmsg(e);
m = -1;
} // end try/catch
return m;
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
String[] typ = null;
if (parms[3] != null) {
typ = new String[1];
typ[0] = parms[3];
} // endif parms
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int Execute(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing '" + query + "'");
try {
boolean b = stmt.execute(query);
if (b == false) {
n = stmt.getUpdateCount();
if (rs != null) rs.close();
} // endif b
if (DEBUG)
System.out.println("Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of Execute
public int GetResult() {
int ncol = 0;
try {
rs = stmt.getResultSet();
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG)
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif rs
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of GetResult
public int ExecuteQuery(String query) {
int ncol = 0;
if (DEBUG)
System.out.println("Executing query '" + query + "'");
try {
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG) {
System.out.println("Query '" + query + "' executed successfully");
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif DEBUG
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of ExecuteQuery
public int ExecuteUpdate(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing update query '" + query + "'");
try {
n = stmt.executeUpdate(query);
if (DEBUG)
System.out.println("Update Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecuteUpdate
public int ReadNext() {
if (rs != null) {
try {
return rs.next() ? 1 : 0;
} catch (SQLException se) {
SetErrmsg(se);
return -1;
} //end try/catch
} else
return 0;
} // end of ReadNext
public boolean Fetch(int row) {
if (rs != null) {
try {
return rs.absolute(row);
} catch (SQLException se) {
SetErrmsg(se);
return false;
} //end try/catch
} else
return false;
} // end of Fetch
public String ColumnName(int n) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnName
public int ColumnType(int n, String name) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
if (n == 0)
n = rs.findColumn(name);
return rsmd.getColumnType(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 666; // Not a type
} // end of ColumnType
public String ColumnDesc(int n, int[] val) {
if (rsmd == null) {
System.out.println("No result metadata");
return null;
} else try {
val[0] = rsmd.getColumnType(n);
val[1] = rsmd.getPrecision(n);
val[2] = rsmd.getScale(n);
val[3] = rsmd.isNullable(n);
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnDesc
public String StringField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getString(n) : rs.getString(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of StringField
public int IntField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getInt(n) : rs.getInt(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of IntField
public long BigintField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of BiginttField
public double DoubleField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDouble(n) : rs.getDouble(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0.;
} // end of DoubleField
public float FloatField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getFloat(n) : rs.getFloat(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of FloatField
public boolean BooleanField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getBoolean(n) : rs.getBoolean(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of DateField
public Time TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimestampField
public String ObjectField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getObject(n).toString() : rs.getObject(name).toString();
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ObjectField
public int GetDrivers(String[] s, int mxs) {
int n = 0;
List<Driver> drivers = Collections.list(DriverManager.getDrivers());
int size = Math.min(mxs, drivers.size());
for (int i = 0; i < size; i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
s[n++] = driver.getClass().getName();
// Get version info
s[n++] = driver.getMajorVersion() + "." + driver.getMinorVersion();
s[n++] = driver.jdbcCompliant() ? "Yes" : "No";
s[n++] = driver.toString();
} // endfor i
return size;
} // end of GetDrivers
/**
* Adds the specified path to the java library path
* from Fahd Shariff blog
*
* @param pathToAdd the path to add
static public int addLibraryPath(String pathToAdd) {
System.out.println("jpath = " + pathToAdd);
try {
Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
String[] paths = (String[])usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
System.out.println("path = " + path);
if (path.equals(pathToAdd))
return -5;
} // endfor path
//add the new path
String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[paths.length] = pathToAdd;
usrPathsField.set(null, newPaths);
System.setProperty("java.library.path",
System.getProperty("java.library.path") + File.pathSeparator + pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
SetErrmsg(e);
return -1;
} // end try/catch
return 0;
} // end of addLibraryPath
*/
} // end of class JdbcInterface

View File

@@ -53,8 +53,9 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // !__WIN__
int GetConvSize();
extern char *JvmPath; // The connect_jvm_path global variable value
extern char *ClassPath; // The connect_class_path global variable value
extern char *JvmPath; // The connect_jvm_path global variable value
extern char *ClassPath; // The connect_class_path global variable value
extern char *Wrapper; // The connect_java_wrapper global variable value
/***********************************************************************/
/* Static JDBConn objects. */
@@ -645,8 +646,8 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
m_Tdb = tdbp;
jvm = nullptr; // Pointer to the JVM (Java Virtual Machine)
env= nullptr; // Pointer to native interface
jdi = nullptr; // Pointer to the JdbcInterface class
job = nullptr; // The JdbcInterface class object
jdi = nullptr; // Pointer to the java wrapper class
job = nullptr; // The java wrapper class object
xqid = xuid = xid = grs = readid = fetchid = typid = errid = nullptr;
prepid = xpid = pcid = nullptr;
chrfldid = intfldid = dblfldid = fltfldid = datfldid = bigfldid = nullptr;
@@ -1028,11 +1029,11 @@ int JDBConn::Open(PJPARM sop)
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
#endif //_DEBUG
// try to find the JdbcInterface class
jdi = env->FindClass("JdbcInterface");
// try to find the java wrapper class
jdi = env->FindClass(Wrapper);
if (jdi == nullptr) {
strcpy(g->Message, "ERROR: class JdbcInterface not found !");
sprintf(g->Message, "ERROR: class %s not found!", Wrapper);
return RC_FX;
} // endif jdi
@@ -1078,7 +1079,7 @@ int JDBConn::Open(PJPARM sop)
jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V");
if (ctor == nullptr) {
strcpy(g->Message, "ERROR: JdbcInterface constructor not found !");
sprintf(g->Message, "ERROR: %s constructor not found!", Wrapper);
return RC_FX;
} else
job = env->NewObject(jdi, ctor);
@@ -1087,7 +1088,7 @@ int JDBConn::Open(PJPARM sop)
// we can then search for the method we want to call,
// and invoke it for the object:
if (job == nullptr) {
strcpy(g->Message, "JdbcInterface class object not constructed !");
sprintf(g->Message, "%s class object not constructed!", Wrapper);
return RC_FX;
} // endif job
@@ -1328,6 +1329,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
case 4: // INTEGER
case 5: // SMALLINT
case -6: // TINYINT
case -7: // BIT
if (!gmID(g, intfldid, "IntField", "(ILjava/lang/String;)I"))
val->SetValue((int)env->CallIntMethod(job, intfldid, rank, jn));
else
@@ -1393,6 +1395,9 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
break;
case java.sql.Types.BOOLEAN:
System.out.print(jdi.BooleanField(i)); */
case 0: // NULL
val->SetNull(true);
// passthru
default:
val->Reset();
} // endswitch Type

View File

@@ -152,8 +152,8 @@ protected:
TDBJDBC *m_Tdb;
JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine)
JNIEnv *env; // Pointer to native interface
jclass jdi; // Pointer to the JdbcInterface class
jobject job; // The JdbcInterface class object
jclass jdi; // Pointer to the java wrapper class
jobject job; // The java wrapper class object
jmethodID xqid; // The ExecuteQuery method ID
jmethodID xuid; // The ExecuteUpdate method ID
jmethodID xid; // The Execute method ID

View File

@@ -5235,21 +5235,28 @@ my_bool envar_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
if (args->arg_count != 1) {
strcpy(message, "Unique argument must be an environment variable name");
return true;
} else
} else {
initid->maybe_null = true;
return false;
} // endif count
} // end of envar_init
char *envar(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *)
unsigned long *res_length, char *is_null, char *)
{
char *str, name[256];
int n = MY_MIN(args->lengths[0], sizeof(name) - 1);
memcpy(name, args->args[0], n);
name[n] = 0;
str = getenv(name);
*res_length = (str) ? strlen(str) : 0;
if (!(str = getenv(name))) {
*res_length = 0;
*is_null = 1;
} else
*res_length = strlen(str);
return str;
} // end of envar

View File

@@ -1 +1,16 @@
#json_udf_bin : broken upstream in --ps
##############################################################################
#
# List the test cases that are to be disabled temporarily.
#
# Separate the test case name and the comment with ':'.
#
# <testcasename> : BUG#<xxxx> <date disabled> <disabler> <comment>
#
# Do not use any TAB characters for whitespace.
#
##############################################################################
#json_udf_bin : broken upstream in --ps (fixed)
jdbc : Variable settings depend on machine configuration
jdbc_new : Variable settings depend on machine configuration
jdbc_oracle : Variable settings depend on machine configuration
jdbc_postgresql : Variable settings depend on machine configuration

View File

@@ -0,0 +1,269 @@
CREATE DATABASE connect;
USE connect;
CREATE TABLE t2 (
id bigint not null,
msg varchar(500),
tm time,
dt date,
dtm datetime,
ts timestamp);
INSERT INTO t2 VALUES(455000000000, 'A very big number', '18:10:25', '2016-03-16', '1999-12-11 23:01:52', '2015-07-24 09:32:45');
SELECT * FROM t2;
id msg tm dt dtm ts
455000000000 A very big number 18:10:25 2016-03-16 1999-12-11 23:01:52 2015-07-24 09:32:45
#
# Testing JDBC connection to MySQL driver
#
USE test;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=t2 CONNECTION='jdbc:mysql://localhost:PORT/connect?user=root';
SELECT * FROM t1;
id msg tm dt dtm ts
455000000000 A very big number 18:10:25 2016-03-16 1999-12-11 23:01:52 2015-07-24 09:32:45
INSERT INTO t1 VALUES(786325481247, 'Hello!', '19:45:03', '1933-08-10', '1985-11-12 09:02:44', '2014-06-17 10:32:01');
Warnings:
Note 1105 t2: 1 affected rows
SELECT * FROM t1;
id msg tm dt dtm ts
455000000000 A very big number 18:10:25 2016-03-16 1999-12-11 23:01:52 2015-07-24 09:32:45
786325481247 Hello! 19:45:03 1933-08-09 1985-11-12 09:02:44 2014-06-17 10:32:01
DELETE FROM t1 WHERE msg = 'Hello!';
Warnings:
Note 1105 t2: 1 affected rows
SELECT * FROM t1;
id msg tm dt dtm ts
455000000000 A very big number 18:10:25 2016-03-16 1999-12-11 23:01:52 2015-07-24 09:32:45
DROP TABLE t1;
#
# Testing JDBC view
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC SRCDEF='select id, msg, tm, dt from t2' CONNECTION='jdbc:mysql://localhost:PORT/connect?user=root';
SELECT * FROM t1;
id msg tm dt
455000000000 A very big number 18:10:25 2016-03-16
SELECT msg, dt FROM t1;
msg dt
A very big number 2016-03-16
DROP TABLE t1, connect.t2;
#
# Testing JDBC write operations
#
USE connect;
CREATE TABLE boys (
name CHAR(12) NOT NULL,
city CHAR(11),
birth DATE DATE_FORMAT='DD/MM/YYYY',
hired DATE DATE_FORMAT='DD/MM/YYYY' flag=36)
ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='boys.txt' ENDING=1;
SELECT * FROM boys;
name city birth hired
John Boston 1986-01-25 2010-06-02
Henry Boston 1987-06-07 2008-04-01
George San Jose 1981-08-10 2010-06-02
Sam Chicago 1979-11-22 2007-10-10
James Dallas 1992-05-13 2009-12-14
Bill Boston 1986-09-11 2008-02-10
USE test;
CREATE TABLE t3 (
name CHAR(12) NOT NULL,
city CHAR(12),
birth DATE,
hired DATE);
INSERT INTO t3 VALUES('Donald','Atlanta','1999-04-01','2016-03-31'),('Mick','New York','1980-01-20','2002-09-11');
SELECT * FROM t3;
name city birth hired
Donald Atlanta 1999-04-01 2016-03-31
Mick New York 1980-01-20 2002-09-11
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=boys CONNECTION='jdbc:mysql://localhost:PORT/connect?user=root' OPTION_LIST='scrollable=1';
SELECT * FROM t1;
name city birth hired
John Boston 1986-01-25 2010-06-02
Henry Boston 1987-06-07 2008-04-01
George San Jose 1981-08-10 2010-06-02
Sam Chicago 1979-11-22 2007-10-10
James Dallas 1992-05-13 2009-12-14
Bill Boston 1986-09-11 2008-02-10
UPDATE t1 SET city = 'Phoenix' WHERE name = 'Henry';
Warnings:
Note 1105 boys: 1 affected rows
INSERT INTO t1 SELECT * FROM t3;
Warnings:
Note 1105 boys: 2 affected rows
INSERT INTO t1 VALUES('Tom','Seatle','2002-03-15',NULL);
Warnings:
Note 1105 boys: 1 affected rows
SELECT * FROM t1;
name city birth hired
John Boston 1986-01-25 2010-06-02
Henry Phoenix 1987-06-07 2008-04-01
George San Jose 1981-08-10 2010-06-02
Sam Chicago 1979-11-22 2007-10-10
James Dallas 1992-05-13 2009-12-14
Bill Boston 1986-09-11 2008-02-10
Donald Atlanta 1999-04-01 2016-03-31
Mick New York 1980-01-20 2002-09-11
Tom Seatle 2002-03-15 1970-01-01
DROP TABLE t3;
#
# Testing JDBC join operations
#
CREATE TABLE t3 (
name CHAR(9) NOT NULL,
city CHAR(12) NOT NULL,
age INT(2))
engine=CONNECT table_type=FIX file_name='girls.txt';
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN connect.boys b where g.city = b.city;
name name city
Mary John Boston
Susan Sam Chicago
Betty Sam Chicago
Mary Bill Boston
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN t1 b where g.city = b.city;
name name city
Mary John Boston
Susan Sam Chicago
Betty Sam Chicago
Mary Bill Boston
DROP TABLE t1, t3, connect.boys;
#
# Testing MariaDB JDBC driver
#
USE connect;
CREATE TABLE emp (
serialno CHAR(5) NOT NULL,
name VARCHAR(12) NOT NULL FLAG=6,
sex TINYINT(1) NOT NULL,
title VARCHAR(15) NOT NULL FLAG=20,
manager CHAR(5) NOT NULL,
department CHAR(4) NOT NULL FLAG=41,
secretary CHAR(5) NOT NULL FLAG=46,
salary DOUBLE(8,2) NOT NULL FLAG=52)
ENGINE=connect TABLE_TYPE=fix FILE_NAME='employee.dat' ENDING=1;
SELECT * FROM emp;
serialno name sex title manager department secretary salary
74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00
02345 SMITH 1 ENGINEER 31416 2452 11111 9000.00
78943 MERCHANT 1 SALESMAN 70012 0318 24888 8700.00
07654 FUNNIGUY 1 ADMINISTRATOR 40567 0319 33333 8500.00
45678 BUGHAPPY 1 PROGRAMMER 40567 0319 12345 8500.00
34567 BIGHEAD 1 SCIENTIST 31416 2452 11111 8000.00
77777 SHRINKY 2 ADMINISTRATOR 70012 0318 27845 7500.00
74234 WALTER 1 ENGINEER 70012 0318 24888 7400.00
56789 FODDERMAN 1 SALESMAN 40567 0319 12345 7000.00
73452 TONGHO 1 ENGINEER 70012 0318 24888 6800.00
22222 SHORTSIGHT 2 SECRETARY 87777 0021 5500.00
55555 MESSIFUL 2 SECRETARY 40567 0319 12345 5000.50
27845 HONEY 2 SECRETARY 70012 0318 24888 4900.00
98765 GOOSEPEN 1 ADMINISTRATOR 07654 0319 33333 4700.00
11111 CHERRY 2 SECRETARY 31416 2452 4500.00
33333 MONAPENNY 2 SECRETARY 07654 0319 3800.00
12345 KITTY 2 TYPIST 40567 0319 3000.45
24888 PLUMHEAD 2 TYPIST 27845 0318 2800.00
87777 STRONG 1 DIRECTOR 0021 22222 23000.00
76543 BULLOZER 1 SALESMAN 40567 0319 12345 14800.00
70012 WERTHER 1 DIRECTOR 87777 0318 27845 14500.00
40567 QUINN 1 DIRECTOR 87777 0319 55555 14000.00
31416 ORELLY 1 ENGINEER 87777 2452 11111 13400.00
36666 BIGHORN 1 SCIENTIST 31416 2452 11111 11000.00
00137 BROWNY 1 ENGINEER 40567 0319 12345 10500.00
73111 WHEELFOR 1 SALESMAN 70012 0318 24888 10030.00
00023 MARTIN 1 ENGINEER 40567 0319 12345 10000.00
USE test;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`serialno` char(5) NOT NULL,
`name` varchar(12) NOT NULL,
`sex` tinyint(3) NOT NULL,
`title` varchar(15) NOT NULL,
`manager` char(5) NOT NULL,
`department` char(4) NOT NULL,
`secretary` char(5) NOT NULL,
`salary` double(12,2) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root' `TABLE_TYPE`='JDBC' `TABNAME`='emp'
SELECT * FROM t1;
serialno name sex title manager department secretary salary
74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00
02345 SMITH 1 ENGINEER 31416 2452 11111 9000.00
78943 MERCHANT 1 SALESMAN 70012 0318 24888 8700.00
07654 FUNNIGUY 1 ADMINISTRATOR 40567 0319 33333 8500.00
45678 BUGHAPPY 1 PROGRAMMER 40567 0319 12345 8500.00
34567 BIGHEAD 1 SCIENTIST 31416 2452 11111 8000.00
77777 SHRINKY 2 ADMINISTRATOR 70012 0318 27845 7500.00
74234 WALTER 1 ENGINEER 70012 0318 24888 7400.00
56789 FODDERMAN 1 SALESMAN 40567 0319 12345 7000.00
73452 TONGHO 1 ENGINEER 70012 0318 24888 6800.00
22222 SHORTSIGHT 2 SECRETARY 87777 0021 5500.00
55555 MESSIFUL 2 SECRETARY 40567 0319 12345 5000.50
27845 HONEY 2 SECRETARY 70012 0318 24888 4900.00
98765 GOOSEPEN 1 ADMINISTRATOR 07654 0319 33333 4700.00
11111 CHERRY 2 SECRETARY 31416 2452 4500.00
33333 MONAPENNY 2 SECRETARY 07654 0319 3800.00
12345 KITTY 2 TYPIST 40567 0319 3000.45
24888 PLUMHEAD 2 TYPIST 27845 0318 2800.00
87777 STRONG 1 DIRECTOR 0021 22222 23000.00
76543 BULLOZER 1 SALESMAN 40567 0319 12345 14800.00
70012 WERTHER 1 DIRECTOR 87777 0318 27845 14500.00
40567 QUINN 1 DIRECTOR 87777 0319 55555 14000.00
31416 ORELLY 1 ENGINEER 87777 2452 11111 13400.00
36666 BIGHORN 1 SCIENTIST 31416 2452 11111 11000.00
00137 BROWNY 1 ENGINEER 40567 0319 12345 10500.00
73111 WHEELFOR 1 SALESMAN 70012 0318 24888 10030.00
00023 MARTIN 1 ENGINEER 40567 0319 12345 10000.00
SELECT name, title, salary FROM t1 WHERE sex = 1;
name title salary
SMITH ENGINEER 9000.00
MERCHANT SALESMAN 8700.00
FUNNIGUY ADMINISTRATOR 8500.00
BUGHAPPY PROGRAMMER 8500.00
BIGHEAD SCIENTIST 8000.00
WALTER ENGINEER 7400.00
FODDERMAN SALESMAN 7000.00
TONGHO ENGINEER 6800.00
GOOSEPEN ADMINISTRATOR 4700.00
STRONG DIRECTOR 23000.00
BULLOZER SALESMAN 14800.00
WERTHER DIRECTOR 14500.00
QUINN DIRECTOR 14000.00
ORELLY ENGINEER 13400.00
BIGHORN SCIENTIST 11000.00
BROWNY ENGINEER 10500.00
WHEELFOR SALESMAN 10030.00
MARTIN ENGINEER 10000.00
DROP TABLE t1, connect.emp;
CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,message varchar(255) flag=2) ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:mariadb://localhost:PORT/connect' OPTION_LIST='User=root,Execsrc=1';
SELECT * FROM t2 WHERE command='drop table tx1';
command number message
drop table tx1 0 Execute: java.sql.SQLSyntaxErrorException: Unknown table 'connect.tx1'
Query is : drop table tx1
SELECT * FROM t2 WHERE command = 'create table tx1 (a int not null, b char(32), c double(8,2))';
command number message
create table tx1 (a int not null, b char(32), c double(8,2)) 0 Affected rows
SELECT * FROM t2 WHERE command in ('insert into tx1 values(1,''The number one'',456.12)',"insert into tx1(a,b) values(2,'The number two'),(3,'The number three')");
command number message
insert into tx1 values(1,'The number one',456.12) 1 Affected rows
insert into tx1(a,b) values(2,'The number two'),(3,'The number three') 2 Affected rows
SELECT * FROM t2 WHERE command='update tx1 set c = 3.1416 where a = 2';
command number message
update tx1 set c = 3.1416 where a = 2 1 Affected rows
SELECT * FROM t2 WHERE command='select * from tx1';
command number message
select * from tx1 3 Result set column number
SELECT * FROM t2 WHERE command='delete from tx1 where a = 2';
command number message
delete from tx1 where a = 2 1 Affected rows
SELECT * FROM connect.tx1;
a b c
1 The number one 456.12
3 The number three NULL
DROP TABLE t2;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables CONNECTION='jdbc:mariadb://localhost:PORT/connect' option_list='User=root,Maxres=50';
SELECT * FROM t1;
Table_Cat Table_Schema Table_Name Table_Type Remark
connect NULL tx1 BASE TABLE
DROP TABLE t1;
DROP TABLE connect.tx1;
DROP DATABASE connect;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;

View File

@@ -0,0 +1,214 @@
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (NULL,NULL),(0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
a b
NULL NULL
0 test00
1 test01
2 test02
3 test03
#
# Testing errors
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=unknown';
SELECT * FROM t1;
ERROR HY000: Got error 174 'Connecting: java.sql.SQLException: Access denied for user 'unknown'@'localhost' (using password: NO) rc=-2' from CONNECT
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/unknown?user=root';
ERROR HY000: Connecting: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'unknown' rc=-2
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='unknown'
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
ERROR HY000: Cannot get columns from unknown
SHOW CREATE TABLE t1;
ERROR 42S02: Table 'test.t1' doesn't exist
CREATE TABLE t1 (x int, y char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`y` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC
SELECT * FROM t1;
ERROR HY000: Got error 174 'ExecuteQuery: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'x' in 'field list'' from CONNECT
DROP TABLE t1;
CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
ALTER TABLE t1 RENAME t1backup;
SELECT * FROM t1;
ERROR HY000: Got error 174 'ExecuteQuery: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.t1' doesn't exist' from CONNECT
ALTER TABLE t1backup RENAME t1;
DROP TABLE t1;
#
# Testing SELECT, etc.
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(10) DEFAULT NULL,
`b` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1;
a b
0 NULL
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='t1'
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(10) DEFAULT NULL
) 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;
a b
0 NULL
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL, b CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` char(10) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC
SELECT * FROM t1;
a b
0
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a char(10), b int) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC
SELECT * FROM t1;
a b
0 NULL
0 0
1 0
2 0
3 0
DROP TABLE t1;
DROP TABLE t1;
#
# Testing numeric data types
#
CREATE TABLE t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float, g double, h decimal(20,5));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint(4) DEFAULT NULL,
`b` smallint(6) DEFAULT NULL,
`c` mediumint(9) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
`e` bigint(20) DEFAULT NULL,
`f` float DEFAULT NULL,
`g` double DEFAULT NULL,
`h` decimal(20,5) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES(100,3333,41235,1234567890,235000000000,3.14159265,3.14159265,3141.59265);
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint(3) DEFAULT NULL,
`b` smallint(5) DEFAULT NULL,
`c` int(7) DEFAULT NULL,
`d` int(10) DEFAULT NULL,
`e` bigint(19) DEFAULT NULL,
`f` double(14,0) DEFAULT NULL,
`g` double(24,0) DEFAULT NULL,
`h` decimal(27,5) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1;
a b c d e f g h
100 3333 41235 1234567890 235000000000 3 3 3141.59265
DROP TABLE t1;
DROP TABLE t1;
#
# Testing character data types
#
CREATE TABLE t1 (a char(12), b varchar(12));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(12) DEFAULT NULL,
`b` varchar(12) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES('Welcome','Hello, World');
SELECT * FROM t1;
a b
Welcome Hello, World
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(12) DEFAULT NULL,
`b` varchar(12) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1;
a b
Welcome Hello, World
DROP TABLE t1;
DROP TABLE t1;
#
# Testing temporal data types
#
CREATE TABLE t1 (a date, b datetime, c time, d timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, e year);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` datetime DEFAULT NULL,
`c` time DEFAULT NULL,
`d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`e` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES('2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23');
Warnings:
Note 1265 Data truncated for column 'a' at row 1
Note 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'e' at row 1
SELECT * FROM t1;
a b c d e
2003-05-27 2003-05-27 10:45:23 10:45:23 2003-05-27 10:45:23 2003
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`c` time DEFAULT NULL,
`d` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`e` date DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1;
a b c d e
2003-05-27 2003-05-27 10:45:23 10:45:23 2003-05-27 10:45:23 2003-01-01
DROP TABLE t1;
DROP TABLE t1;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;

View File

@@ -0,0 +1,70 @@
CREATE TABLE t2 (
command varchar(128) not null,
number int(5) not null flag=1,
message varchar(255) flag=2)
ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager,Execsrc=1';
SELECT * FROM t2 WHERE command = 'drop table employee';
command number message
drop table employee 0 Execute: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary number(8,2))';
command number message
create table employee (id int not null, name varchar(32), title char(16), salary number(8,2)) 0 Affected rows
SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)";
command number message
insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables
CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager';
SELECT * FROM t1 WHERE table_name='employee';
Table_Cat Table_Schema Table_Name Table_Type Remark
NULL SYSTEM EMPLOYEE TABLE NULL
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='EMPLOYEE' CATFUNC=columns
CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager';
SELECT * FROM t1;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL SYSTEM EMPLOYEE ID 3 NUMBER 38 0 0 10 0 NULL
NULL SYSTEM EMPLOYEE NAME 12 VARCHAR2 32 0 0 10 1 NULL
NULL SYSTEM EMPLOYEE TITLE 1 CHAR 16 0 0 10 1 NULL
NULL SYSTEM EMPLOYEE SALARY 3 NUMBER 8 0 2 10 1 NULL
DROP TABLE t1;
CREATE SERVER 'oracle' FOREIGN DATA WRAPPER 'oracle.jdbc.driver.OracleDriver' OPTIONS (
HOST 'jdbc:oracle:thin:@localhost:1521:xe',
DATABASE 'SYSTEM',
USER 'system',
PASSWORD 'manager',
PORT 0,
SOCKET '',
OWNER 'SYSTEM');
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='oracle' tabname='EMPLOYEE';
SELECT * FROM t1;
ID NAME TITLE SALARY
4567 Johnson Engineer 12560.50
INSERT INTO t1 VALUES(6214, 'Clinton', 'Retired', NULL);
Warnings:
Note 1105 EMPLOYEE: 1 affected rows
UPDATE t1 set name='Trump' WHERE id = 4567;
Warnings:
Note 1105 EMPLOYEE: 1 affected rows
SELECT * FROM t1;
ID NAME TITLE SALARY
4567 Trump Engineer 12560.50
6214 Clinton Retired 0.00
DELETE FROM t1 WHERE id = 6214;
Warnings:
Note 1105 EMPLOYEE: 1 affected rows
SELECT * FROM t1;
ID NAME TITLE SALARY
4567 Trump Engineer 12560.50
DROP TABLE t1;
SELECT * FROM t2 WHERE command = 'drop table employee';
command number message
drop table employee 0 Affected rows
DROP TABLE t2;
DROP SERVER 'oracle';
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;

View File

@@ -0,0 +1,65 @@
CREATE TABLE t2 (
command varchar(128) not null,
number int(5) not null flag=1,
message varchar(255) flag=2)
ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:postgresql://localhost/mtr'
OPTION_LIST='User=mtr,Password=mtr,Schema=public,Execsrc=1';
SELECT * FROM t2 WHERE command='drop table employee';
command number message
drop table employee 0 Execute: org.postgresql.util.PSQLException: ERREUR: la table « employee » n'existe pas
SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2))';
command number message
create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2)) 0 Affected rows
SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)";
command number message
insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables
CONNECTION='jdbc:postgresql://localhost/mtr'
OPTION_LIST='User=mtr,Password=mtr,Schema=public,Tabtype=TABLE,Maxres=10';
SELECT * FROM t1;
Table_Cat Table_Schema Table_Name Table_Type Remark
public employee TABLE NULL
public t1 TABLE NULL
public t2 TABLE NULL
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=columns
CONNECTION='jdbc:postgresql://localhost/mtr' tabname=employee
OPTION_LIST='User=mtr,Password=mtr,Maxres=10';
SELECT * FROM t1;
Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks
NULL public employee id 4 int4 10 0 0 10 0 NULL
NULL public employee name 12 varchar 32 0 0 10 1 NULL
NULL public employee title 1 bpchar 16 0 0 10 1 NULL
NULL public employee salary 2 numeric 8 0 2 10 1 NULL
DROP TABLE t1;
CREATE SERVER 'postgresql' FOREIGN DATA WRAPPER 'postgresql' OPTIONS (
HOST 'localhost',
DATABASE 'mtr',
USER 'mtr',
PASSWORD 'mtr',
PORT 0,
SOCKET '',
OWNER 'root');
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='postgresql/public.employee';
SELECT * FROM t1;
id name title salary
4567 Johnson Engineer 12560.50
INSERT INTO t1 VALUES(3126,'Smith', 'Clerk', 5230.00);
Warnings:
Note 1105 public.employee: 1 affected rows
UPDATE t1 SET salary = salary + 100.00;
Warnings:
Note 1105 public.employee: 2 affected rows
SELECT * FROM t1;
id name title salary
4567 Johnson Engineer 12660.50
3126 Smith Clerk 5330.00
DROP TABLE t1;
DROP SERVER 'postgresql';
SELECT * FROM t2 WHERE command='drop table employee';
command number message
drop table employee 0 Affected rows
DROP TABLE t2;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;

View File

@@ -0,0 +1,5 @@
Mary Boston 25
Nancy Palo Alto 23
Susan Chicago 18
Betty Chicago 32
Anne Denver 23

View File

@@ -0,0 +1,143 @@
-- source jdbconn.inc
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MTR_SUITE_DIR/std_data/girls.txt $MYSQLD_DATADIR/test/girls.txt
let $PORT= `select @@port`;
#
# This test is run against a local MariaDB server
#
CREATE DATABASE connect;
USE connect;
CREATE TABLE t2 (
id bigint not null,
msg varchar(500),
tm time,
dt date,
dtm datetime,
ts timestamp);
INSERT INTO t2 VALUES(455000000000, 'A very big number', '18:10:25', '2016-03-16', '1999-12-11 23:01:52', '2015-07-24 09:32:45');
SELECT * FROM t2;
--echo #
--echo # Testing JDBC connection to MySQL driver
--echo #
USE test;
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=t2 CONNECTION='jdbc:mysql://localhost:$PORT/connect?user=root'
SELECT * FROM t1;
INSERT INTO t1 VALUES(786325481247, 'Hello!', '19:45:03', '1933-08-10', '1985-11-12 09:02:44', '2014-06-17 10:32:01');
SELECT * FROM t1;
DELETE FROM t1 WHERE msg = 'Hello!';
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Testing JDBC view
--echo #
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC SRCDEF='select id, msg, tm, dt from t2' CONNECTION='jdbc:mysql://localhost:$PORT/connect?user=root'
SELECT * FROM t1;
SELECT msg, dt FROM t1;
DROP TABLE t1, connect.t2;
--echo #
--echo # Testing JDBC write operations
--echo #
USE connect;
--copy_file $MTR_SUITE_DIR/std_data/boys.txt $MYSQLD_DATADIR/connect/boys.txt
CREATE TABLE boys (
name CHAR(12) NOT NULL,
city CHAR(11),
birth DATE DATE_FORMAT='DD/MM/YYYY',
hired DATE DATE_FORMAT='DD/MM/YYYY' flag=36)
ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='boys.txt' ENDING=1;
SELECT * FROM boys;
USE test;
CREATE TABLE t3 (
name CHAR(12) NOT NULL,
city CHAR(12),
birth DATE,
hired DATE);
INSERT INTO t3 VALUES('Donald','Atlanta','1999-04-01','2016-03-31'),('Mick','New York','1980-01-20','2002-09-11');
SELECT * FROM t3;
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=boys CONNECTION='jdbc:mysql://localhost:$PORT/connect?user=root' OPTION_LIST='scrollable=1'
SELECT * FROM t1;
UPDATE t1 SET city = 'Phoenix' WHERE name = 'Henry';
INSERT INTO t1 SELECT * FROM t3;
INSERT INTO t1 VALUES('Tom','Seatle','2002-03-15',NULL);
SELECT * FROM t1;
DROP TABLE t3;
--echo #
--echo # Testing JDBC join operations
--echo #
CREATE TABLE t3 (
name CHAR(9) NOT NULL,
city CHAR(12) NOT NULL,
age INT(2))
engine=CONNECT table_type=FIX file_name='girls.txt';
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN connect.boys b where g.city = b.city;
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN t1 b where g.city = b.city;
DROP TABLE t1, t3, connect.boys;
--echo #
--echo # Testing MariaDB JDBC driver
--echo #
USE connect;
--copy_file $MTR_SUITE_DIR/std_data/employee.dat $MYSQLD_DATADIR/connect/employee.dat
CREATE TABLE emp (
serialno CHAR(5) NOT NULL,
name VARCHAR(12) NOT NULL FLAG=6,
sex TINYINT(1) NOT NULL,
title VARCHAR(15) NOT NULL FLAG=20,
manager CHAR(5) NOT NULL,
department CHAR(4) NOT NULL FLAG=41,
secretary CHAR(5) NOT NULL FLAG=46,
salary DOUBLE(8,2) NOT NULL FLAG=52)
ENGINE=connect TABLE_TYPE=fix FILE_NAME='employee.dat' ENDING=1;
SELECT * FROM emp;
USE test;
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:$PORT/connect?user=root'
--replace_result $PORT PORT
--eval SHOW CREATE TABLE t1
SELECT * FROM t1;
SELECT name, title, salary FROM t1 WHERE sex = 1;
DROP TABLE t1, connect.emp;
#
# Testing remote command execution
#
--replace_result $PORT PORT
--eval CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,message varchar(255) flag=2) ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:mariadb://localhost:$PORT/connect' OPTION_LIST='User=root,Execsrc=1'
SELECT * FROM t2 WHERE command='drop table tx1';
SELECT * FROM t2 WHERE command = 'create table tx1 (a int not null, b char(32), c double(8,2))';
SELECT * FROM t2 WHERE command in ('insert into tx1 values(1,''The number one'',456.12)',"insert into tx1(a,b) values(2,'The number two'),(3,'The number three')");
SELECT * FROM t2 WHERE command='update tx1 set c = 3.1416 where a = 2';
SELECT * FROM t2 WHERE command='select * from tx1';
SELECT * FROM t2 WHERE command='delete from tx1 where a = 2';
SELECT * FROM connect.tx1;
DROP TABLE t2;
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables CONNECTION='jdbc:mariadb://localhost:$PORT/connect' option_list='User=root,Maxres=50'
SELECT * FROM t1;
DROP TABLE t1;
DROP TABLE connect.tx1;
#
# Clean up
#
--remove_file $MYSQLD_DATADIR/connect/boys.txt
--remove_file $MYSQLD_DATADIR/connect/employee.dat
DROP DATABASE connect;
--remove_file $MYSQLD_DATADIR/test/girls.txt
-- source jdbconn_cleanup.inc

View File

@@ -0,0 +1,179 @@
#
# This test is run against a remote MySQL server
#
connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
connection master;
-- source jdbconn.inc
connection slave;
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (NULL,NULL),(0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
--echo #
--echo # Testing errors
--echo #
connection master;
# Bad user name
# Suppress "mysql_real_connect failed:" (printed in _DEBUG build)
--replace_result $SLAVE_MYPORT SLAVE_PORT "mysql_real_connect failed: " ""
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=unknown';
--error ER_GET_ERRMSG
SELECT * FROM t1;
DROP TABLE t1;
# Bad database name
--replace_result $SLAVE_MYPORT SLAVE_PORT "mysql_real_connect failed: " ""
--error ER_UNKNOWN_ERROR
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/unknown?user=root';
# Bad table name
--replace_result $SLAVE_MYPORT SLAVE_PORT
--error ER_UNKNOWN_ERROR
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='unknown'
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--error ER_NO_SUCH_TABLE
SHOW CREATE TABLE t1;
# Bad column name
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (x int, y char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
--error ER_GET_ERRMSG
SELECT * FROM t1;
DROP TABLE t1;
# The remote table disappeared
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
connection slave;
ALTER TABLE t1 RENAME t1backup;
connection master;
--error ER_GET_ERRMSG
SELECT * FROM t1;
connection slave;
ALTER TABLE t1backup RENAME t1;
connection master;
DROP TABLE t1;
--echo #
--echo # Testing SELECT, etc.
--echo #
# Automatic table structure
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
# Explicit table structure
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='t1'
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
# Explicit table structure: remote NULL, local NOT NULL
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (a INT NOT NULL, b CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
# Explicit table structure with wrong column types
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (a char(10), b int) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
--echo #
--echo # Testing numeric data types
--echo #
# TODO: mediumint is converted to int, float is converted to double, decimal is converted to double
CREATE TABLE t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float, g double, h decimal(20,5));
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES(100,3333,41235,1234567890,235000000000,3.14159265,3.14159265,3141.59265);
connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
--echo #
--echo # Testing character data types
--echo #
CREATE TABLE t1 (a char(12), b varchar(12));
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES('Welcome','Hello, World');
SELECT * FROM t1;
connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
--echo #
--echo # Testing temporal data types
--echo #
CREATE TABLE t1 (a date, b datetime, c time, d timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, e year);
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES('2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23');
SELECT * FROM t1;
connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:$SLAVE_MYPORT/test?user=root';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
connection slave;
DROP TABLE t1;
connection master;
-- source jdbconn_cleanup.inc

View File

@@ -0,0 +1,56 @@
-- source jdbconn.inc
#
# This test is run against Oracle driver
#
CREATE TABLE t2 (
command varchar(128) not null,
number int(5) not null flag=1,
message varchar(255) flag=2)
ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager,Execsrc=1';
SELECT * FROM t2 WHERE command = 'drop table employee';
SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary number(8,2))';
SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)";
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables
CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager';
SELECT * FROM t1 WHERE table_name='employee';
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME='EMPLOYEE' CATFUNC=columns
CONNECTION='jdbc:oracle:thin:@localhost:1521:xe'
OPTION_LIST='User=system,Password=manager';
SELECT * FROM t1;
DROP TABLE t1;
#
# Test connecting via a Federated server
#
CREATE SERVER 'oracle' FOREIGN DATA WRAPPER 'oracle.jdbc.driver.OracleDriver' OPTIONS (
HOST 'jdbc:oracle:thin:@localhost:1521:xe',
DATABASE 'SYSTEM',
USER 'system',
PASSWORD 'manager',
PORT 0,
SOCKET '',
OWNER 'SYSTEM');
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='oracle' tabname='EMPLOYEE';
SELECT * FROM t1;
INSERT INTO t1 VALUES(6214, 'Clinton', 'Retired', NULL);
UPDATE t1 set name='Trump' WHERE id = 4567;
SELECT * FROM t1;
DELETE FROM t1 WHERE id = 6214;
SELECT * FROM t1;
DROP TABLE t1;
SELECT * FROM t2 WHERE command = 'drop table employee';
DROP TABLE t2;
DROP SERVER 'oracle';
#
# Clean up
#
-- source jdbconn_cleanup.inc

View File

@@ -0,0 +1,53 @@
-- source jdbconn.inc
#
# This test is run against Postgresql driver
#
CREATE TABLE t2 (
command varchar(128) not null,
number int(5) not null flag=1,
message varchar(255) flag=2)
ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:postgresql://localhost/mtr'
OPTION_LIST='User=mtr,Password=mtr,Schema=public,Execsrc=1';
SELECT * FROM t2 WHERE command='drop table employee';
SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2))';
SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)";
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables
CONNECTION='jdbc:postgresql://localhost/mtr'
OPTION_LIST='User=mtr,Password=mtr,Schema=public,Tabtype=TABLE,Maxres=10';
SELECT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=columns
CONNECTION='jdbc:postgresql://localhost/mtr' tabname=employee
OPTION_LIST='User=mtr,Password=mtr,Maxres=10';
SELECT * FROM t1;
DROP TABLE t1;
#
# Test connecting via a Federated server
#
CREATE SERVER 'postgresql' FOREIGN DATA WRAPPER 'postgresql' OPTIONS (
HOST 'localhost',
DATABASE 'mtr',
USER 'mtr',
PASSWORD 'mtr',
PORT 0,
SOCKET '',
OWNER 'root');
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='postgresql/public.employee';
SELECT * FROM t1;
INSERT INTO t1 VALUES(3126,'Smith', 'Clerk', 5230.00);
UPDATE t1 SET salary = salary + 100.00;
SELECT * FROM t1;
DROP TABLE t1;
DROP SERVER 'postgresql';
SELECT * FROM t2 WHERE command='drop table employee';
DROP TABLE t2;
#
# Clean up
#
-- source jdbconn_cleanup.inc

View File

@@ -0,0 +1,31 @@
--source include/not_embedded.inc
--disable_query_log
--error 0,ER_UNKNOWN_ERROR
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=drivers;
if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'
AND ENGINE='CONNECT'
AND (CREATE_OPTIONS LIKE "%`table_type`='JDBC'%" OR CREATE_OPTIONS LIKE '%`table_type`=JDBC%')`)
{
Skip Need Java support;
}
DROP TABLE t1;
# This is specific and explains why this test is disabled.
# You should edit this file to reflect what is the required files location on your machine.
# This is the path to the JVM library (dll or so)
SET GLOBAL connect_jvm_path='C:\\Program Files\\Java\\jdk1.8.0_77\\jre\\bin\\client';
# The complete class path send when creating the Java Virtual Machine is, in that order:
# 1 - The current directory.
# 2 - The paths of the connect_class_path global variable.
# 3 - The paths of the CLASSPATH environment variable.
# These are the paths to the needed classes or jar files. The Apache ones are only for the JdbcApacheInterface wrapper.
SET GLOBAL connect_class_path='E:\\MariaDB-10.1\\Connect\\storage\\connect;E:\\MariaDB-10.1\\Connect\\sql\\data\\postgresql-9.4.1208.jar;E:\\Oracle\\ojdbc6.jar;E:\\Apache\\commons-dbcp2-2.1.1\\commons-dbcp2-2.1.1.jar;E:\\Apache\\commons-pool2-2.4.2\\commons-pool2-2.4.2.jar;E:\\Apache\\commons-logging-1.2\\commons-logging-1.2.jar';
# On my machine, paths to the JDK classes and to the MySQL and MariaDB drivers are defined in the CLASSPATH environment variable
#CREATE FUNCTION envar RETURNS STRING SONAME 'ha_connect.dll';
#SELECT envar('CLASSPATH');
--enable_query_log

View File

@@ -0,0 +1,6 @@
--disable_warnings
#DROP FUNCTION envar;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;
--enable_warnings