Skip to content

Commit 46defc4

Browse files
committed
- Fix MDEV-15429 CONNECT engine JDBC handling Postgresql UUID type
Also handle Postgresql sending type VARCHAR for TEXT column and setting length to b x7FFFFFF when the length is unknown. modified: storage/connect/Client.java modified: storage/connect/JavaWrappers.jar modified: storage/connect/JdbcInterface.java modified: storage/connect/PostgresqlInterface.java modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/jdbconn.cpp modified: storage/connect/jdbconn.h modified: storage/connect/mysql-test/connect/r/jdbc_postgresql.result modified: storage/connect/mysql-test/connect/t/jdbc_postgresql.test modified: storage/connect/mysql-test/connect/t/jdbconn.inc modified: storage/connect/plgdbsem.h modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabjdbc.h added: storage/connect/mysql-test/connect/std_data/JavaWrappers.jar
1 parent ed5e84e commit 46defc4

15 files changed

+383
-171
lines changed

storage/connect/Client.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
12
package wrappers;
23

34
import java.io.BufferedReader;
45
import java.io.Console;
56
import java.io.IOException;
67
import java.io.InputStreamReader;
8+
import java.sql.Date;
9+
import java.sql.Time;
10+
import java.sql.Timestamp;
711

812
public class Client {
913
static boolean DEBUG = true;
@@ -58,6 +62,9 @@ public static void main(String[] args) {
5862
String query;
5963
System.out.println("Successfully connected to " + parms[1]);
6064

65+
s = jdi.GetQuoteString();
66+
System.out.println("Qstr = '" + s + "'");
67+
6168
while ((query = getLine("Query: ", false)) != null) {
6269
n = jdi.Execute(query);
6370
System.out.println("Returned n = " + n);
@@ -79,7 +86,11 @@ public static void main(String[] args) {
7986
private static void PrintResult(int ncol) {
8087
// Get result set meta data
8188
int i;
89+
Date date = new Date(0);
90+
Time time = new Time(0);
91+
Timestamp tsp = new Timestamp(0);
8292
String columnName;
93+
Object job;
8394

8495
// Get the column names; column indices start from 1
8596
for (i = 1; i <= ncol; i++) {
@@ -112,6 +123,7 @@ private static void PrintResult(int ncol) {
112123
case java.sql.Types.VARCHAR:
113124
case java.sql.Types.LONGVARCHAR:
114125
case java.sql.Types.CHAR:
126+
case 1111:
115127
System.out.print(jdi.StringField(i, null));
116128
break;
117129
case java.sql.Types.INTEGER:
@@ -120,14 +132,17 @@ private static void PrintResult(int ncol) {
120132
case java.sql.Types.BIGINT:
121133
System.out.print(jdi.BigintField(i, null));
122134
break;
123-
case java.sql.Types.TIMESTAMP:
124-
System.out.print(jdi.TimestampField(i, null));
125-
break;
126135
case java.sql.Types.TIME:
127-
System.out.print(jdi.TimeField(i, null));
136+
time.setTime((long)jdi.TimeField(i, null) * 1000);
137+
System.out.print(time);
128138
break;
129139
case java.sql.Types.DATE:
130-
System.out.print(jdi.DateField(i, null));
140+
date.setTime((long)jdi.DateField(i, null) * 1000);
141+
System.out.print(date);
142+
break;
143+
case java.sql.Types.TIMESTAMP:
144+
tsp.setTime((long)jdi.TimestampField(i, null) * 1000);
145+
System.out.print(tsp);
131146
break;
132147
case java.sql.Types.SMALLINT:
133148
System.out.print(jdi.IntField(i, null));
@@ -141,6 +156,8 @@ private static void PrintResult(int ncol) {
141156
case java.sql.Types.BOOLEAN:
142157
System.out.print(jdi.BooleanField(i, null));
143158
default:
159+
job = jdi.ObjectField(i, null);
160+
System.out.print(job.toString());
144161
break;
145162
} // endswitch Type
146163

storage/connect/JavaWrappers.jar

-24.3 KB
Binary file not shown.

storage/connect/JdbcInterface.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
package wrappers;
22

3-
import java.math.*;
4-
import java.sql.*;
3+
import java.math.BigDecimal;
4+
import java.sql.Connection;
5+
import java.sql.DatabaseMetaData;
6+
import java.sql.Date;
7+
import java.sql.Driver;
8+
import java.sql.DriverManager;
9+
import java.sql.PreparedStatement;
10+
import java.sql.ResultSet;
11+
import java.sql.ResultSetMetaData;
12+
import java.sql.SQLException;
13+
import java.sql.Statement;
14+
import java.sql.Time;
15+
import java.sql.Timestamp;
516
import java.util.Collections;
617
import java.util.Hashtable;
718
import java.util.List;
19+
import java.util.UUID;
820

921
import javax.sql.DataSource;
1022

@@ -223,6 +235,24 @@ public void SetTimestampParm(int i, Timestamp t) {
223235

224236
} // end of SetTimestampParm
225237

238+
public void SetUuidParm(int i, String s) {
239+
try {
240+
UUID uuid;
241+
242+
if (s == null)
243+
uuid = null;
244+
else if (s.isEmpty())
245+
uuid = UUID.randomUUID();
246+
else
247+
uuid = UUID.fromString(s);
248+
249+
pstmt.setObject(i, uuid);
250+
} catch (Exception e) {
251+
SetErrmsg(e);
252+
} // end try/catch
253+
254+
} // end of SetUuidParm
255+
226256
public int SetNullParm(int i, int typ) {
227257
int rc = 0;
228258

@@ -481,6 +511,8 @@ public int ExecuteQuery(String query) {
481511
System.out.println("Executing query '" + query + "'");
482512

483513
try {
514+
if (rs != null)
515+
rs.close();
484516
rs = stmt.executeQuery(query);
485517
rsmd = rs.getMetaData();
486518
ncol = rsmd.getColumnCount();
@@ -708,7 +740,7 @@ public int TimestampField(int n, String name) {
708740
return 0;
709741
} // end of TimestampField
710742

711-
public Object ObjectField(int n, String name) {
743+
public Object ObjectField(int n, String name) {
712744
if (rs == null) {
713745
System.out.println("No result set");
714746
} else try {
@@ -720,6 +752,22 @@ public Object ObjectField(int n, String name) {
720752
return null;
721753
} // end of ObjectField
722754

755+
public String UuidField(int n, String name) {
756+
Object job;
757+
758+
if (rs == null) {
759+
System.out.println("No result set");
760+
} else
761+
try {
762+
job = (n > 0) ? rs.getObject(n) : rs.getObject(name);
763+
return job.toString();
764+
} catch (SQLException se) {
765+
SetErrmsg(se);
766+
} // end try/catch
767+
768+
return null;
769+
} // end of UuidField
770+
723771
public int GetDrivers(String[] s, int mxs) {
724772
int n = 0;
725773
List<Driver> drivers = Collections.list(DriverManager.getDrivers());

storage/connect/PostgresqlInterface.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package wrappers;
22

3-
import java.sql.*;
3+
import java.sql.SQLException;
44
import java.util.Hashtable;
55

66
import javax.sql.DataSource;
7+
78
import org.postgresql.jdbc2.optional.PoolingDataSource;
89

910
public class PostgresqlInterface extends JdbcInterface {
@@ -19,7 +20,7 @@ public PostgresqlInterface(boolean b) {
1920

2021
} // end of constructor
2122

22-
@Override
23+
@Override
2324
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
2425
int rc = 0;
2526
String url = parms[1];

storage/connect/global.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ DllExport BOOL PlugIsAbsolutePath(LPCSTR path);
220220
DllExport bool AllocSarea(PGLOBAL, uint);
221221
DllExport void FreeSarea(PGLOBAL);
222222
DllExport BOOL PlugSubSet(PGLOBAL, void *, uint);
223-
void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw
224223
DllExport char *PlugDup(PGLOBAL g, const char *str);
225224
DllExport void *MakePtr(void *, OFFSET);
226225
DllExport void htrc(char const *fmt, ...);
@@ -231,4 +230,9 @@ DllExport uint GetTraceValue(void);
231230
} // extern "C"
232231
#endif
233232

233+
/***********************************************************************/
234+
/* Non exported routine declarations. */
235+
/***********************************************************************/
236+
void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw
237+
234238
/*-------------------------- End of Global.H --------------------------*/

storage/connect/ha_connect.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@
174174
#define JSONMAX 10 // JSON Default max grp size
175175

176176
extern "C" {
177-
char version[]= "Version 1.06.0006 February 02, 2018";
177+
char version[]= "Version 1.06.0007 March 11, 2018";
178178
#if defined(__WIN__)
179-
char compver[]= "Version 1.06.0006 " __DATE__ " " __TIME__;
179+
char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__;
180180
char slash= '\\';
181181
#else // !__WIN__
182182
char slash= '/';
@@ -288,11 +288,16 @@ static MYSQL_THDVAR_SET(
288288
0, // def (NO)
289289
&xtrace_typelib); // typelib
290290

291-
// Getting exact info values
291+
// Getting exact info values
292292
static MYSQL_THDVAR_BOOL(exact_info, PLUGIN_VAR_RQCMDARG,
293293
"Getting exact info values",
294294
NULL, NULL, 0);
295295

296+
// Enabling cond_push
297+
static MYSQL_THDVAR_BOOL(cond_push, PLUGIN_VAR_RQCMDARG,
298+
"Enabling cond_push",
299+
NULL, NULL, 1); // YES by default
300+
296301
/**
297302
Temporary file usage:
298303
no: Not using temporary file
@@ -427,6 +432,7 @@ handlerton *connect_hton= NULL;
427432
uint GetTraceValue(void)
428433
{return (uint)(connect_hton ? THDVAR(current_thd, xtrace) : 0);}
429434
bool ExactInfo(void) {return THDVAR(current_thd, exact_info);}
435+
bool CondPushEnabled(void) {return THDVAR(current_thd, cond_push);}
430436
USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);}
431437
int GetConvSize(void) {return THDVAR(current_thd, conv_size);}
432438
TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
@@ -3196,7 +3202,7 @@ const COND *ha_connect::cond_push(const COND *cond)
31963202
{
31973203
DBUG_ENTER("ha_connect::cond_push");
31983204

3199-
if (tdbp) {
3205+
if (tdbp && CondPushEnabled()) {
32003206
PGLOBAL& g= xp->g;
32013207
AMT tty= tdbp->GetAmType();
32023208
bool x= (tty == TYPE_AM_MYX || tty == TYPE_AM_XDBC);
@@ -7243,7 +7249,8 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
72437249
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
72447250
MYSQL_SYSVAR(enable_mongo),
72457251
#endif // JAVA_SUPPORT || CMGO_SUPPORT
7246-
NULL
7252+
MYSQL_SYSVAR(cond_push),
7253+
NULL
72477254
};
72487255

72497256
maria_declare_plugin(connect)
@@ -7256,10 +7263,10 @@ maria_declare_plugin(connect)
72567263
PLUGIN_LICENSE_GPL,
72577264
connect_init_func, /* Plugin Init */
72587265
connect_done_func, /* Plugin Deinit */
7259-
0x0106, /* version number (1.05) */
7266+
0x0107, /* version number (1.05) */
72607267
NULL, /* status variables */
72617268
connect_system_variables, /* system variables */
7262-
"1.06.0006", /* string version */
7269+
"1.06.0007", /* string version */
72637270
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
72647271
}
72657272
maria_declare_plugin_end;

0 commit comments

Comments
 (0)