Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/util/SQLExporter.java @ 975:5e320086a01c default tip
Some docker images are not available as dev-builds
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 01 May 2025 17:13:53 +0200 (29 hours ago) |
parents | d416e9b6b3d0 |
children |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
3 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 * |
937
d416e9b6b3d0
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
901
diff
changeset
|
8 * Copyright 2024, 2025 MonetDB Foundation; |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 |
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:
374
diff
changeset
|
13 package org.monetdb.util; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 import java.sql.DatabaseMetaData; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 import java.sql.ResultSet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 import java.sql.ResultSetMetaData; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 import java.sql.SQLException; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 import java.sql.Types; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 import java.util.Iterator; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 import java.util.LinkedHashSet; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 import java.util.Map; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 import java.util.Set; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
24 import java.util.Stack; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
25 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
26 public final class SQLExporter extends Exporter { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
27 private int outputMode; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
28 private Stack<String> lastSchema; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
30 public final static short TYPE_OUTPUT = 1; |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
31 public final static short VALUE_INSERT = 0; |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
32 public final static short VALUE_COPY = 1; |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
33 public final static short VALUE_TABLE = 2; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
35 public SQLExporter(final java.io.PrintWriter out) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 super(out); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 * A helper method to generate SQL CREATE code for a given table. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 * This method performs all required lookups to find all relations and |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 * column information, as well as additional indices. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 * @param dbmd a DatabaseMetaData object to query on (not null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 * @param type the type of the object, e.g. VIEW, TABLE (not null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
46 * @param schema the schema the object is in (not null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 * @param name the table to describe in SQL CREATE format (not null) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 * @throws SQLException if a database related error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
49 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 public void dumpSchema( |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
51 final DatabaseMetaData dbmd, |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
52 final String type, |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
53 final String schema, |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
54 final String name) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 assert dbmd != null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 assert type != null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
59 assert schema != null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
60 assert name != null; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
61 |
313
f2750ea9f93d
When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
312
diff
changeset
|
62 final String fqname = dq(schema) + "." + dq(name); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 if (useSchema) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 changeSchema(schema); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 // handle views directly |
318
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
68 if (type.endsWith("VIEW")) { // for types: VIEW and SYSTEM VIEW |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
69 final String viewDDL = fetchSysTablesQueryValue(dbmd.getConnection(), schema, name); |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
70 if (viewDDL != null) |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
71 out.println(viewDDL); |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
72 else |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
73 out.println("-- unknown " + type + " " + fqname + ": no SQL view definition found!"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 return; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
77 out.println("CREATE " + type + " " + fqname + " ("); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
78 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
79 // add all columns with their type, nullability and default definition |
315
4793f9b80bb3
Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
314
diff
changeset
|
80 ResultSet cols = dbmd.getColumns(null, schema, name, null); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
81 int colNmIndex = cols.findColumn("COLUMN_NAME"); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
82 final int colTypeNmIndex = cols.findColumn("TYPE_NAME"); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
83 final int datatypeIndex = cols.findColumn("DATA_TYPE"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
84 final int sizeIndex = cols.findColumn("COLUMN_SIZE"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
85 final int digitsIndex = cols.findColumn("DECIMAL_DIGITS"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
86 final int isNotNullIndex = cols.findColumn("NULLABLE"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
87 final int defaultValueIndex = cols.findColumn("COLUMN_DEF"); |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
88 final ResultSetMetaData rsmd = cols.getMetaData(); |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
89 final int colwidth = rsmd.getColumnDisplaySize(colNmIndex); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
90 int typewidth = rsmd.getColumnDisplaySize(colTypeNmIndex); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
91 if (typewidth < 13) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
92 typewidth = 13; // use minimal 13 characters for the typename (same as used in mclient) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
93 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
94 final StringBuilder sb = new StringBuilder(128); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
95 int i; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
96 for (i = 0; cols.next(); i++) { |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
97 if (i > 0) |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
98 out.println(","); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
99 |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
100 // print column name (with double quotes) |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
101 String s = dq(cols.getString(colNmIndex)); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
102 out.print("\t" + s + repeat(' ', (colwidth - s.length() + 3))); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
103 |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
104 int digits = cols.getInt(digitsIndex); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
105 s = cols.getString(colTypeNmIndex).toUpperCase(); // ANSI SQL uses uppercase data type names |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
106 // do some data type substitutions to match SQL standard |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
107 if (s.equals("INT")) { |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
108 s = "INTEGER"; |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
109 } else if (s.equals("SEC_INTERVAL")) { |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
110 s = "INTERVAL SECOND"; |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
111 } else if (s.equals("DAY_INTERVAL")) { |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
112 s = "INTERVAL DAY"; |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
113 } else if (s.equals("MONTH_INTERVAL")) { |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
114 s = "INTERVAL MONTH"; |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
115 } else if (s.equals("TIMETZ")) { |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
116 s = "TIME"; |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
117 // small hack to get desired behaviour: set digits when we have |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
118 // a time with time zone and at the same time masking the internal types |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
119 digits = 1; |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
120 } else if (s.equals("TIMESTAMPTZ")) { |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
121 s = "TIMESTAMP"; |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
122 // small hack to get desired behaviour: set digits when we have |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
123 // a timestamp with time zone and at the same time masking the internal types |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
124 digits = 1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
125 } |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
126 sb.append(s); // add the data type for this column |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
127 |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
128 int ctype = cols.getInt(datatypeIndex); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
129 int size = cols.getInt(sizeIndex); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
130 // do some SQL/MonetDB type length/precision and scale specifics |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 switch (ctype) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
132 case Types.CHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 case Types.VARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 case Types.LONGVARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 case Types.CLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
136 case Types.BLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 case Types.FLOAT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 if (size > 0) |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
139 sb.append('(').append(size).append(')'); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
140 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 case Types.TIME: |
424
709300b32284
Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
420
diff
changeset
|
142 case Types.TIME_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
143 case Types.TIMESTAMP: |
424
709300b32284
Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
420
diff
changeset
|
144 case Types.TIMESTAMP_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
145 if (size > 1) |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
146 sb.append('(').append(size -1).append(')'); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
147 if (digits == 1) // flag is set to include suffix: WITH TIME ZONE |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
148 sb.append(" WITH TIME ZONE"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
149 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 case Types.DECIMAL: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 case Types.NUMERIC: |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
152 sb.append('(').append(size); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
153 if (digits != 0) |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
154 sb.append(',').append(digits); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
155 sb.append(')'); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
156 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
157 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
158 |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
159 boolean isNotNull = cols.getInt(isNotNullIndex) == DatabaseMetaData.columnNoNulls; |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
160 String defaultValue = cols.getString(defaultValueIndex); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
161 boolean hasDefault = (defaultValue != null && !defaultValue.isEmpty()); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
162 if (isNotNull || hasDefault) { |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
163 final int spaces = typewidth - sb.length(); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
164 if (spaces > 0) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
165 sb.append(repeat(' ', spaces)); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
166 if (isNotNull) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
167 sb.append(" NOT NULL"); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
168 if (hasDefault) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
169 sb.append(" DEFAULT ").append(defaultValue); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
170 } |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
171 |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
172 // print column data type, optional length and scale, optional NOT NULL, optional DEFAULT value |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
173 out.print(sb.toString()); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
174 |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
175 sb.setLength(0); // clear the buffer for next column |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
176 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
177 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
178 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
179 // add the primary key constraint definition |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
180 // unfortunately some idiot defined that getPrimaryKeys() |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
181 // returns the primary key columns sorted by column name, not |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
182 // key sequence order. So we have to sort ourself :( |
315
4793f9b80bb3
Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
314
diff
changeset
|
183 cols = dbmd.getPrimaryKeys(null, schema, name); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
184 int colKeySeq = cols.findColumn("KEY_SEQ"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
185 // first make a 'index' of the KEY_SEQ columns |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
186 final java.util.SortedMap<Integer, Integer> seqIndex = new java.util.TreeMap<Integer, Integer>(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
187 for (i = 1; cols.next(); i++) { |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
188 seqIndex.put(Integer.valueOf(cols.getInt(colKeySeq)), Integer.valueOf(i)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
189 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
190 if (seqIndex.size() > 0) { |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
191 cols.absolute(1); // reset to first pk column row |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
192 // terminate the previous line |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
193 out.println(","); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
194 out.print("\tCONSTRAINT " + dq(cols.getString("PK_NAME")) + " PRIMARY KEY ("); |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
195 |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
196 colNmIndex = cols.findColumn("COLUMN_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
197 final Iterator<Map.Entry<Integer, Integer>> it = seqIndex.entrySet().iterator(); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
198 for (i = 0; it.hasNext(); i++) { |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
199 final Map.Entry<Integer, Integer> e = it.next(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
200 cols.absolute(e.getValue().intValue()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
201 if (i > 0) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
202 out.print(", "); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
203 out.print(dq(cols.getString(colNmIndex))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
205 out.print(")"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
206 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
207 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
208 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
209 // add unique constraint definitions |
306
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
210 // we use getIndexInfo to get unique indexes, but need to exclude |
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
211 // the indexes which are generated by the system for pkey constraints |
937
d416e9b6b3d0
Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
901
diff
changeset
|
212 // TODO improve this as the detection on whether it is a UNIQUE NULLS NOT DISTINCT is not good enough. |
315
4793f9b80bb3
Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
314
diff
changeset
|
213 cols = dbmd.getIndexInfo(null, schema, name, true, true); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
214 int colIndexNm = cols.findColumn("INDEX_NAME"); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
215 colNmIndex = cols.findColumn("COLUMN_NAME"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 while (cols.next()) { |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
217 final String idxname = cols.getString(colIndexNm); |
306
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
218 if (idxname != null && !idxname.endsWith("_pkey")) { |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
219 out.println(","); |
901
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
220 out.print("\tCONSTRAINT " + dq(idxname)); |
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
221 if (idxname.endsWith("_nndunique")) |
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
222 out.print(" UNIQUE NULLS NOT DISTINCT ("); // new since release 11.50 (Aug2024) |
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
223 else |
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
224 out.print(" UNIQUE ("); |
73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
225 out.print(dq(cols.getString(colNmIndex))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
226 |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
227 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
228 while ((next = cols.next()) && idxname.equals(cols.getString(colIndexNm))) { |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
229 out.print(", " + dq(cols.getString(colNmIndex))); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
230 } |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
231 // go back one, we've gone one too far |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
232 if (next) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
233 cols.previous(); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
234 |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
235 out.print(")"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
236 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
237 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
240 // add foreign keys definitions |
315
4793f9b80bb3
Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
314
diff
changeset
|
241 cols = dbmd.getImportedKeys(null, schema, name); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
242 final int colFkNm = cols.findColumn("FK_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
243 final int colFkColNm = cols.findColumn("FKCOLUMN_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
244 final int colPkColNm = cols.findColumn("PKCOLUMN_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
245 colKeySeq = cols.findColumn("KEY_SEQ"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
246 final int colPkTblSch = cols.findColumn("PKTABLE_SCHEM"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
247 final int colPkTblNm = cols.findColumn("PKTABLE_NAME"); |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
248 final int colUpdRule = cols.findColumn("UPDATE_RULE"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
249 final int colDelRule = cols.findColumn("DELETE_RULE"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
250 final String onUpdate = " ON UPDATE "; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
251 final String onDelete = " ON DELETE "; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
252 final Set<String> fknames = new LinkedHashSet<String>(8); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
253 final Set<String> fk = new LinkedHashSet<String>(6); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
254 final Set<String> pk = new LinkedHashSet<String>(6); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
255 while (cols.next()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
256 out.println(","); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
257 out.print("\tCONSTRAINT " + dq(cols.getString(colFkNm)) + " FOREIGN KEY ("); |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
258 fknames.add(cols.getString(colFkNm)); // needed later on for exclusion of generating CREATE INDEX for them |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
259 |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
260 fk.clear(); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
261 fk.add(cols.getString(colFkColNm)); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
262 pk.clear(); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
263 pk.add(cols.getString(colPkColNm)); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
264 final short fkUpdRule = cols.getShort(colUpdRule); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
265 final short fkDelRule = cols.getShort(colDelRule); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
266 |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
267 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
268 while ((next = cols.next()) && cols.getInt(colKeySeq) != 1) { |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
269 fk.add(cols.getString(colFkColNm)); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
270 pk.add(cols.getString(colPkColNm)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
271 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
272 // go back one |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
273 if (next) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
274 cols.previous(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
275 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
276 Iterator<String> it = fk.iterator(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
277 for (i = 0; it.hasNext(); i++) { |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
278 if (i > 0) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
279 out.print(", "); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 out.print(dq(it.next())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
281 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
282 out.print(") REFERENCES " + dq(cols.getString(colPkTblSch)) + "." + dq(cols.getString(colPkTblNm)) + " ("); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
283 it = pk.iterator(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
284 for (i = 0; it.hasNext(); i++) { |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
285 if (i > 0) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
286 out.print(", "); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
287 out.print(dq(it.next())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
288 } |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
289 out.print(")"); |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
290 |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
291 // ON UPDATE { NO ACTION | CASCADE | RESTRICT | SET NULL | SET DEFAULT } |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
292 switch (fkUpdRule) { |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
293 case DatabaseMetaData.importedKeyCascade: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
294 out.print(onUpdate); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
295 out.print("CASCADE"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
296 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
297 case DatabaseMetaData.importedKeyNoAction: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
298 out.print(onUpdate); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
299 out.print("NO ACTION"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
300 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
301 case DatabaseMetaData.importedKeyRestrict: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
302 out.print(onUpdate); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
303 out.print("RESTRICT"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
304 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
305 case DatabaseMetaData.importedKeySetNull: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
306 out.print(onUpdate); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
307 out.print("SET NULL"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
308 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
309 case DatabaseMetaData.importedKeySetDefault: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
310 out.print(onUpdate); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
311 out.print("SET DEFAULT"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
312 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
313 } |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
314 // ON DELETE { NO ACTION | CASCADE | RESTRICT | SET NULL | SET DEFAULT } |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
315 switch (fkDelRule) { |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
316 case DatabaseMetaData.importedKeyCascade: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
317 out.print(onDelete); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
318 out.print("CASCADE"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
319 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
320 case DatabaseMetaData.importedKeyNoAction: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
321 out.print(onDelete); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
322 out.print("NO ACTION"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
323 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
324 case DatabaseMetaData.importedKeyRestrict: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
325 out.print(onDelete); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
326 out.print("RESTRICT"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
327 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
328 case DatabaseMetaData.importedKeySetNull: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
329 out.print(onDelete); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
330 out.print("SET NULL"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
331 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
332 case DatabaseMetaData.importedKeySetDefault: |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
333 out.print(onDelete); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
334 out.print("SET DEFAULT"); |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
335 break; |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
336 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
337 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
338 cols.close(); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
339 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
340 out.println(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
341 // end the create table statement |
318
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
342 if (type.equals("REMOTE TABLE")) { |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
343 final String on_clause = fetchSysTablesQueryValue(dbmd.getConnection(), schema, name); |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
344 out.println(") ON '" + ((on_clause != null) ? on_clause : "!!missing mapi:monetdb:// spec") + "';"); |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
345 } else |
13a9d5316e37
Corrected JdbcClient program: the dumping of a view DDL was incorrect when the view creation statement was not starting with "create view ", such as when it was created using "CREATE VIEW" or "create or replace view".
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
315
diff
changeset
|
346 out.println(");"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
347 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
348 // create the non unique indexes defined for this table |
306
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
349 // we use getIndexInfo to get non-unique indexes, but need to exclude |
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
350 // the indexes which are generated by the system for fkey constraints |
7c79ef41b840
Undo change cf372fae2adb. The problem was in the dump code in JdbcClient.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
351 // (and pkey and unique constraints but those are marked as unique and not requested) |
315
4793f9b80bb3
Removed the catalog parameter from the Exporter.dumpSchema method as it is always null for MonetDB.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
314
diff
changeset
|
352 cols = dbmd.getIndexInfo(null, schema, name, false, true); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
353 colIndexNm = cols.findColumn("INDEX_NAME"); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
354 colNmIndex = cols.findColumn("COLUMN_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
355 final int tblNmIndex = cols.findColumn("TABLE_NAME"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
356 final int tblSchIndex = cols.findColumn("TABLE_SCHEM"); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
357 final int nonUniqIndex = cols.findColumn("NON_UNIQUE"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
358 while (cols.next()) { |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
359 if (cols.getBoolean(nonUniqIndex)) { |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
360 // We only process non-unique indexes here. |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
361 // The unique indexes are already covered as UNIQUE constraints in the CREATE TABLE above |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
362 final String idxname = cols.getString(colIndexNm); |
420
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
363 // check idxname is not in the list of fknames for this table |
a0f99a81ce8e
Extend the generation of FOREIGN KEY CONSTRAINTS with ON UPDATE and ON DELETE rules.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
406
diff
changeset
|
364 if (idxname != null && !fknames.contains(idxname)) { |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
365 out.print("CREATE INDEX " + dq(idxname) + " ON " + |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
366 dq(cols.getString(tblSchIndex)) + "." + |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
367 dq(cols.getString(tblNmIndex)) + " (" + |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
368 dq(cols.getString(colNmIndex))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
369 |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
370 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
371 while ((next = cols.next()) && idxname.equals(cols.getString(colIndexNm))) { |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
372 out.print(", " + dq(cols.getString(colNmIndex))); |
5
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
373 } |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
374 // go back one |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
375 if (next) |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
376 cols.previous(); |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
377 |
b07b4940c3ed
Improve output of table definition dump to match output of mclient table definition dump
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
0
diff
changeset
|
378 out.println(");"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
379 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
380 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
381 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
382 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
383 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
384 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
385 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
386 * Dumps the given ResultSet as specified in the form variable. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
387 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
388 * @param rs the ResultSet to dump |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
389 * @throws SQLException if a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
390 */ |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
391 public void dumpResultSet(final ResultSet rs) throws SQLException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
392 switch (outputMode) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
393 case VALUE_INSERT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
394 resultSetToSQL(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
395 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
396 case VALUE_COPY: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
397 resultSetToSQLDump(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
398 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
399 case VALUE_TABLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
400 resultSetToTable(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
401 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
402 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
403 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
404 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
405 public void setProperty(final int type, final int value) throws Exception { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
406 switch (type) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
407 case TYPE_OUTPUT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
408 switch (value) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
409 case VALUE_INSERT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
410 case VALUE_COPY: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
411 case VALUE_TABLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
412 outputMode = value; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
413 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
414 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
415 throw new Exception("Illegal value " + value + " for TYPE_OUTPUT"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
416 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
417 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
418 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
419 throw new Exception("Illegal type " + type); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
420 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
421 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
422 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
423 public int getProperty(final int type) throws Exception { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
424 switch (type) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
425 case TYPE_OUTPUT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
426 return outputMode; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
427 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
428 throw new Exception("Illegal type " + type); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
429 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
430 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
431 |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
432 private static final short AS_IS = 0; |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
433 private static final short QUOTE = 1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
434 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
435 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
436 * Helper method to dump the contents of a table in SQL INSERT INTO |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
437 * format. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
438 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
439 * @param rs the ResultSet to convert into INSERT INTO statements |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
440 * @throws SQLException if a database related error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
441 */ |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
442 private void resultSetToSQL(final ResultSet rs) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
443 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
444 { |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
445 final ResultSetMetaData rsmd = rs.getMetaData(); |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
446 final int cols = rsmd.getColumnCount(); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
447 // get for each output column whether it requires quotes around the value based on data type |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
448 final short[] types = new short[cols +1]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
449 for (int i = 1; i <= cols; i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
450 switch (rsmd.getColumnType(i)) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
451 case Types.CHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
452 case Types.VARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
453 case Types.LONGVARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
454 case Types.CLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
455 case Types.BLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
456 case Types.DATE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
457 case Types.TIME: |
424
709300b32284
Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
420
diff
changeset
|
458 case Types.TIME_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
459 case Types.TIMESTAMP: |
424
709300b32284
Added entries for new Java 8 java.sql.Types: Types.TIME_WITH_TIMEZONE and Types.TIMESTAMP_WITH_TIMEZONE
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
420
diff
changeset
|
460 case Types.TIMESTAMP_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
461 types[i] = QUOTE; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
462 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
463 case Types.NUMERIC: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
464 case Types.DECIMAL: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
465 case Types.BIT: // we don't use type BIT, it's here for completeness |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
466 case Types.BOOLEAN: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
467 case Types.TINYINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
468 case Types.SMALLINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
469 case Types.INTEGER: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
470 case Types.BIGINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
471 case Types.REAL: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
472 case Types.FLOAT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
473 case Types.DOUBLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
474 types[i] = AS_IS; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
475 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
476 default: |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
477 // treat all other types (such as inet,url,json,objects) as complex types requiring quotes |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
478 types[i] = QUOTE; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
479 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
480 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
481 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
482 final StringBuilder strbuf = new StringBuilder(1024); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
483 strbuf.append("INSERT INTO "); |
313
f2750ea9f93d
When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
312
diff
changeset
|
484 final String schema = rsmd.getSchemaName(1); |
f2750ea9f93d
When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
312
diff
changeset
|
485 if (schema != null && !schema.isEmpty()) |
f2750ea9f93d
When exporting table/view definition always include the schema name.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
312
diff
changeset
|
486 strbuf.append(dq(schema)).append("."); |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
487 strbuf.append(dq(rsmd.getTableName(1))).append(" VALUES ("); |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
488 final int cmdpart = strbuf.length(); |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
489 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
490 while (rs.next()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
491 for (int i = 1; i <= cols; i++) { |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
492 final String val = rs.getString(i); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
493 if (i > 1) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
494 strbuf.append(", "); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
495 if (val == null || rs.wasNull()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
496 strbuf.append("NULL"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
497 } else { |
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:
424
diff
changeset
|
498 strbuf.append((types[i] == QUOTE) ? sq(val) : val); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
499 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
500 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
501 strbuf.append(");"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
502 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
503 // clear the variable part of the buffer contents for next data row |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
504 strbuf.setLength(cmdpart); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
505 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
506 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
507 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
508 public void resultSetToSQLDump(final ResultSet rs) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
509 // TODO: write copy into statement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
510 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
511 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
512 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
513 * Helper method to write a ResultSet in a convenient table format |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
514 * to the output writer. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
515 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
516 * @param rs the ResultSet to write out |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
517 * @throws SQLException if a database related error occurs |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
518 */ |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
519 public void resultSetToTable(final ResultSet rs) throws SQLException { |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
520 final ResultSetMetaData md = rs.getMetaData(); |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
521 final int cols = md.getColumnCount(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
522 // find the optimal display widths of the columns |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
523 final int[] width = new int[cols + 1]; |
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
524 final boolean[] isSigned = new boolean[cols + 1]; // used for controlling left or right alignment of data |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
525 for (int j = 1; j < width.length; j++) { |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
526 final int coldisplaysize = md.getColumnDisplaySize(j); |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
527 final int collabellength = md.getColumnLabel(j).length(); |
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
528 final int maxwidth = (coldisplaysize > collabellength) ? coldisplaysize : collabellength; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
529 // the minimum width should be 4 to represent: "NULL" |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
530 width[j] = (maxwidth > 4) ? maxwidth : 4; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
531 isSigned[j] = md.isSigned(j); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
532 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
533 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
534 // use a buffer to construct the text lines |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
535 final StringBuilder strbuf = new StringBuilder(1024); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
536 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
537 // construct the frame lines and header text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
538 strbuf.append('+'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
539 for (int j = 1; j < width.length; j++) |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
540 strbuf.append(repeat('-', width[j] + 1)).append("-+"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
541 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
542 final String outsideLine = strbuf.toString(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
543 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
544 strbuf.setLength(0); // clear the buffer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
545 strbuf.append('|'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
546 for (int j = 1; j < width.length; j++) { |
309
8a96a4a13528
Add additional "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
307
diff
changeset
|
547 final String colLabel = md.getColumnLabel(j); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
548 strbuf.append(' ').append(colLabel); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
549 strbuf.append(repeat(' ', width[j] - colLabel.length())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
550 strbuf.append(" |"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
551 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
552 // print the header text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
553 out.println(outsideLine); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
554 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
555 out.println(outsideLine.replace('-', '=')); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
556 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
557 // print formatted data of each row from resultset |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
558 long count = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
559 for (; rs.next(); count++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
560 strbuf.setLength(0); // clear the buffer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
561 strbuf.append('|'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
562 for (int j = 1; j < width.length; j++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
563 String data = rs.getString(j); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
564 if (data == null || rs.wasNull()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
565 data = "NULL"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
566 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
567 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
568 int filler_length = width[j] - data.length(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
569 if (filler_length <= 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
570 if (filler_length == 0) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
571 strbuf.append(' '); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
572 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
573 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
574 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
575 strbuf.append(' '); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
576 if (isSigned[j]) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
577 // we have a numeric type here, right align |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
578 strbuf.append(repeat(' ', filler_length)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
579 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
580 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
581 // all other left align |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
582 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
583 strbuf.append(repeat(' ', filler_length)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
584 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
585 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
586 strbuf.append(" |"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
587 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
588 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
589 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
590 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
591 // print the footer text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
592 out.println(outsideLine); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
593 out.print(count); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
594 out.println((count != 1) ? " rows" : " row"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
595 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
596 |
307
05549bc7ed26
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
306
diff
changeset
|
597 private void changeSchema(final String schema) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
598 if (lastSchema == null) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
599 lastSchema = new Stack<String>(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
600 lastSchema.push(null); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
601 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
602 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
603 if (!schema.equals(lastSchema.peek())) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
604 if (!lastSchema.contains(schema)) { |
312
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
605 // do not generate CREATE SCHEMA cmds for existing system schemas |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
606 if (!schema.equals("sys") |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
607 && !schema.equals("tmp") |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
608 && !schema.equals("json") |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
609 && !schema.equals("profiler") |
374
31e79dd9e658
Add 3 new system schemas for which no CREATE SCHEMA command should to be generated.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
610 && !schema.equals("wlc") // added in Nov2019 |
31e79dd9e658
Add 3 new system schemas for which no CREATE SCHEMA command should to be generated.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
611 && !schema.equals("wlr") // added in Nov2019 |
31e79dd9e658
Add 3 new system schemas for which no CREATE SCHEMA command should to be generated.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
612 && !schema.equals("logging") // added in Jun2020 |
312
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
613 && !schema.equals("bam")) { |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
614 // create schema |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
615 out.print("CREATE SCHEMA "); |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
616 out.print(dq(schema)); |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
617 out.println(";\n"); |
df815a403bf4
Improved JdbcClient program by including the schema prefix when dumping schema objects. It now behaves more similar to mclient -D -N.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
311
diff
changeset
|
618 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
619 lastSchema.push(schema); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
620 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
621 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
622 out.print("SET SCHEMA "); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
623 out.print(dq(schema)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
624 out.println(";\n"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
625 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
626 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
627 } |