Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/util/SQLExporter.java @ 901:73f25cb71e4f
Adapt table DDL generator to deal with new UNIQUE NULLS NOT DISTINCT key_type.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 30 May 2024 19:06:20 +0200 (11 months ago) |
parents | e890195256ac |
children | d416e9b6b3d0 |
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 * |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
8 * Copyright 2024 MonetDB Foundation; |
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 |
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
|
212 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
|
213 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
|
214 colNmIndex = cols.findColumn("COLUMN_NAME"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 out.print(dq(cols.getString(colNmIndex))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
225 |
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
|
226 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
227 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
|
228 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
|
229 } |
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 // 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
|
231 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
|
232 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
|
233 |
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 out.print(")"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 } |
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 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 // 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 while (cols.next()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
255 out.println(","); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
256 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
|
257 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
|
258 |
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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 final short fkDelRule = cols.getShort(colDelRule); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
265 |
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
|
266 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
267 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
|
268 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
|
269 pk.add(cols.getString(colPkColNm)); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
270 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
271 // 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
|
272 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
|
273 cols.previous(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
274 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
275 Iterator<String> it = fk.iterator(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
276 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
|
277 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
|
278 out.print(", "); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
279 out.print(dq(it.next())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
280 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
281 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
|
282 it = pk.iterator(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
283 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
|
284 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
|
285 out.print(", "); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
286 out.print(dq(it.next())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
287 } |
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
|
288 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
|
289 |
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 // 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 } |
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 // 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
336 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
337 cols.close(); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
338 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
339 out.println(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
340 // 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
|
341 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
|
342 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
|
343 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
|
344 } 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
|
345 out.println(");"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
346 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
347 // 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
|
348 // 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
|
349 // 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
|
350 // (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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 final int nonUniqIndex = cols.findColumn("NON_UNIQUE"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
357 while (cols.next()) { |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
358 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
|
359 // 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
|
360 // 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
|
361 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
|
362 // 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
|
363 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
|
364 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
|
365 dq(cols.getString(tblSchIndex)) + "." + |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
366 dq(cols.getString(tblNmIndex)) + " (" + |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
367 dq(cols.getString(colNmIndex))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
368 |
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
|
369 boolean next; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
370 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
|
371 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
|
372 } |
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 // 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
|
374 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
|
375 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
|
376 |
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 out.println(");"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
378 } |
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 cols.close(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
382 } |
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 * 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
|
386 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
387 * @param rs the ResultSet to dump |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
388 * @throws SQLException if a database error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
389 */ |
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
|
390 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
|
391 switch (outputMode) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
392 case VALUE_INSERT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
393 resultSetToSQL(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
394 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
395 case VALUE_COPY: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
396 resultSetToSQLDump(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
397 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
398 case VALUE_TABLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
399 resultSetToTable(rs); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
400 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
401 } |
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 |
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
|
404 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
|
405 switch (type) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
406 case TYPE_OUTPUT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
407 switch (value) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
408 case VALUE_INSERT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
409 case VALUE_COPY: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
410 case VALUE_TABLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
411 outputMode = value; |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
412 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
413 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
414 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
|
415 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
416 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
417 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
418 throw new Exception("Illegal type " + type); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
419 } |
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 |
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
|
422 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
|
423 switch (type) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
424 case TYPE_OUTPUT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
425 return outputMode; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
426 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
427 throw new Exception("Illegal type " + type); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
428 } |
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 |
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
|
431 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
|
432 private static final short QUOTE = 1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
433 |
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 * 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
|
436 * format. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
437 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
438 * @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
|
439 * @throws SQLException if a database related error occurs |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
440 */ |
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
|
441 private void resultSetToSQL(final ResultSet rs) |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
442 throws SQLException |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
443 { |
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
|
444 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
|
445 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
|
446 // 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
|
447 final short[] types = new short[cols +1]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
448 for (int i = 1; i <= cols; i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
449 switch (rsmd.getColumnType(i)) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
450 case Types.CHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
451 case Types.VARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
452 case Types.LONGVARCHAR: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
453 case Types.CLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
454 case Types.BLOB: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
455 case Types.DATE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
456 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
|
457 case Types.TIME_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
458 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
|
459 case Types.TIMESTAMP_WITH_TIMEZONE: |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
460 types[i] = QUOTE; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
461 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
462 case Types.NUMERIC: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
463 case Types.DECIMAL: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
464 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
|
465 case Types.BOOLEAN: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
466 case Types.TINYINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
467 case Types.SMALLINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
468 case Types.INTEGER: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
469 case Types.BIGINT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
470 case Types.REAL: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
471 case Types.FLOAT: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
472 case Types.DOUBLE: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
473 types[i] = AS_IS; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
474 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
475 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
|
476 // 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
|
477 types[i] = QUOTE; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
478 } |
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 |
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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
489 while (rs.next()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
490 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
|
491 final String val = rs.getString(i); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
492 if (i > 1) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
493 strbuf.append(", "); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
494 if (val == null || rs.wasNull()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
495 strbuf.append("NULL"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
496 } 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
|
497 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
|
498 } |
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 strbuf.append(");"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
501 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
502 // 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
|
503 strbuf.setLength(cmdpart); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
504 } |
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 |
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
|
507 public void resultSetToSQLDump(final ResultSet rs) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
508 // TODO: write copy into statement |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
509 } |
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 * 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
|
513 * to the output writer. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
514 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
515 * @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
|
516 * @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
|
517 */ |
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
|
518 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
|
519 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
|
520 final int cols = md.getColumnCount(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
521 // 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 final int maxwidth = (coldisplaysize > collabellength) ? coldisplaysize : collabellength; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
528 // 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
|
529 width[j] = (maxwidth > 4) ? maxwidth : 4; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
530 isSigned[j] = md.isSigned(j); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
531 } |
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 // 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
|
534 final StringBuilder strbuf = new StringBuilder(1024); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
535 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
536 // construct the frame lines and header text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
537 strbuf.append('+'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
538 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
|
539 strbuf.append(repeat('-', width[j] + 1)).append("-+"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
540 |
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
|
541 final String outsideLine = strbuf.toString(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
542 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
543 strbuf.setLength(0); // clear the buffer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
544 strbuf.append('|'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
545 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
|
546 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
|
547 strbuf.append(' ').append(colLabel); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
548 strbuf.append(repeat(' ', width[j] - colLabel.length())); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
549 strbuf.append(" |"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
550 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
551 // print the header text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
552 out.println(outsideLine); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
553 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
554 out.println(outsideLine.replace('-', '=')); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
555 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
556 // print formatted data of each row from resultset |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
557 long count = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
558 for (; rs.next(); count++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
559 strbuf.setLength(0); // clear the buffer |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
560 strbuf.append('|'); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
561 for (int j = 1; j < width.length; j++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
562 String data = rs.getString(j); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
563 if (data == null || rs.wasNull()) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
564 data = "NULL"; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
565 } |
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 int filler_length = width[j] - data.length(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
568 if (filler_length <= 0) { |
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 strbuf.append(' '); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
571 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
572 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
573 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
574 strbuf.append(' '); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
575 if (isSigned[j]) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
576 // we have a numeric type here, right align |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
577 strbuf.append(repeat(' ', filler_length)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
578 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
579 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
580 // all other left align |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
581 strbuf.append(data); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
582 strbuf.append(repeat(' ', filler_length)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
583 } |
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 strbuf.append(" |"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
586 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
587 out.println(strbuf.toString()); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
588 } |
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 // print the footer text |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
591 out.println(outsideLine); |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
592 out.print(count); |
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
593 out.println((count != 1) ? " rows" : " row"); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
594 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
595 |
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
|
596 private void changeSchema(final String schema) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
597 if (lastSchema == null) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
598 lastSchema = new Stack<String>(); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
599 lastSchema.push(null); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
600 } |
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 if (!schema.equals(lastSchema.peek())) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
603 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
|
604 // 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
|
605 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
|
606 && !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
|
607 && !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
|
608 && !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
|
609 && !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
|
610 && !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
|
611 && !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
|
612 && !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
|
613 // 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
|
614 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
|
615 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
|
616 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
|
617 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
618 lastSchema.push(schema); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
619 } |
314
6d98a1d3af00
Optimize and improve SQL and XML exporters
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
313
diff
changeset
|
620 |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
621 out.print("SET SCHEMA "); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
622 out.print(dq(schema)); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
623 out.println(";\n"); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
624 } |
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 } |