You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2007/05/08 09:14:39 UTC
svn commit: r536107 - in /db/derby/code/branches/10.2/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/apa...
Author: kristwaa
Date: Tue May 8 00:14:37 2007
New Revision: 536107
URL: http://svn.apache.org/viewvc?view=rev&rev=536107
Log:
DERBY-2222: 'show indexes in SCHEMANAME' does not work with the client driver. Merged 'DERBY-2222-3.diff' from trunk (revision 536100).
Patch contributed by Jørgen Løland.
Added:
db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java
- copied unchanged from r536100, db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijMultipleResultSetResult.java
Modified:
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj
db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResult.java
db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java
db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
db/derby/code/branches/10.2/java/tools/org/apache/derby/loc/toolsmessages.properties
db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java
Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/ij7.out Tue May 8 00:14:37 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/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij7.sql Tue May 8 00:14:37 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/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ij.jj Tue May 8 00:14:37 2007
@@ -63,6 +63,8 @@
import java.util.Vector;
import java.util.Enumeration;
import java.util.Locale;
+import java.util.List;
+import java.util.ArrayList;
/**
@@ -635,51 +637,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);
+ @param table the exact name of the table to find indexes for
+ */
+ private ResultSet getIndexInfoForTable(String schema, String table)
+ throws SQLException {
- DatabaseMetaData dbmd = theConnection.getMetaData();
- rs = dbmd.getIndexInfo(null, schema, table, false, true);
+ 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);
- 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,
- };
-
- 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
Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResult.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResult.java?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResult.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResult.java Tue May 8 00:14:37 2007
@@ -28,6 +28,7 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.Vector;
+import java.util.List;
/**
* This is a wrapper for results coming out of the
@@ -45,12 +46,14 @@
boolean isVector();
boolean isMulti();
boolean isException();
+ boolean isMultipleResultSetResult();
boolean hasWarnings() throws SQLException ;
Connection getConnection();
Statement getStatement();
int getUpdateCount() throws SQLException;
ResultSet getResultSet() throws SQLException;
+ List getMultipleResultSets();
ResultSet getNextRowOfResultSet();
Vector getVector();
SQLException getException();
Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/ijResultImpl.java Tue May 8 00:14:37 2007
@@ -28,6 +28,7 @@
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.Vector;
+import java.util.List;
/**
* This is an empty impl for reuse of code.
@@ -43,12 +44,14 @@
public boolean isVector() { return false; }
public boolean isMulti() { return false; }
public boolean isException() { return false; }
+ public boolean isMultipleResultSetResult(){ return false; }
public boolean hasWarnings() throws SQLException { return getSQLWarnings()!=null; }
public Connection getConnection() { return null; }
public Statement getStatement() { return null; }
public int getUpdateCount() throws SQLException { return -1; }
public ResultSet getResultSet() throws SQLException { return null; }
+ public List getMultipleResultSets() { return null; }
public ResultSet getNextRowOfResultSet() { return null; }
public Vector getVector() { return null; }
public SQLException getException() { return null; }
@@ -69,6 +72,9 @@
if (isVector()) return LocalizedResource.getMessage("IJ_Vec0",getVector().toString());
if (isMulti()) return LocalizedResource.getMessage("IJ_Mul0",getVector().toString());
if (isException()) return LocalizedResource.getMessage("IJ_Exc0",getException().toString());
+ if (isMultipleResultSetResult())
+ return LocalizedResource.getMessage("IJ_MRS0",
+ getMultipleResultSets().toString());
try {
if (isResultSet()) return LocalizedResource.getMessage("IJ_Rse0",getStatement().toString());
} catch(SQLException se) {
Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Tue May 8 00:14:37 2007
@@ -33,6 +33,7 @@
import org.apache.derby.iapi.error.PublicAPI;
import org.apache.derby.iapi.error.StandardException;
+import java.util.List;
import java.util.Stack;
import java.util.Hashtable;
import java.util.Properties;
@@ -488,6 +489,17 @@
throw se;
}
result.closeStatement();
+ } else if (result.isMultipleResultSetResult()) {
+ List resultSets = result.getMultipleResultSets();
+ try {
+ JDBCDisplayUtil.DisplayMultipleResults(out,resultSets,
+ connEnv[currCE].getConnection(),
+ result.getColumnDisplayList(),
+ result.getColumnWidthList());
+ } catch (SQLException se) {
+ result.closeStatement();
+ throw se;
+ }
} else if (result.isException()) {
JDBCDisplayUtil.ShowException(out,result.getException());
}
Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/loc/toolsmessages.properties
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/loc/toolsmessages.properties?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/loc/toolsmessages.properties (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/loc/toolsmessages.properties Tue May 8 00:14:37 2007
@@ -157,6 +157,7 @@
IJ_Vec0=VEC::{0}
IJ_Mul0=MUL::{0}
IJ_Exc0=EXC::{0}
+IJ_MRS0=MRS::{0}
IJ_Rse0=RST::{0}
IJ_Unkn0=UNKNOWN::{0}
# From util.java
Modified: db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java?view=diff&rev=536107&r1=536106&r2=536107
==============================================================================
--- db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java (original)
+++ db/derby/code/branches/10.2/java/tools/org/apache/derby/tools/JDBCDisplayUtil.java Tue May 8 00:14:37 2007
@@ -38,6 +38,8 @@
import java.util.Properties;
import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
import org.apache.derby.iapi.tools.i18n.LocalizedResource;
@@ -287,15 +289,34 @@
}
- /**
- @param out the place to write to
- @param rs the ResultSet to display
- @param conn the Connection against which the ResultSet was retrieved
- @param displayColumns Column numbers to display, or null if all
- @param displayColumnWidths Column widths, in characters, if displayColumns is specified.
+ /**
+ @param out the place to write to
+ @param resultSets List of ResultSet to display
+ @param conn the Connection against which the ResultSet was retrieved
+ @param displayColumns Column numbers to display, or null if all
+ @param displayColumnWidths Column widths, in characters, if displayColumns is specified.
+
+ @exception SQLException on JDBC access failure
+ */
+ static public void DisplayMultipleResults(PrintWriter out, List resultSets,
+ Connection conn,
+ int[] displayColumns,
+ int[] displayColumnWidths)
+ throws SQLException
+ {
+ indent_DisplayResults( out, resultSets, conn, 0, displayColumns,
+ displayColumnWidths);
+ }
- @exception SQLException on JDBC access failure
- */
+ /**
+ @param out the place to write to
+ @param rs the ResultSet to display
+ @param conn the Connection against which the ResultSet was retrieved
+ @param displayColumns Column numbers to display, or null if all
+ @param displayColumnWidths Column widths, in characters, if displayColumns is specified.
+
+ @exception SQLException on JDBC access failure
+ */
static public void DisplayResults(PrintWriter out, ResultSet rs, Connection conn,
int[] displayColumns, int[] displayColumnWidths)
throws SQLException
@@ -304,66 +325,90 @@
displayColumnWidths);
}
- static private void indent_DisplayResults
- (PrintWriter out, ResultSet rs, Connection conn, int indentLevel,
- int[] displayColumns, int[] displayColumnWidths)
- throws SQLException {
- ResultSetMetaData rsmd = rs.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;
+ static private void indent_DisplayResults
+ (PrintWriter out, ResultSet rs, Connection conn, int indentLevel,
+ int[] displayColumns, int[] displayColumnWidths)
+ throws SQLException {
+ List resultSets = new ArrayList();
+ resultSets.add(rs);
+ indent_DisplayResults( out, resultSets, conn, 0, displayColumns,
+ displayColumnWidths);
+ }
- 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.
- boolean doNext = true;
- int retry = 0;
- while (doNext) {
- try {
- doNext = rs.next();
- if (doNext) {
+ static private void indent_DisplayResults
+ (PrintWriter out, List resultSets, Connection conn, int indentLevel,
+ int[] displayColumns, int[] displayColumnWidths)
+ throws SQLException {
+
+ ResultSetMetaData rsmd = null;
+
+ //get metadata from the first ResultSet
+ if (resultSets != null && resultSets.size() > 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