annotate src/main/java/org/monetdb/client/JdbcClient.java @ 628:c0f6884b0de4

Add a few extra spaces to get a better indentation and presentation of the list of (system) functions, aggregates and window functions. It now looks more like how mclient presents them.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 20 Jan 2022 20:17:24 +0100 (2022-01-20)
parents d059971d2931
children 844139b33cdd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1 /*
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
5 *
610
6aa38e8c0f2d Updated Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 578
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
7 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
8
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
9 package org.monetdb.client;
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
10
413
f0dfd2003aff Resolved an issue where the JdbcClient sometimes would not find the MonetDB JDBC driver.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
11 import org.monetdb.jdbc.MonetDriver;
564
c45bfdc2e2c4 Extend JdbcClient with registering default File Transfer upload and download handlers to support ON CLIENT functionality.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 467
diff changeset
12 import org.monetdb.jdbc.MonetConnection;
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
13 import org.monetdb.util.CmdLineOpts;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
14 import org.monetdb.util.Exporter;
564
c45bfdc2e2c4 Extend JdbcClient with registering default File Transfer upload and download handlers to support ON CLIENT functionality.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 467
diff changeset
15 import org.monetdb.util.FileTransferHandler;
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
16 import org.monetdb.util.MDBvalidator;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
17 import org.monetdb.util.OptionsException;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
18 import org.monetdb.util.SQLExporter;
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
19 import org.monetdb.util.XMLExporter;
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
20
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
21 import java.io.BufferedReader;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
22 import java.io.BufferedWriter;
466
1bb3885dd240 Defensive line, if the console is not available don't attempt to read from it
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents: 457
diff changeset
23 import java.io.Console;
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
24 import java.io.IOException;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
25 import java.io.InputStreamReader;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
26 import java.io.File;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
27 import java.io.PrintWriter;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
28 import java.net.HttpURLConnection;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
29 import java.net.URL;
578
687034945b3f Pass expected encoding as a constructor parameter to FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 577
diff changeset
30 import java.nio.charset.Charset;
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
31 import java.sql.Connection;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
32 import java.sql.DatabaseMetaData;
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
33 import java.sql.DriverManager; // this import is required as it will trigger loading the org.monetdb.jdbc.MonetDriver class
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
34 import java.sql.ResultSet;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
35 import java.sql.Statement;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
36 import java.sql.SQLException;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
37 import java.sql.SQLWarning;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
38 import java.util.ArrayList;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
39 import java.util.LinkedList;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
40 import java.util.List;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
41
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
42 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
43 * This program acts like an extended client program for MonetDB. Its
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
44 * look and feel is very much like PostgreSQL's interactive terminal
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
45 * program. Although it looks like this client is designed for MonetDB,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
46 * it demonstrates the power of the JDBC interface since it built on top
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
47 * of JDBC only.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
48 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
49 * @author Fabian Groffen
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
50 * @author Martin van Dinther
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
51 * @version 1.7
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
52 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
53
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 388
diff changeset
54 public class JdbcClient { /* cannot (yet) be final as nl.cwi.monetdb.client.JdbcClient extends this class */
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
55
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
56 private static Connection con;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
57 private static DatabaseMetaData dbmd;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
58 private static Statement stmt;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
59 private static BufferedReader in;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
60 private static PrintWriter out;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
61 private static Exporter exporter;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
62
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
63 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
64 * JdbcClient is a command line query tool for MonetDB, similar to mclient.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
65 * It uses the JDBC API and the MonetDB JDBC driver to communicate with a
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
66 * MonetDB server. The MonetDB JDBC driver is included in the jdbcclient.jre8.jar
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
67 * for ease of use, so only 1 jar file is needed to use it.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
68 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
69 * <pre>Usage java -jar jdbcclient.jre8.jar
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
70 * [-h host[:port]] [-p port] [-f file] [-u user]
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
71 * [-l language] [-d database] [-e] [-D [table]]
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
72 * [--csvdir /path/to/csvfiles] [-X&lt;opt&gt;]
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
73 * | [--help] | [--version]
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
74 * or using long option equivalents --host --port --file --user --language
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
75 * --dump --echo --database.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
76 * Arguments may be written directly after the option like -p50000.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
77 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
78 * If no host and port are given, localhost and 50000 are assumed.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
79 * An .monetdb file may exist in the user's home directory. This file can contain
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
80 * preferences to use each time JdbcClient is started. Options given on the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
81 * command line override the preferences file. The .monetdb file syntax is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
82 * &lt;option&gt;=&lt;value&gt; where option is one of the options host, port, file, mode
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
83 * debug, or password. Note that the last one is perilous and therefore not
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
84 * available as command line option.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
85 * If no input file is given using the -f flag, an interactive session is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
86 * started on the terminal.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
87 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
88 * OPTIONS
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
89 * -h --host The hostname of the host that runs the MonetDB database. A port
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
90 * number can be supplied by use of a colon, i.e. -h somehost:12345.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
91 * -p --port The port number to connect to.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
92 * -f --file A file name to use either for reading or writing. The file will
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
93 * be used for writing when dump mode is used (-D --dump). In read
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
94 * mode, the file can also be an URL pointing to a plain text file
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
95 * that is optionally gzip compressed.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
96 * -u --user The username to use when connecting to the database.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
97 * -d --database Try to connect to the given database (only makes sense if
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
98 * connecting to monetdbd).
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
99 * -l --language Use the given language, defaults to 'sql'.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
100 * --help This help screen.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
101 * --version Display driver version and exit.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
102 * -e --echo Also outputs the contents of the input file, if any.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
103 * -q --quiet Suppress printing the welcome header.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
104 * -D --dump Dumps the given table(s), or the complete database if none given.
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
105 * --csvdir The directory path where csv data files wil be read from or
627
d059971d2931 Typo, found by reviewing generated javadoc
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 611
diff changeset
106 * written to when COPY ... ON CLIENT commands are executed.
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
107 * -Xoutput The output mode when dumping. Default is sql, xml may be used for
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
108 * an experimental XML output.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
109 * -Xhash Use the given hash algorithm during challenge response.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
110 * Supported algorithm names: SHA512, SHA384, SHA256 and SHA1.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
111 * -Xdebug Writes a transmission log to disk for debugging purposes. If a
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
112 * file name is given, it is used, otherwise a file called
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
113 * monet&lt;timestamp&gt;.log is created. A given file never be
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
114 * overwritten; instead a unique variation of the file is used.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
115 * -Xbatching Indicates that a batch should be used instead of direct
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
116 * communication with the server for each statement. If a number is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
117 * given, it is used as batch size. i.e. 8000 would execute the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
118 * contents on the batch after each 8000 statements read. Batching
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
119 * can greatly speedup the process of restoring a database dump.</pre>
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
120 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
121 * @param args optional list of startup arguments
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
122 * @throws Exception if uncaught exception is thrown
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
123 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
124 public final static void main(String[] args) throws Exception {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
125 final CmdLineOpts copts = new CmdLineOpts();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
126
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
127 // arguments which take exactly one argument
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
128 copts.addOption("h", "host", CmdLineOpts.CAR_ONE, "localhost",
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
129 "The hostname of the host that runs the MonetDB database. " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
130 "A port number can be supplied by use of a colon, i.e. " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
131 "-h somehost:12345.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
132 copts.addOption("p", "port", CmdLineOpts.CAR_ONE, "50000",
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
133 "The port number to connect to.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
134 // todo make it CAR_ONE_MANY
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
135 copts.addOption("f", "file", CmdLineOpts.CAR_ONE, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
136 "A file name to use either for reading or writing. The " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
137 "file will be used for writing when dump mode is used " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
138 "(-D --dump). In read mode, the file can also be an URL " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
139 "pointing to a plain text file that is optionally gzip " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
140 "compressed.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
141 copts.addOption("u", "user", CmdLineOpts.CAR_ONE, System.getProperty("user.name"),
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
142 "The username to use when connecting to the database.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
143 // this one is only here for the .monetdb file parsing, it is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
144 // removed before the command line arguments are parsed
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
145 copts.addOption(null, "password", CmdLineOpts.CAR_ONE, null, null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
146 copts.addOption("d", "database", CmdLineOpts.CAR_ONE, "",
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
147 "Try to connect to the given database (only makes sense " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
148 "if connecting to monetdbd).");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
149 copts.addOption("l", "language", CmdLineOpts.CAR_ONE, "sql",
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
150 "Use the given language, defaults to 'sql'.");
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
151 copts.addOption(null, "csvdir", CmdLineOpts.CAR_ONE, null,
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
152 "The directory path where csv data files are read or " +
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
153 "written when using ON CLIENT clause of COPY command.");
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
154
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
155 // arguments which have no argument(s)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
156 copts.addOption(null, "help", CmdLineOpts.CAR_ZERO, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
157 "This help screen.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
158 copts.addOption(null, "version", CmdLineOpts.CAR_ZERO, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
159 "Display driver version and exit.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
160 copts.addOption("e", "echo", CmdLineOpts.CAR_ZERO, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
161 "Also outputs the contents of the input file, if any.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
162 copts.addOption("q", "quiet", CmdLineOpts.CAR_ZERO, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
163 "Suppress printing the welcome header.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
164
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
165 // arguments which have zero to many arguments
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
166 copts.addOption("D", "dump", CmdLineOpts.CAR_ZERO_MANY, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
167 "Dumps the given table(s), or the complete database if " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
168 "none given.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
169
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
170 // extended options
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
171 copts.addOption(null, "Xoutput", CmdLineOpts.CAR_ONE, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
172 "The output mode when dumping. Default is sql, xml may " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
173 "be used for an experimental XML output.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
174 copts.addOption(null, "Xhash", CmdLineOpts.CAR_ONE, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
175 "Use the given hash algorithm during challenge response. " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
176 "Supported algorithm names: SHA512, SHA384, SHA256 and SHA1.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
177 // arguments which can have zero or one argument(s)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
178 copts.addOption(null, "Xdebug", CmdLineOpts.CAR_ZERO_ONE, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
179 "Writes a transmission log to disk for debugging purposes. " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
180 "If a file name is given, it is used, otherwise a file " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
181 "called monet<timestamp>.log is created. A given file " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
182 "never be overwritten; instead a unique variation of the " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
183 "file is used.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
184 copts.addOption(null, "Xbatching", CmdLineOpts.CAR_ZERO_ONE, null,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
185 "Indicates that a batch should be used instead of direct " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
186 "communication with the server for each statement. If a " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
187 "number is given, it is used as batch size. i.e. 8000 " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
188 "would execute the contents on the batch after each 8000 " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
189 "statements read. Batching can greatly speedup the " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
190 "process of restoring a database dump.");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
191
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
192 // we store user and password in separate variables in order to
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
193 // be able to properly act on them like forgetting the password
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
194 // from the user's file if the user supplies a username on the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
195 // command line arguments
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
196 String pass = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
197 String user = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
198
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
199 // look for a file called .monetdb in the current dir or in the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
200 // user's homedir and read its preferences
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
201 File pref = new File(".monetdb");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
202 if (!pref.exists())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
203 pref = new File(System.getProperty("user.home"), ".monetdb");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
204 if (pref.exists()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
205 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
206 copts.processFile(pref);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
207 } catch (OptionsException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
208 System.err.println("Error in " + pref.getAbsolutePath() + ": " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
209 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
210 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
211 user = copts.getOption("user").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
212 pass = copts.getOption("password").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
213 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
214
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
215 // process the command line arguments, remove password option
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
216 // first, and save the user we had at this point
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
217 copts.removeOption("password");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
218 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
219 copts.processArgs(args);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
220 } catch (OptionsException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
221 System.err.println("Error: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
222 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
223 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
224 // we can actually compare pointers (objects) here
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
225 if (user != copts.getOption("user").getArgument())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
226 pass = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
227
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
228 if (copts.getOption("help").isPresent()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
229 System.out.print(
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
230 "Usage java -jar jdbcclient.jre8.jar\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
231 "\t\t[-h host[:port]] [-p port] [-f file] [-u user]\n" +
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
232 "\t\t[-l language] [-d database] [-e] [-D [table]]\n" +
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
233 "\t\t[--csvdir /path/to/csvfiles]] [-X<opt>]\n" +
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
234 "\t\t| [--help] | [--version]\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
235 "or using long option equivalents --host --port --file --user --language\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
236 "--dump --echo --database.\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
237 "Arguments may be written directly after the option like -p50000.\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
238 "\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
239 "If no host and port are given, localhost and 50000 are assumed.\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
240 "An .monetdb file may exist in the user's home directory. This file can contain\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
241 "preferences to use each time JdbcClient is started. Options given on the\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
242 "command line override the preferences file. The .monetdb file syntax is\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
243 "<option>=<value> where option is one of the options host, port, file, mode\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
244 "debug, or password. Note that the last one is perilous and therefore not\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
245 "available as command line option.\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
246 "If no input file is given using the -f flag, an interactive session is\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
247 "started on the terminal.\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
248 "\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
249 "OPTIONS\n" +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
250 copts.produceHelpMessage()
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
251 );
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
252 System.exit(0);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
253 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
254
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
255 if (copts.getOption("version").isPresent()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
256 // We cannot use the DatabaseMetaData here, because we
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
257 // cannot get a Connection. So instead, we just get the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
258 // values we want out of the Driver directly.
413
f0dfd2003aff Resolved an issue where the JdbcClient sometimes would not find the MonetDB JDBC driver.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
259 System.out.println("JDBC Driver: v" + MonetDriver.getDriverVersion());
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
260 System.exit(0);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
261 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
262
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
263 // whether the semi-colon at the end of a String terminates the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
264 // query or not (default = yes => SQL)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
265 final boolean scolonterm = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
266 final boolean xmlMode = "xml".equals(copts.getOption("Xoutput").getArgument());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
267
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
268 // we need the password from the user, fetch it with a pseudo
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
269 // password protector
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
270 if (pass == null) {
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
271 final Console syscon = System.console();
466
1bb3885dd240 Defensive line, if the console is not available don't attempt to read from it
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents: 457
diff changeset
272 char[] tmp = null;
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
273 if (syscon != null) {
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
274 tmp = syscon.readPassword("password: ");
466
1bb3885dd240 Defensive line, if the console is not available don't attempt to read from it
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents: 457
diff changeset
275 }
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
276 if (tmp == null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
277 System.err.println("Invalid password!");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
278 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
279 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
280 pass = String.valueOf(tmp);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
281 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
282
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
283 user = copts.getOption("user").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
284
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
285 // build the hostname
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
286 String host = copts.getOption("host").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
287 if (host.indexOf(":") == -1) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
288 host = host + ":" + copts.getOption("port").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
289 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
290
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
291 // build the extra arguments of the JDBC connect string
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
292 String attr = "?";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
293 CmdLineOpts.OptionContainer oc = copts.getOption("language");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
294 final String lang = oc.getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
295 if (oc.isPresent())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
296 attr += "language=" + lang + "&";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
297
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
298 /* Xquery is no longer functional or supported
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
299 // set some behaviour based on the language XQuery
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
300 if (lang.equals("xquery")) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
301 scolonterm = false; // no ; to end a statement
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
302 if (!copts.getOption("Xoutput").isPresent())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
303 xmlMode = true; // the user will like xml results, most probably
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
304 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
305 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
306 oc = copts.getOption("Xdebug");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
307 if (oc.isPresent()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
308 attr += "debug=true&";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
309 if (oc.getArgumentCount() == 1)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
310 attr += "logfile=" + oc.getArgument() + "&";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
311 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
312 oc = copts.getOption("Xhash");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
313 if (oc.isPresent())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
314 attr += "hash=" + oc.getArgument() + "&";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
315
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
316 // request a connection suitable for MonetDB from the driver
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
317 // manager note that the database specifier is only used when
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
318 // connecting to a proxy-like service, since MonetDB itself
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
319 // can't access multiple databases.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
320 con = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
321 final String database = copts.getOption("database").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
322 try {
417
fb4c8d59699a Force the driver class to the loaded so it registers itself with the DriverManager.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 413
diff changeset
323 // make sure the driver class is loaded (and thus register itself with the DriverManager)
fb4c8d59699a Force the driver class to the loaded so it registers itself with the DriverManager.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 413
diff changeset
324 Class.forName("org.monetdb.jdbc.MonetDriver");
fb4c8d59699a Force the driver class to the loaded so it registers itself with the DriverManager.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 413
diff changeset
325
388
e79718252ce6 Undo the removal of line: import java.sql.DriverManager;
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 387
diff changeset
326 con = DriverManager.getConnection(
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
327 "jdbc:monetdb://" + host + "/" + database + attr,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
328 user,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
329 pass
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
330 );
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
331 SQLWarning warn = con.getWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
332 while (warn != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
333 System.err.println("Connection warning: " + warn.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
334 warn = warn.getNextWarning();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
335 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
336 con.clearWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
337 } catch (SQLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
338 System.err.println("Database connect failed: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
339 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
340 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
341
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
342 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
343 dbmd = con.getMetaData();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
344 } catch (SQLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
345 // we ignore this because it's probably because we don't use
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
346 // SQL language
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
347 dbmd = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
348 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
349
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
350 oc = copts.getOption("csvdir");
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
351 if (oc.isPresent()) {
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
352 final String csvdir = oc.getArgument();
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
353 if (csvdir != null) {
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
354 // check if provided csvdir is an existing dir
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
355 // else a download of data into file will terminate the JDBC connection!!
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
356 if (java.nio.file.Files.isDirectory(java.nio.file.Paths.get(csvdir))) {
578
687034945b3f Pass expected encoding as a constructor parameter to FileTransferHandler
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents: 577
diff changeset
357 final FileTransferHandler FThandler = new FileTransferHandler(csvdir, Charset.defaultCharset());
577
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
358
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
359 // register file data uploadHandler to allow support
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
360 // for: COPY INTO mytable FROM 'data.csv' ON CLIENT;
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
361 ((MonetConnection) con).setUploadHandler(FThandler);
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
362
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
363 // register file data downloadHandler to allow support
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
364 // for: COPY select_query INTO 'data.csv' ON CLIENT;
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
365 ((MonetConnection) con).setDownloadHandler(FThandler);
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
366 } else {
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
367 System.err.println("Warning: provided csvdir \"" + csvdir + "\" does not exist. Ignoring csvdir setting.");
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
368 }
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
369 }
6ab9168ef8e1 Added startup argument --csvdir to JdbcClient program to allow explicit enabling and specification where csv data files are to be read from or written to when the COPY ... ON CLIENT command is executed.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 564
diff changeset
370 }
564
c45bfdc2e2c4 Extend JdbcClient with registering default File Transfer upload and download handlers to support ON CLIENT functionality.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 467
diff changeset
371
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
372 stmt = con.createStatement(); // is used by processInteractive(), processBatch(), doDump()
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
373
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
374 in = new BufferedReader(new InputStreamReader(System.in));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
375 out = new PrintWriter(new BufferedWriter(new java.io.OutputStreamWriter(System.out)));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
376
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
377 // see if we will have to perform a database dump (only in SQL mode)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
378 if ("sql".equals(lang) && copts.getOption("dump").isPresent() && dbmd != null) {
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
379 final int argcount = copts.getOption("dump").getArgumentCount();
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
380
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
381 // use the given file for writing
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
382 oc = copts.getOption("file");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
383 if (oc.isPresent())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
384 out = new PrintWriter(new BufferedWriter(new java.io.FileWriter(oc.getArgument())));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
385
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
386 // we only want user tables and views to be dumped (DDL and optional data), unless a specific table is requested
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
387 final String[] types = {"TABLE","VIEW","MERGE TABLE","REMOTE TABLE","REPLICA TABLE","STREAM TABLE"};
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
388 // Future: fetch all type names using dbmd.getTableTypes() and construct String[] with all
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
389 // table type names excluding the SYSTEM ... ones and LOCAL TEMPORARY TABLE ones.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
390
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
391 // request the list of tables/views available in the current schema in the database
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
392 ResultSet tbl = dbmd.getTables(null, con.getSchema(), null, (argcount == 0) ? types : null);
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
393 // fetch all tables and store them in a LinkedList of Table objects
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
394 final LinkedList<Table> tables = new LinkedList<Table>();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
395 while (tbl.next()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
396 tables.add(new Table(
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
397 tbl.getString(2), // 2 = "TABLE_SCHEM"
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
398 tbl.getString(3), // 3 = "TABLE_NAME"
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
399 tbl.getString(4))); // 4 = "TABLE_TYPE"
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
400 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
401 tbl.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
402 tbl = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
403
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
404 if (xmlMode) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
405 exporter = new XMLExporter(out);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
406 exporter.setProperty(XMLExporter.TYPE_NIL, XMLExporter.VALUE_XSI);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
407 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
408 exporter = new SQLExporter(out);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
409 // stick with SQL INSERT INTO commands for now
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
410 // in the future we might do COPY INTO's here using VALUE_COPY
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
411 exporter.setProperty(SQLExporter.TYPE_OUTPUT, SQLExporter.VALUE_INSERT);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
412 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
413 exporter.useSchemas(true);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
414
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
415 // start SQL output
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
416 if (!xmlMode)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
417 out.println("START TRANSACTION;\n");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
418
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
419 // dump specific table(s) or not?
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
420 if (argcount > 0) { // yes we do
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
421 final String[] dumpers = copts.getOption("dump").getArguments();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
422 for (int i = 0; i < tables.size(); i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
423 Table ttmp = tables.get(i);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
424 for (int j = 0; j < dumpers.length; j++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
425 String dumptblnm = dumpers[j].toString();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
426 if (ttmp.getName().equalsIgnoreCase(dumptblnm) ||
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
427 ttmp.getFqname().equalsIgnoreCase(dumptblnm))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
428 {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
429 // dump the table
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
430 doDump(out, ttmp);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
431 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
432 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
433 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
434 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
435 /* this returns everything, so including SYSTEM TABLE constraints */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
436 tbl = dbmd.getImportedKeys(null, null, null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
437 while (tbl.next()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
438 // find FK table object 6 = "FKTABLE_SCHEM", 7 = "FKTABLE_NAME"
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
439 Table fk = Table.findTable(tbl.getString(6), tbl.getString(7), tables);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
440
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
441 // find PK table object 2 = "PKTABLE_SCHEM", 3 = "PKTABLE_NAME"
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
442 Table pk = Table.findTable(tbl.getString(2), tbl.getString(3), tables);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
443
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
444 // this happens when a system table has referential constraints
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
445 if (fk == null || pk == null)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
446 continue;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
447
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
448 // add PK table dependency to FK table
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
449 fk.addDependency(pk);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
450 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
451 tbl.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
452 tbl = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
453
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
454 // search for cycles of type a -> (x ->)+ b probably not
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
455 // the most optimal way, but it works by just scanning
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
456 // every table for loops in a recursive manor
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
457 for (Table t : tables) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
458 Table.checkForLoop(t, new ArrayList<Table>());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
459 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
460
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
461 // find the graph, at this point we know there are no
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
462 // cycles, thus a solution exists
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
463 for (int i = 0; i < tables.size(); i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
464 final List<Table> needs = tables.get(i).requires(tables.subList(0, i + 1));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
465 if (needs.size() > 0) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
466 tables.removeAll(needs);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
467 tables.addAll(i, needs);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
468
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
469 // re-evaluate this position, for there is a new
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
470 // table now
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
471 i--;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
472 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
473 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
474
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
475 // we now have the right order to dump tables
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
476 for (Table t : tables) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
477 // dump the table
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
478 doDump(out, t);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
479 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
480 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
481
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
482 if (!xmlMode)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
483 out.println("COMMIT;");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
484 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
485
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
486 // free resources, close the statement
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
487 stmt.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
488 // close the connection with the database
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
489 con.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
490 // completed database dump
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
491 System.exit(0);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
492 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
493
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
494 if (xmlMode) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
495 exporter = new XMLExporter(out);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
496 exporter.setProperty(XMLExporter.TYPE_NIL, XMLExporter.VALUE_XSI);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
497 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
498 exporter = new SQLExporter(out);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
499 // we want nice table formatted output
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
500 exporter.setProperty(SQLExporter.TYPE_OUTPUT, SQLExporter.VALUE_TABLE);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
501 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
502 exporter.useSchemas(false);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
503
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
504 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
505 // use the given file for reading
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
506 final boolean hasFile = copts.getOption("file").isPresent();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
507 final boolean doEcho = hasFile && copts.getOption("echo").isPresent();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
508 if (hasFile) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
509 final String tmp = copts.getOption("file").getArgument();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
510 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
511 in = getReader(tmp);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
512 } catch (Exception e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
513 System.err.println("Error: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
514 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
515 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
516
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
517 // check for batch mode
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
518 int batchSize = 0;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
519 oc = copts.getOption("Xbatching");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
520 if (oc.isPresent()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
521 if (oc.getArgumentCount() == 1) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
522 // parse the number
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
523 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
524 batchSize = Integer.parseInt(oc.getArgument());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
525 } catch (NumberFormatException ex) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
526 // complain to the user
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
527 throw new IllegalArgumentException("Illegal argument for Xbatching: " + oc.getArgument() + " is not a parseable number!");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
528 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
529 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
530 processBatch(batchSize);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
531 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
532 processInteractive(true, doEcho, scolonterm, user);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
533 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
534 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
535 if (!copts.getOption("quiet").isPresent()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
536 // print welcome message
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
537 out.println("Welcome to the MonetDB interactive JDBC terminal!");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
538 if (dbmd != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
539 out.println("JDBC Driver: " + dbmd.getDriverName() +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
540 " v" + dbmd.getDriverVersion());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
541 out.println("Database Server: " + dbmd.getDatabaseProductName() +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
542 " v" + dbmd.getDatabaseProductVersion());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
543 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
544 out.println("Current Schema: " + con.getSchema());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
545 out.println("Type \\q to quit (you can also use: quit or exit), \\? or \\h for a list of available commands");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
546 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
547 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
548 processInteractive(false, doEcho, scolonterm, user);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
549 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
550
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
551 // free resources, close the statement
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
552 stmt.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
553 // close the connection with the database
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
554 con.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
555 // close the file (if we used a file)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
556 in.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
557 } catch (Exception e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
558 System.err.println("A fatal exception occurred: " + e.toString());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
559 e.printStackTrace(System.err);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
560 // at least try to close the connection properly, since it will
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
561 // close all statements associated with it
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
562 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
563 con.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
564 } catch (SQLException ex) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
565 // ok... nice try
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
566 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
567 System.exit(1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
568 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
569 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
570
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
571 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
572 * Tries to interpret the given String as URL or file. Returns the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
573 * assigned BufferedReader, or throws an Exception if the given
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
574 * string couldn't be identified as a valid URL or file.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
575 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
576 * @param uri URL or filename as String
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
577 * @return a BufferedReader for the uri
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
578 * @throws Exception if uri cannot be identified as a valid URL or file
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
579 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
580 static BufferedReader getReader(final String uri) throws Exception {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
581 BufferedReader ret = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
582 URL u = null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
583
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
584 // Try and parse as URL first
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
585 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
586 u = new URL(uri);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
587 } catch (java.net.MalformedURLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
588 // no URL, try as file
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
589 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
590 ret = new BufferedReader(new java.io.FileReader(uri));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
591 } catch (java.io.FileNotFoundException fnfe) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
592 // the message is descriptive enough, adds "(No such file
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
593 // or directory)" itself.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
594 throw new Exception(fnfe.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
595 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
596 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
597
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
598 if (ret == null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
599 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
600 HttpURLConnection.setFollowRedirects(true);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
601 final HttpURLConnection con = (HttpURLConnection)u.openConnection();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
602 con.setRequestMethod("GET");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
603 final String ct = con.getContentType();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
604 if ("application/x-gzip".equals(ct)) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
605 // open gzip stream
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
606 ret = new BufferedReader(new InputStreamReader(
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
607 new java.util.zip.GZIPInputStream(con.getInputStream())));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
608 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
609 // text/plain otherwise just attempt to read as is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
610 ret = new BufferedReader(new InputStreamReader(con.getInputStream()));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
611 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
612 } catch (IOException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
613 // failed to open the url
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
614 throw new Exception("No such host/file: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
615 } catch (Exception e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
616 // this is an exception that comes from deep ...
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
617 throw new Exception("Invalid URL: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
618 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
619 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
620
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
621 return ret;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
622 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
623
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
624 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
625 * Starts an interactive processing loop, where output is adjusted to an
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
626 * user session. This processing loop is not suitable for bulk processing
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
627 * as in executing the contents of a file, since processing on the given
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
628 * input is done after each row that has been entered.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
629 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
630 * @param hasFile a boolean indicating whether a file is used as input
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
631 * @param doEcho a boolean indicating whether to echo the given input
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
632 * @param scolonterm whether a ';' makes this query part complete
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
633 * @param user a String representing the username of the current user
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
634 * @throws IOException if an IO exception occurs
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
635 * @throws SQLException if a database related error occurs
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
636 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
637 private static void processInteractive(
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
638 final boolean hasFile,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
639 final boolean doEcho,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
640 final boolean scolonterm,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
641 final String user)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
642 throws IOException, SQLException
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
643 {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
644 // an SQL stack keeps track of ( " and '
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
645 final SQLStack stack = new SQLStack();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
646 boolean lastac = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
647
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
648 if (!hasFile) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
649 lastac = con.getAutoCommit();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
650 out.println("auto commit mode: " + (lastac ? "on" : "off"));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
651 out.print(getPrompt(stack, true));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
652 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
653 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
654
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
655 String curLine;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
656 String query = "";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
657 boolean doProcess;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
658 boolean wasComplete = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
659
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
660 // the main (interactive) process loop
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
661 for (long i = 1; true; i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
662 // Manually read a line, because we want to detect an EOF
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
663 // (ctrl-D). Doing so allows to have a terminator for query
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
664 // which is not based on a special character, as is the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
665 // problem for XQuery
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
666 curLine = in.readLine();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
667 if (curLine == null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
668 out.println("");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
669 if (!query.isEmpty()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
670 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
671 executeQuery(query, stmt, out, !hasFile);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
672 } catch (SQLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
673 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
674 do {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
675 if (hasFile) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
676 System.err.println("Error on line " + i + ": [" + e.getSQLState() + "] " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
677 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
678 System.err.println("Error [" + e.getSQLState() + "]: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
679 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
680 // print all error messages in the chain (if any)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
681 } while ((e = e.getNextException()) != null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
682 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
683 query = "";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
684 wasComplete = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
685 if (!hasFile) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
686 final boolean ac = con.getAutoCommit();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
687 if (ac != lastac) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
688 out.println("auto commit mode: " + (ac ? "on" : "off"));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
689 lastac = ac;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
690 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
691 out.print(getPrompt(stack, wasComplete));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
692 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
693 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
694 // try to read again
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
695 continue;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
696 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
697 // user did ctrl-D without something in the buffer,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
698 // so terminate
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
699 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
700 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
701 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
702
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
703 if (doEcho) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
704 out.println(curLine);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
705 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
706 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
707
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
708 // a query part is a line of an SQL query
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
709 QueryPart qp = scanQuery(curLine, stack, scolonterm);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
710 if (!qp.isEmpty()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
711 final String command = qp.getQuery();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
712 doProcess = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
713 if (wasComplete) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
714 doProcess = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
715 // check for commands only when the previous row was complete
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
716 if (command.equals("\\q") || command.equals("quit") || command.equals("exit")) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
717 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
718 } else if (dbmd != null && command.startsWith("\\d")) {
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
719 processDescribeCmd(command, scolonterm);
457
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
720 } else if (command.startsWith("\\v")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
721 if (command.equals("\\vsci")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
722 MDBvalidator.validateSqlCatalogIntegrity(con, true);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
723 } else if (command.equals("\\vsci_noheader")) { // used only for internal automated testing
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
724 MDBvalidator.validateSqlCatalogIntegrity(con, false);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
725 } else if (command.equals("\\vsni")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
726 MDBvalidator.validateSqlNetcdfTablesIntegrity(con, true);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
727 } else if (command.equals("\\vsni_noheader")) { // used only for internal automated testing
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
728 MDBvalidator.validateSqlNetcdfTablesIntegrity(con, false);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
729 } else if (command.equals("\\vsgi")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
730 MDBvalidator.validateSqlGeomTablesIntegrity(con, true);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
731 } else if (command.equals("\\vsgi_noheader")) { // used only for internal automated testing
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
732 MDBvalidator.validateSqlGeomTablesIntegrity(con, false);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
733 } else if (command.startsWith("\\vsi ")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
734 String schema_nm = command.substring(5);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
735 MDBvalidator.validateSchemaIntegrity(con, schema_nm, true);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
736 } else if (command.startsWith("\\vsi_noheader ")) { // used only for internal automated testing
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
737 String schema_nm = command.substring(14);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
738 MDBvalidator.validateSchemaIntegrity(con, schema_nm, false);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
739 } else if (command.equals("\\vdbi")) {
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
740 MDBvalidator.validateDBIntegrity(con, true);
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
741 } else if (command.equals("\\vdbi_noheader")) { // used only for internal automated testing
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
742 MDBvalidator.validateDBIntegrity(con, false);
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
743 } else {
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
744 showCommands();
457
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
745 }
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
746 } else if (command.startsWith("\\l") || command.startsWith("\\i")) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
747 String object = command.substring(2).trim();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
748 if (scolonterm && object.endsWith(";"))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
749 object = object.substring(0, object.length() - 1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
750 if (object.isEmpty()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
751 System.err.println("Usage: '" + command.substring(0, 2) + "<uri>' where <uri> is a file or URL");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
752 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
753 // temporarily redirect input from in
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
754 final BufferedReader console = in;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
755 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
756 in = getReader(object);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
757 if (command.startsWith("\\l")) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
758 processInteractive(true, doEcho, scolonterm, user);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
759 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
760 processBatch(0);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
761 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
762 } catch (Exception e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
763 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
764 System.err.println("Error: " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
765 } finally {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
766 // put back in redirection
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
767 in = console;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
768 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
769 }
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
770 } else if (command.equals("\\?") || command.equals("\\h") || command.startsWith("\\")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
771 showCommands();
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
772 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
773 doProcess = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
774 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
775 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
776
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
777 if (doProcess) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
778 query += command + (qp.hasOpenQuote() ? "\\n" : " ");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
779 if (qp.isComplete()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
780 // strip off trailing ';'
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
781 query = query.substring(0, query.length() - 2);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
782 // execute query
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
783 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
784 executeQuery(query, stmt, out, !hasFile);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
785 } catch (SQLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
786 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
787 final String startmsg = (hasFile ? ("Error on line " + i + ": [") : "Error [");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
788 do {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
789 System.err.println(startmsg + e.getSQLState() + "] " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
790 // print all error messages in the chain (if any)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
791 } while ((e = e.getNextException()) != null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
792 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
793 query = "";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
794 wasComplete = true;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
795 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
796 wasComplete = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
797 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
798 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
799 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
800
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
801 if (!hasFile) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
802 final boolean ac = con.getAutoCommit();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
803 if (ac != lastac) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
804 out.println("auto commit mode: " + (ac ? "on" : "off"));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
805 lastac = ac;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
806 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
807 out.print(getPrompt(stack, wasComplete));
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
808 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
809 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
810 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
811 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
812
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
813 private static void showCommands()
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
814 {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
815 out.println("Available commands:");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
816 out.println("\\q quits this program (you can also use: quit or exit)");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
817 if (dbmd != null) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
818 out.println("\\d list available user tables and views in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
819 out.println("\\dt list available user tables in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
820 out.println("\\dv list available user views in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
821 out.println("\\df list available user functions in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
822 out.println("\\dp list available user procedures in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
823 out.println("\\ds list available user sequences in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
824 out.println("\\dn list available user schemas");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
825 out.println("\\dS list available system tables and views in sys/tmp schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
826 out.println("\\dSt list available system tables in sys/tmp schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
827 out.println("\\dSv list available system views in sys/logging schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
828 out.println("\\dSf list available system functions in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
829 out.println("\\dSp list available system procedures in current schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
830 out.println("\\dSn list available system schemas");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
831 out.println("\\d <obj> describes the given table or view");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
832 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
833 out.println("\\l<uri> executes the contents of the given file or URL");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
834 out.println("\\i<uri> batch executes the inserts from the given file or URL");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
835 out.println("\\vsci validate sql system catalog integrity");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
836 // out.println("\\vsni validate sql system netcdf tables integrity"); // do not print as it depends on availability of netcdf library on server
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
837 // out.println("\\vsgi validate sql system geom tables integrity"); // do not print as it depends on availability of geom library on server
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
838 out.println("\\vsi <schema> validate integrity of data in the given schema");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
839 out.println("\\vdbi validate integrity of data in all user schemas in the database");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
840 out.println("\\? or \\h this help screen");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
841 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
842
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
843 /**
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
844 * Process the commands that start with \d
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
845 * These commands list the available user or system tables, views, functions, procedures, schemas
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
846 * or user sequences
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
847 * or describe a specific table or view by printing the CREATE DDL statement
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
848 * See also showCommands()
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
849 * These commands are almost the same as in mclient program
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
850 */
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
851 private static void processDescribeCmd(final String dcommand, final boolean scolonterm)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
852 {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
853 final String command = dcommand.substring(1); // remove the leading \ character first
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
854 ResultSet rs = null;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
855 Statement st = null;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
856 try {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
857 if (command.equals("d") || command.equals("dt") || command.equals("dv")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
858 // list available user tables and/or views in current schema (maybe tmp schema to show temporary tables)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
859 boolean tablesOnly = command.equals("dt");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
860 boolean viewsOnly = command.equals("dv");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
861 rs = dbmd.getTables(null, con.getSchema(), null, null);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
862 while (rs.next()) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
863 final String tableType = rs.getString(4); // 4 = "TABLE_TYPE"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
864 boolean include = (tableType != null && !tableType.startsWith("SYSTEM "));
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
865 if (include && tablesOnly && !tableType.contains("TABLE"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
866 include = false;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
867 if (include && viewsOnly && !tableType.contains("VIEW"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
868 include = false;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
869 if (include) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
870 out.println(tableType + "\t" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
871 optAddDqs(rs.getString(2)) + "." + // 2 = "TABLE_SCHEM"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
872 optAddDqs(rs.getString(3)) ); // 3 = "TABLE_NAME"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
873 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
874 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
875 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
876 if (command.equals("dS") || command.equals("dSt") || command.equals("dSv") || command.equals("dtS") || command.equals("dvS")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
877 // list available system tables and/or views in sys/tmp/logging schema
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
878 boolean tablesOnly = command.contains("t");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
879 boolean viewsOnly = command.contains("v");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
880 String curSchema = con.getSchema();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
881 // only schemas: sys, tmp and logging contain system tables and views.
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
882 if (!("sys".equals(curSchema) || "tmp".equals(curSchema) || "logging".equals(curSchema)))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
883 // when currently in another schema, default to the sys tables/views else nothing will be listed
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
884 curSchema = "sys";
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
885 rs = dbmd.getTables(null, curSchema, null, null);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
886 while (rs.next()) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
887 final String tableType = rs.getString(4); // 4 = "TABLE_TYPE"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
888 boolean include = (tableType != null && tableType.startsWith("SYSTEM "));
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
889 if (include && tablesOnly && !tableType.contains("TABLE"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
890 include = false;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
891 if (include && viewsOnly && !tableType.contains("VIEW"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
892 include = false;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
893 if (include) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
894 out.println(tableType + "\t" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
895 optAddDqs(rs.getString(2)) + "." + // 2 = "TABLE_SCHEM"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
896 optAddDqs(rs.getString(3)) ); // 3 = "TABLE_NAME"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
897 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
898 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
899 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
900 if (command.equals("df") || command.equals("dp") || command.equals("dSf") || command.equals("dSp") || command.equals("dfS") || command.equals("dpS")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
901 // list available user/system functions or procedures in current schema (maybe tmp schema)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
902 boolean proceduresOnly = command.contains("p");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
903 boolean systemOnly = command.contains("S");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
904 // Note we cannot use: dbmd.getFunctions(null, con.getSchema(), null); or dbmd.getProcedures(null, con.getSchema(), null);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
905 // as they do not return the full function type name, nor provide information whether it is a system function or system procedure.
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
906 // Instead we query the MonetDB system catog tables directly using:
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
907 String qy = "SELECT DISTINCT " + (systemOnly ? "'SYSTEM ' || " : "") + "\"function_type_keyword\" as func_type, " +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
908 "\"schemas\".\"name\" as schem_name, \"functions\".\"name\" as func_name" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
909 " FROM sys.\"functions\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
910 " JOIN sys.\"function_types\" ON \"functions\".\"type\" = \"function_types\".\"function_type_id\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
911 " JOIN sys.\"schemas\" ON \"functions\".\"schema_id\" = \"schemas\".\"id\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
912 " WHERE \"functions\".\"system\" = " + (systemOnly ? "true" : "false") +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
913 " AND \"functions\".\"type\" " + (proceduresOnly ? "= 2" : "<> 2") +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
914 " AND \"schemas\".\"name\" = current_schema" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
915 " ORDER BY 2, 3";
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
916 st = con.createStatement();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
917 rs = st.executeQuery(qy);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
918 while (rs.next()) {
628
c0f6884b0de4 Add a few extra spaces to get a better indentation and presentation of the list of (system) functions, aggregates and window functions.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 627
diff changeset
919 out.println(rs.getString(1) + " \t" + // 1 = func_type
611
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
920 optAddDqs(rs.getString(2)) + "." + // 2 = schem_name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
921 optAddDqs(rs.getString(3)) ); // 3 = func_name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
922 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
923 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
924 if (command.equals("ds")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
925 // list available (user) sequences in current schema
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
926 String qy = "SELECT \"schemas\".\"name\", \"sequences\".\"name\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
927 " FROM sys.\"sequences\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
928 " JOIN sys.\"schemas\" ON \"sequences\".\"schema_id\" = \"schemas\".\"id\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
929 " WHERE \"schemas\".\"name\" = current_schema" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
930 " ORDER BY 1, 2";
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
931 st = con.createStatement();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
932 rs = st.executeQuery(qy);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
933 while (rs.next()) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
934 out.println("SEQUENCE " +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
935 optAddDqs(rs.getString(1)) + "." + // 1 = schemas.name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
936 optAddDqs(rs.getString(2)) ); // 2 = sequences.name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
937 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
938 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
939 if (command.equals("dn") || command.equals("dSn") || command.equals("dnS")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
940 // list available user/system schemas in the database
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
941 boolean systemOnly = command.contains("S");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
942 String qy = "SELECT \"name\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
943 " FROM sys.\"schemas\"" +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
944 " WHERE \"system\" = " + (systemOnly ? "true" : "false") +
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
945 " ORDER BY 1";
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
946 String schema_type = (systemOnly ? "SYSTEM SCHEMA\t" : "SCHEMA\t");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
947 st = con.createStatement();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
948 rs = st.executeQuery(qy);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
949 while (rs.next()) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
950 out.println(schema_type + optAddDqs(rs.getString(1)) ); // 1 = schemas.name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
951 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
952 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
953 if (command.startsWith("d ")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
954 // describes the given table or view name. It may be a fully qualified name such as: sys."keys"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
955 String object = command.substring(2).trim();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
956 if (scolonterm && object.endsWith(";"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
957 object = object.substring(0, object.length() - 1);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
958 if (object.isEmpty()) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
959 System.err.println("Missing name of object to describe");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
960 } else {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
961 // extract the name of the schema first. If none found use current schema
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
962 String schema;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
963 String obj_nm = object;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
964 int len;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
965 boolean found = false;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
966 final int dot = object.indexOf(".");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
967 if (dot > 0) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
968 // use specified schema
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
969 schema = object.substring(0, dot);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
970 obj_nm = object.substring(dot + 1);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
971 // remove potential surrounding double quotes around schema name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
972 len = schema.length();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
973 if (len > 2 && schema.charAt(0) == '"' && schema.charAt(len -1) == '"')
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
974 schema = schema.substring(1, len -1);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
975 } else {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
976 // use current schema
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
977 schema = con.getSchema();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
978 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
979 // remove potential surrounding double quotes around table or view name
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
980 len = obj_nm.length();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
981 if (len > 2 && obj_nm.charAt(0) == '"' && obj_nm.charAt(len -1) == '"')
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
982 obj_nm = obj_nm.substring(1, len -1);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
983
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
984 // System.err.println("calling dbmd.getTables(" + schema + ", " + obj_nm + ")");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
985 rs = dbmd.getTables(null, schema, obj_nm, null);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
986 while (rs.next() && !found) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
987 final String schemaName = rs.getString(2); // 2 = "TABLE_SCHEM"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
988 final String tableName = rs.getString(3); // 3 = "TABLE_NAME"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
989 if (obj_nm.equals(tableName) && schema.equals(schemaName)) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
990 String tableType = rs.getString(4); // 4 = "TABLE_TYPE"
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
991 if (tableType.startsWith("SYSTEM "))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
992 tableType = tableType.substring(7);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
993 // we found it, describe it
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
994 exporter.dumpSchema(dbmd, tableType, schemaName, tableName);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
995 found = true;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
996 break;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
997 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
998 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
999 if (!found)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1000 System.err.println("table or view: " + schema + "." + obj_nm + " does not exist");
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1001 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1002 } else
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1003 if (command.startsWith("d")) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1004 System.err.println("unknown sub-command for \\d: " + command.substring(1));
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1005 } else {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1006 showCommands();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1007 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1008 } catch (SQLException e) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1009 out.flush();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1010 do {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1011 System.err.println("Error [" + e.getSQLState() + "]: " + e.getMessage());
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1012 // print all error messages in the chain (if any)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1013 } while ((e = e.getNextException()) != null);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1014 } finally {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1015 if (rs != null) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1016 try {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1017 rs.close();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1018 } catch (SQLException e) { /* ignore */ }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1019 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1020 if (st != null) {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1021 try {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1022 st.close();
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1023 } catch (SQLException e) { /* ignore */ }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1024 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1025 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1026 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1027
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1028 private static String optAddDqs(final String name)
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1029 {
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1030 if (name.contains(" ") || name.contains("\t") || name.contains("\n"))
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1031 return Exporter.dq(name);
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1032 return name;
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1033 }
d2a141446e22 Extended JdbcClient application with support for more \d commands:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 610
diff changeset
1034
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1035 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1036 * Executes the given query and prints the result tabularised to the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1037 * given PrintWriter stream. The result of this method is the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1038 * default output of a query: tabular data.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1039 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1040 * @param query the query to execute
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1041 * @param stmt the Statement to execute the query on
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1042 * @param out the PrintWriter to write to
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1043 * @param showTiming flag to specify if timing information nees to be printed
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1044 * @throws SQLException if a database related error occurs
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1045 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1046 private static void executeQuery(final String query,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1047 final Statement stmt,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1048 final PrintWriter out,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1049 final boolean showTiming)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1050 throws SQLException
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1051 {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1052 // warnings generated during querying
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1053 SQLWarning warn;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1054 long startTime = (showTiming ? System.currentTimeMillis() : 0);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1055 long finishTime = 0;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1056
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1057 // execute the query, let the driver decide what type it is
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1058 int aff = -1;
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1059 boolean nextRslt = stmt.execute(query, Statement.RETURN_GENERATED_KEYS);
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1060 if (!nextRslt)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1061 aff = stmt.getUpdateCount();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1062 do {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1063 if (nextRslt) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1064 // we have a ResultSet, print it
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1065 final ResultSet rs = stmt.getResultSet();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1066
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1067 exporter.dumpResultSet(rs);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1068 if (showTiming) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1069 finishTime = System.currentTimeMillis();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1070 out.println("Elapsed Time: " + (finishTime - startTime) + " ms");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1071 startTime = finishTime;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1072 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1073
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1074 // if there were warnings for this result,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1075 // show them!
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1076 warn = rs.getWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1077 if (warn != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1078 // force stdout to be written so the
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1079 // warning appears below it
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1080 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1081 do {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1082 System.err.println("ResultSet warning: " +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1083 warn.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1084 warn = warn.getNextWarning();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1085 } while (warn != null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1086 rs.clearWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1087 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1088 rs.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1089 } else if (aff != -1) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1090 String timingoutput = "";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1091 if (showTiming) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1092 finishTime = System.currentTimeMillis();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1093 timingoutput = ". Elapsed Time: " + (finishTime - startTime) + " ms";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1094 startTime = finishTime;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1095 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1096
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1097 if (aff == Statement.SUCCESS_NO_INFO) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1098 out.println("Operation successful" + timingoutput);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1099 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1100 // we have an update count
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1101 // see if a key was generated
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1102 final ResultSet rs = stmt.getGeneratedKeys();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1103 final boolean hasGeneratedKeyData = rs.next();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1104 out.println(aff + " affected row" + (aff != 1 ? "s" : "") +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1105 (hasGeneratedKeyData ? ", last generated key: " + rs.getString(1) : "") +
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1106 timingoutput);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1107 rs.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1108 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1109 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1110
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1111 out.flush();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1112 } while ((nextRslt = stmt.getMoreResults()) ||
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1113 (aff = stmt.getUpdateCount()) != -1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1114
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1115 // if there were warnings for this statement show them!
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1116 warn = stmt.getWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1117 while (warn != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1118 System.err.println("Statement warning: " + warn.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1119 warn = warn.getNextWarning();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1120 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1121 stmt.clearWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1122
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1123 // if there were warnings for this connection show them!
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1124 warn = con.getWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1125 while (warn != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1126 // suppress warning when issueing a "set schema xyz;" command
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1127 // if ( !(warn.getMessage()).equals("Server enabled auto commit mode while local state already was auto commit.") )
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1128 System.err.println("Connection warning: " + warn.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1129 warn = warn.getNextWarning();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1130 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1131 con.clearWarnings();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1132 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1133
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1134 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1135 * Starts a processing loop optimized for processing (large) chunks of
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1136 * continuous data, such as input from a file. Unlike in the interactive
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1137 * loop above, queries are sent only to the database if a certain batch
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1138 * amount is reached. No client side query checks are made, but everything
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1139 * is sent to the server as-is.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1140 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1141 * @param batchSize the number of items to store in the batch before
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1142 * sending them to the database for execution.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1143 * @throws IOException if an IO exception occurs.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1144 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1145 private static void processBatch(final int batchSize) throws IOException {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1146 final StringBuilder query = new StringBuilder(2048);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1147 int i = 0;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1148 try {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1149 String curLine;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1150 // the main loop
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1151 for (i = 1; (curLine = in.readLine()) != null; i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1152 query.append(curLine);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1153 if (curLine.endsWith(";")) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1154 // lousy check for end of statement, but in batch mode it
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1155 // is not very important to catch all end of statements...
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1156 stmt.addBatch(query.toString());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1157 query.setLength(0); // clear the buffer
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1158 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1159 query.append('\n');
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1160 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1161 if (batchSize > 0 && i % batchSize == 0) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1162 stmt.executeBatch();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1163 // stmt.clearBatch(); // this is no longer needed after call executeBatch(), see https://www.monetdb.org/bugzilla/show_bug.cgi?id=6953
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1164 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1165 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1166 stmt.addBatch(query.toString());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1167 stmt.executeBatch();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1168 // stmt.clearBatch(); // this is no longer needed after call executeBatch(), see https://www.monetdb.org/bugzilla/show_bug.cgi?id=6953
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1169 } catch (SQLException e) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1170 do {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1171 System.err.println("Error at line " + i + ": [" + e.getSQLState() + "] " + e.getMessage());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1172 // print all error messages in the chain (if any)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1173 } while ((e = e.getNextException()) != null);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1174 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1175 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1176
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1177 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1178 * Wrapper method that decides to dump SQL or XML. In the latter case,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1179 * this method does the XML data generation.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1180 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1181 * @param out a Writer to write the data to
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1182 * @param table the table to dump
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1183 * @throws SQLException if a database related error occurs
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1184 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1185 private static void doDump(final PrintWriter out, final Table table) throws SQLException {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1186 final String tableType = table.getType();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1187
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1188 // dump CREATE definition of this table/view
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1189 exporter.dumpSchema(dbmd, tableType, table.getSchem(), table.getName());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1190 out.println();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1191
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1192 // only dump data from real tables, not from VIEWs / MERGE / REMOTE / REPLICA / STREAM tables
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1193 if (tableType.contains("TABLE")
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1194 && !tableType.equals("MERGE TABLE")
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1195 && !tableType.equals("REMOTE TABLE")
467
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1196 && !tableType.equals("REPLICA TABLE")
171144a26ba0 Do not dump table data of STREAM TABLEs. And other small improvements and optimisations.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 466
diff changeset
1197 && !tableType.equals("STREAM TABLE")) {
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1198 final ResultSet rs = stmt.executeQuery("SELECT * FROM " + table.getFqnameQ());
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1199 if (rs != null) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1200 exporter.dumpResultSet(rs);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1201 rs.close();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1202 out.println();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1203 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1204 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1205 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1206
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1207 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1208 * Simple helper method that generates a prompt.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1209 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1210 * @param stack the current SQLStack
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1211 * @param compl whether the statement is complete
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1212 * @return a prompt which consist of "sql" plus the top of the stack
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1213 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1214 private static String getPrompt(final SQLStack stack, final boolean compl) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1215 return (compl ? "sql" : "more") + (stack.empty() ? ">" : stack.peek()) + " ";
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1216 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1217
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1218 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1219 * Scans the given string and tries to discover if it is a complete query
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1220 * or that there needs something to be added. If a string doesn't end with
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1221 * a ; it is considered not to be complete. SQL string quotation using ' and
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1222 * SQL identifier quotation using " is taken into account when scanning a
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1223 * string this way.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1224 * Additionally, this method removes comments from the SQL statements,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1225 * identified by -- and removes white space where appropriate.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1226 *
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1227 * @param query the query to parse
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1228 * @param stack query stack to work with
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1229 * @param scolonterm whether a ';' makes this query part complete
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1230 * @return a QueryPart object containing the results of this parse
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1231 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1232 private static QueryPart scanQuery(
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1233 final String query,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1234 final SQLStack stack,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1235 final boolean scolonterm)
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1236 {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1237 // examine string, char for char
457
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
1238 final boolean wasInString = (stack.peek() == '\'');
ebda95332d57 Add support for double quoted schema names for the \vsi command
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 456
diff changeset
1239 final boolean wasInIdentifier = (stack.peek() == '"');
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1240 boolean escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1241 int len = query.length();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1242 for (int i = 0; i < len; i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1243 switch(query.charAt(i)) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1244 case '\\':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1245 escaped = !escaped;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1246 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1247 default:
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1248 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1249 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1250 case '\'':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1251 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1252 * We can not be in a string if we are in an identifier. So
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1253 * If we find a ' and are not in an identifier, and not in
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1254 * a string we can safely assume we will be now in a string.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1255 * If we are in a string already, we should stop being in a
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1256 * string if we find a quote which is not prefixed by a \,
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1257 * for that would be an escaped quote. However, a nasty
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1258 * situation can occur where the string is like 'test \\'.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1259 * As obvious, a test for a \ in front of a ' doesn't hold
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1260 * here. Because 'test \\\'' can exist as well, we need to
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1261 * know if a quote is prefixed by an escaping slash or not.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1262 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1263 if (!escaped && stack.peek() != '"') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1264 if (stack.peek() != '\'') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1265 // although it makes no sense to escape a quote
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1266 // outside a string, it is escaped, thus not meant
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1267 // as quote for us, apparently
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1268 stack.push('\'');
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1269 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1270 stack.pop();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1271 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1272 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1273 // reset escaped flag
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1274 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1275 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1276 case '"':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1277 if (!escaped && stack.peek() != '\'') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1278 if (stack.peek() != '"') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1279 stack.push('"');
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1280 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1281 stack.pop();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1282 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1283 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1284 // reset escaped flag
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1285 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1286 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1287 case '-':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1288 if (!escaped && stack.peek() != '\'' && stack.peek() != '"' && i + 1 < len && query.charAt(i + 1) == '-') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1289 len = i;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1290 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1291 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1292 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1293 case '(':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1294 if (!escaped && stack.peek() != '\'' && stack.peek() != '"') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1295 stack.push('(');
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1296 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1297 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1298 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1299 case ')':
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1300 if (!escaped && stack.peek() == '(') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1301 stack.pop();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1302 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1303 escaped = false;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1304 break;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1305 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1306 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1307
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1308 int start = 0;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1309 if (!wasInString && !wasInIdentifier && len > 0) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1310 // trim spaces at the start of the string
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1311 for (; start < len && Character.isWhitespace(query.charAt(start)); start++);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1312 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1313 int stop = len - 1;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1314 if (stack.peek() != '\'' && !wasInIdentifier && stop > start) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1315 // trim spaces at the end of the string
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1316 for (; stop >= start && Character.isWhitespace(query.charAt(stop)); stop--);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1317 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1318 stop++;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1319
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1320 if (start == stop) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1321 // we have an empty string
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1322 return new QueryPart(false, null, stack.peek() == '\'' || stack.peek() == '"');
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1323 } else if (stack.peek() == '\'' || stack.peek() == '"') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1324 // we have an open quote
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1325 return new QueryPart(false, query.substring(start, stop), true);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1326 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1327 // see if the string is complete
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1328 if (scolonterm && query.charAt(stop - 1) == ';') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1329 return new QueryPart(true, query.substring(start, stop), false);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1330 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1331 return new QueryPart(false, query.substring(start, stop), false);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1332 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1333 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1334 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1335 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1336
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1337 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1338 * A QueryPart is (a part of) a SQL query. In the QueryPart object information
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1339 * like the actual SQL query string, whether it has an open quote and the like
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1340 * is stored.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1341 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1342 final class QueryPart {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1343 private final boolean complete;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1344 private final String query;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1345 private final boolean open;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1346
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1347 QueryPart(final boolean complete, final String query, final boolean open) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1348 this.complete = complete;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1349 this.query = query;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1350 this.open = open;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1351 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1352
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1353 boolean isEmpty() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1354 return query == null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1355 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1356
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1357 boolean isComplete() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1358 return complete;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1359 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1360
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1361 String getQuery() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1362 return query;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1363 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1364
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1365 boolean hasOpenQuote() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1366 return open;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1367 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1368 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1369
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1370 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1371 * An SQLStack is a simple stack that keeps track of open brackets and
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1372 * (single and double) quotes in an SQL query.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1373 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1374 final class SQLStack {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1375 final StringBuilder stack = new StringBuilder();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1376
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1377 char peek() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1378 if (empty()) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1379 return '\0';
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1380 } else {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1381 return stack.charAt(stack.length() - 1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1382 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1383 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1384
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1385 char pop() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1386 final char tmp = peek();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1387 if (tmp != '\0') {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1388 stack.setLength(stack.length() - 1);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1389 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1390 return tmp;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1391 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1392
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1393 char push(char item) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1394 stack.append(item);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1395 return item;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1396 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1397
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1398 boolean empty() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1399 return stack.length() == 0;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1400 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1401 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1402
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1403 /**
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1404 * A Table represents an SQL table. All data required to
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1405 * generate a fully qualified name is stored, as well as dependency
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1406 * data.
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1407 */
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1408 final class Table {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1409 final String schem;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1410 final String name;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1411 final String type;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1412 final String fqname;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1413 final ArrayList<Table> needs = new ArrayList<Table>();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1414
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1415 Table(final String schem, final String name, final String type) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1416 this.schem = schem;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1417 this.name = name;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1418 this.type = type;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1419 this.fqname = schem + "." + name;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1420 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1421
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1422 void addDependency(final Table dependsOn) throws Exception {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1423 if (this.fqname.equals(dependsOn.fqname))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1424 throw new Exception("Cyclic dependency graphs are not supported (foreign key relation references self)");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1425
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1426 if (dependsOn.needs.contains(this))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1427 throw new Exception("Cyclic dependency graphs are not supported (foreign key relation a->b and b->a)");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1428
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1429 if (!needs.contains(dependsOn))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1430 needs.add(dependsOn);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1431 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1432
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1433 List<Table> requires(final List<Table> existingTables) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1434 if (existingTables == null || existingTables.isEmpty())
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1435 return new ArrayList<Table>(needs);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1436
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1437 final ArrayList<Table> req = new ArrayList<Table>();
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1438 for (Table n : needs) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1439 if (!existingTables.contains(n))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1440 req.add(n);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1441 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1442
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1443 return req;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1444 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1445
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1446 final String getSchem() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1447 return schem;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1448 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1449
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1450 final String getName() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1451 return name;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1452 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1453
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1454 final String getType() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1455 return type;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1456 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1457
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1458 final String getFqname() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1459 return fqname;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1460 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1461
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1462 final String getFqnameQ() {
425
95d15f1d750d Restructured code (incl removal of duplicate code) for utility functions dq() and sq() which add double or double quotes and add escapes to string values.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 417
diff changeset
1463 return Exporter.dq(schem) + "." + Exporter.dq(name);
386
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1464 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1465
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1466 public final String toString() {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1467 return fqname;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1468 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1469
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1470 static final Table findTable(final String schname, final String tblname, final List<Table> list) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1471 for (Table t : list) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1472 if (t.schem.equals(schname) && t.name.equals(tblname))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1473 return t;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1474 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1475 // not found
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1476 return null;
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1477 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1478
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1479 static final void checkForLoop(final Table table, final List<Table> parents) throws Exception {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1480 parents.add(table);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1481 for (int i = 0; i < table.needs.size(); i++) {
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1482 Table child = table.needs.get(i);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1483 if (parents.contains(child))
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1484 throw new Exception("Cyclic dependency graphs are not supported (cycle detected for " + child.fqname + ")");
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1485 checkForLoop(child, parents);
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1486 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1487 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1488 }
15b87fd68052 Extended JdbcClient program with 3 new commands to quickly validate data integrity:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 367
diff changeset
1489