Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 65565 invoked from network); 8 May 2007 06:50:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 May 2007 06:50:17 -0000 Received: (qmail 42002 invoked by uid 500); 8 May 2007 06:50:24 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 41970 invoked by uid 500); 8 May 2007 06:50:24 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 41957 invoked by uid 99); 8 May 2007 06:50:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2007 23:50:24 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2007 23:50:16 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 773B51A9838; Mon, 7 May 2007 23:49:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r536100 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/tools/ tools/org/apache/derby/impl/tools/ij/ tools/org/apache/derby/loc/ tools/org/apache/derb... Date: Tue, 08 May 2007 06:49:56 -0000 To: derby-commits@db.apache.org From: kristwaa@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070508064956.773B51A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kristwaa Date: Mon May 7 23:49:55 2007 New Revision: 536100 URL: http://svn.apache.org/viewvc?view=rev&rev=536100 Log: DERBY-2222: 'show indexes in SCHEMANAME' does not work with the client driver. Patch file: DERBY-2222-3.diff Patch contributed by Jørgen Løland. Added: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java (with props) Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResult.java db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties db/derby/code/trunk/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out?view=diff&rev=536100&r1=536099&r2=536100 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out Mon May 7 23:49:55 2007 @@ -142,6 +142,11 @@ ------------------------------------------------------------------------ USER1 |T3 | 1 row selected +ij> SHOW INDEXES IN APP; +TABLE_NAME |COLUMN_NAME |NON_U&|TYPE|ASC&|CARDINA&|PAGES +---------------------------------------------------------------------------- +T1 |TEST |true |3 |A |NULL |NULL +1 row selected ij> SHOW INDEXES FROM APP.t1; TABLE_NAME |COLUMN_NAME |NON_U&|TYPE|ASC&|CARDINA&|PAGES ---------------------------------------------------------------------------- Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql?view=diff&rev=536100&r1=536099&r2=536100 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql Mon May 7 23:49:55 2007 @@ -51,5 +51,6 @@ SHOW VIEWS IN USER1; SHOW PROCEDURES IN APP; SHOW SYNONYMS IN USER1; +SHOW INDEXES IN APP; SHOW INDEXES FROM APP.t1; Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?view=diff&rev=536100&r1=536099&r2=536100 ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Mon May 7 23:49:55 2007 @@ -64,6 +64,8 @@ import java.util.Vector; import java.util.Enumeration; import java.util.Locale; +import java.util.List; +import java.util.ArrayList; /** @@ -642,51 +644,129 @@ Return a resultset of indexes for the given table or schema @param schema schema to find indexes for - @param table table to find indexes for - */ - public ijResult showIndexes(String schema, String table) throws SQLException { - ResultSet rs = null; - try { - haveConnection(); - verifyTableExists(schema, table); - - DatabaseMetaData dbmd = theConnection.getMetaData(); - rs = dbmd.getIndexInfo(null, schema, table, false, true); + @param table the exact name of the table to find indexes for + */ + private ResultSet getIndexInfoForTable(String schema, String table) + throws SQLException { - int[] displayColumns = new int[] { - rs.findColumn("TABLE_SCHEM"), - rs.findColumn("TABLE_NAME"), - rs.findColumn("COLUMN_NAME"), - rs.findColumn("NON_UNIQUE"), - rs.findColumn("TYPE"), - rs.findColumn("ASC_OR_DESC"), - rs.findColumn("CARDINALITY"), - rs.findColumn("PAGES"), - }; - int[] columnWidths = new int[] { - 20, - 20, - 20, - 6, - 4, - 4, - 8, - 8, - }; + ResultSet rs = null; + try { + haveConnection(); + verifyTableExists(schema, table); + + DatabaseMetaData dbmd = theConnection.getMetaData(); + rs = dbmd.getIndexInfo(null, schema, table, false, true); + + } catch (SQLException e) { + if(rs!=null) + rs.close(); + throw e; + } + return rs; + } + + /** + * Used by showIndexes to get columns in correct order + */ + private int[] getDisplayColumnsForIndex(String schema, ResultSet rs) + throws SQLException{ + int[] displayColumns = new int[] { + rs.findColumn("TABLE_SCHEM"), + rs.findColumn("TABLE_NAME"), + rs.findColumn("COLUMN_NAME"), + rs.findColumn("NON_UNIQUE"), + rs.findColumn("TYPE"), + rs.findColumn("ASC_OR_DESC"), + rs.findColumn("CARDINALITY"), + rs.findColumn("PAGES"), + }; + if(schema!=null) { + displayColumns = intArraySubset(displayColumns, 1, + displayColumns.length); + } + return displayColumns; + } + + /** + * Used by showIndexes to get correct column widths + */ + private int[] getColumnWidthsForIndex(String schema){ + int[] columnWidths = new int[] { + 20, + 20, + 20, + 6, + 4, + 4, + 8, + 8, + }; + if(schema!=null) { + columnWidths = intArraySubset(columnWidths, 1, + columnWidths.length); + } + return columnWidths; + } + + /** + * Used to show all indices + * @param schema the schema indices are shown from. + * @param table the table name to show indices for. If null, all + * indices of the schema are returned. + */ + public ijResult showIndexes(String schema, String table) throws SQLException { + + ijResult result = null; + + int[] displayColumns = null; + int[] columnWidths = null; + + try { + if (table != null) { + ResultSet rs = getIndexInfoForTable(schema, table); + displayColumns = getDisplayColumnsForIndex(schema, rs); + columnWidths = getColumnWidthsForIndex(schema); + result = new ijResultSetResult(rs, displayColumns, + columnWidths); + } + else { + /* DatabaseMetaData#getIndexInfo requires exact table names. + * If table is null, we must first get all table names in + * the appropriate schema, and then get all indices for each + * of these. + */ + haveConnection(); + verifyTableExists(schema, table); - if(schema!=null) { - displayColumns = intArraySubset(displayColumns, 1, - displayColumns.length); - columnWidths = intArraySubset(columnWidths, 1, - columnWidths.length); - } - return new ijResultSetResult(rs, displayColumns, columnWidths); - } catch (SQLException e) { - if(rs!=null) - rs.close(); - throw e; - } - } + DatabaseMetaData dbmd = theConnection.getMetaData(); + ResultSet tablers = dbmd.getTables(null,schema,null,null); + + List resultSets = new ArrayList(); + boolean firstIteration = true; + ResultSet current_rs = null; + while (tablers.next()){ + String tableName = tablers.getString("TABLE_NAME"); + current_rs = getIndexInfoForTable(schema, tableName); + resultSets.add(current_rs); + + if (firstIteration) { + displayColumns = getDisplayColumnsForIndex(schema, + current_rs); + columnWidths = getColumnWidthsForIndex(schema); + firstIteration = false; + } + } + result = new ijMultipleResultSetResult(resultSets, + displayColumns, + columnWidths); + } + return result; + } catch (SQLException e) { + if(result!=null) + result.closeStatement(); + throw e; + } + } /** Return a resultset of procedures from database metadata Added: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java?view=auto&rev=536100 ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java (added) +++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java Mon May 7 23:49:55 2007 @@ -0,0 +1,123 @@ +/* + +Derby - Class org.apache.derby.impl.tools.ij.ijResultSetResult + +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/ + +package org.apache.derby.impl.tools.ij; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.SQLException; +import java.sql.SQLWarning; + +import java.util.List; +import java.util.ArrayList; + +/** + * This impl is intended to be used with multiple resultsets, where + * the execution of the statement is already complete. + */ +public class ijMultipleResultSetResult extends ijResultImpl { + + List resultSets = null; + + int[] displayColumns = null; + int[] columnWidths = null; + + /** + * Create a ijResultImpl that represents multiple result set. + */ + public ijMultipleResultSetResult(List resultSets) throws SQLException { + resultSets = new ArrayList(); + resultSets.addAll(resultSets); + } + + /** + * Create a ijResultImpl that represents multiple result sets, only + * displaying a subset of the columns, using specified column widths. + * + * @param resultSets The result sets to display + * @param display Which column numbers to display, or null to display + * all columns. + * @param widths The widths of the columns specified in 'display', or + * null to display using default column sizes. + */ + public ijMultipleResultSetResult(List resultSets, int[] display, + int[] widths) throws SQLException { + this.resultSets = new ArrayList(); + this.resultSets.addAll(resultSets); + + displayColumns = display; + columnWidths = widths; + } + + + public void addResultSet(ResultSet rs){ + resultSets.add(rs); + } + + public boolean isMultipleResultSetResult(){ + return true; + } + + public List getMultipleResultSets() { + return resultSets; + } + + public void closeStatement() throws SQLException { + if (resultSets != null) { + ResultSet rs = null; + for (int i = 0; i 0) + rsmd = ((ResultSet)resultSets.get(0)).getMetaData(); + + checkNotNull(rsmd, "ResultSetMetaData"); + Vector nestedResults; + int numberOfRowsSelected = 0; + + // autocommit must be off or the nested cursors + // are closed when the outer statement completes. + if (!conn.getAutoCommit()) + nestedResults = new Vector(); + else + nestedResults = null; + + if(displayColumnWidths == null) + displayColumnWidths = getColumnDisplayWidths(rsmd, + displayColumns,true); + + int len = indent_DisplayBanner(out,rsmd, indentLevel, displayColumns, + displayColumnWidths); + + // When displaying rows, keep going past errors + // unless/until the maximum # of errors is reached. + int retry = 0; + + ResultSet rs = null; + boolean doNext = true; + for (int i = 0; i< resultSets.size(); i++) { + rs = (ResultSet)resultSets.get(i); + doNext = true; + while (doNext){ + try { + doNext = rs.next(); + if (doNext) { + + DisplayRow(out, rs, rsmd, len, nestedResults, conn, + indentLevel, displayColumns, + displayColumnWidths); + ShowWarnings(out, rs); + numberOfRowsSelected++; + } + } catch (SQLException e) { + // REVISIT: might want to check the exception + // and for some, not bother with the retry. + if (++retry > MAX_RETRIES) + throw e; + else + ShowSQLException(out, e); + } + } + } + if (showSelectCount == true) { + if (numberOfRowsSelected == 1) { + out.println(); + indentedPrintLine( out, indentLevel, LocalizedResource.getMessage("UT_1RowSelec")); + } else if (numberOfRowsSelected >= 0) { + out.println(); + indentedPrintLine( out, indentLevel, + LocalizedResource.getMessage("UT_0RowsSelec", LocalizedResource.getNumber(numberOfRowsSelected))); + } + } - DisplayRow(out, rs, rsmd, len, nestedResults, conn, - indentLevel, displayColumns, - displayColumnWidths); - ShowWarnings(out, rs); - numberOfRowsSelected++; - } - } catch (SQLException e) { - // REVISIT: might want to check the exception - // and for some, not bother with the retry. - if (++retry > MAX_RETRIES) - throw e; - else - ShowSQLException(out, e); - } - } - if (showSelectCount == true) { - if (numberOfRowsSelected == 1) { - out.println(); - indentedPrintLine( out, indentLevel, LocalizedResource.getMessage("UT_1RowSelec")); - } else if (numberOfRowsSelected >= 0) { - out.println(); - indentedPrintLine( out, indentLevel, - LocalizedResource.getMessage("UT_0RowsSelec", LocalizedResource.getNumber(numberOfRowsSelected))); - } - } + DisplayNestedResults(out, nestedResults, conn, indentLevel ); + nestedResults = null; + } - DisplayNestedResults(out, nestedResults, conn, indentLevel ); - nestedResults = null; - } /** @param out the place to write to