changeset 564:c45bfdc2e2c4 onclient

Extend JdbcClient with registering default File Transfer upload and download handlers to support ON CLIENT functionality.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 22 Sep 2021 20:24:13 +0200 (2021-09-22)
parents fa2493d924c8
children 228a529b4059
files onclient.txt src/main/java/org/monetdb/client/JdbcClient.java
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/onclient.txt
+++ b/onclient.txt
@@ -1,8 +1,9 @@
-ON CLIENT support in the MonetDB JDBC driver
+COPY ... ON CLIENT support in the MonetDB JDBC driver nad JdbcClient program.
 
 MonetDB provides the nonstandard COPY INTO statement to perform bulk inserts and
 retrievals, see also
-https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData.
+https://www.monetdb.org/Documentation/ServerAdministration/LoadingBulkData/CSVBulkLoads
+https://www.monetdb.org/Documentation/ServerAdministration/ExportingBulkData
 
 By default, COPY INTO accesses files on the server but it also has a mode to
 access files on the client.  This is supported by the command line tool
@@ -16,7 +17,11 @@ of file transfers.  If you execute, for 
 the server will send a request for file 'data.csv' to the JDBC driver.
 By default, the JDBC driver will refuse with an error message:
 
-	'No file upload handler has been registered with the JDBC driver'.
+	'No file upload handler has been registered with the JDBC driver'
+
+or in JdbcClient:
+	'Error [22000] !HY000!data.csv: No file upload handler has been registered with the JDBC driver;
+	'Error [22000] cannot transfer files from client'
 
 This is for security reasons.  However, you can register a callback to handle
 these requests from the server:
--- a/src/main/java/org/monetdb/client/JdbcClient.java
+++ b/src/main/java/org/monetdb/client/JdbcClient.java
@@ -9,8 +9,10 @@
 package org.monetdb.client;
 
 import org.monetdb.jdbc.MonetDriver;
+import org.monetdb.jdbc.MonetConnection;
 import org.monetdb.util.CmdLineOpts;
 import org.monetdb.util.Exporter;
+import org.monetdb.util.FileTransferHandler;
 import org.monetdb.util.MDBvalidator;
 import org.monetdb.util.OptionsException;
 import org.monetdb.util.SQLExporter;
@@ -337,6 +339,12 @@ public class JdbcClient {	/* cannot (yet
 			dbmd = null;
 		}
 
+		// register file data uploadHandler to allow support for: COPY INTO mytable FROM 'data.csv' ON CLIENT;
+		FileTransferHandler FThandler = new FileTransferHandler("", true);
+		con.unwrap(MonetConnection.class).setUploadHandler(FThandler);
+		// register file data downloadHandler to allow support for: COPY select_query INTO 'data.csv' ON CLIENT;
+		con.unwrap(MonetConnection.class).setDownloadHandler(FThandler);
+
 		stmt = con.createStatement();	// is used by processInteractive(), processBatch(), doDump()
 
 		in = new BufferedReader(new InputStreamReader(System.in));