db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r537882 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java
Date Mon, 14 May 2007 15:33:47 GMT
Author: kristwaa
Date: Mon May 14 08:33:46 2007
New Revision: 537882

URL: http://svn.apache.org/viewvc?view=rev&rev=537882
Log:
DERBY-1484: Client and embedded behave differently when the table name is null in DatabaseMetaData
methods.
Patch file: DERBY-1484-4_ExcFact.diff

Patch contributed by Jørgen Løland.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java?view=diff&rev=537882&r1=537881&r2=537882
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
Mon May 14 08:33:46 2007
@@ -37,6 +37,7 @@
 import org.apache.derby.impl.sql.execute.GenericConstantActionFactory;
 import org.apache.derby.impl.sql.execute.GenericExecutionFactory;
 
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.Limits;
 import org.apache.derby.iapi.reference.JDBC20Translation;
 import org.apache.derby.iapi.reference.JDBC30Translation;
@@ -1960,10 +1961,16 @@
      */
 	public ResultSet getColumnPrivileges(String catalog, String schema,
 		String table, String columnNamePattern) throws SQLException {
+
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+
 		PreparedStatement s = getPreparedQuery("getColumnPrivileges");
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484; must match table name as stored
 		s.setString(4, swapNull(columnNamePattern));
 		return s.executeQuery();
 	}
@@ -2040,7 +2047,7 @@
      * @param catalogPattern a catalog name; "" retrieves those without a
      * catalog; null means drop catalog name from the selection criteria
      * @param schemaPattern a schema name; "" retrieves those without a schema
-     * @param tablePattern a table name
+     * @param table a table name
      * @param scope the scope of interest; use same values as SCOPE
      * @param nullable include columns that are nullable?
      * @return ResultSet - each row is a column description
@@ -2050,12 +2057,12 @@
 	(
 		String catalogPattern,
 		String schemaPattern,
-		String tablePattern,
+		String table,
 		int scope,
 		boolean nullable
 	) throws SQLException
 	{
-		return doGetBestRowId(catalogPattern, schemaPattern, tablePattern,
+		return doGetBestRowId(catalogPattern, schemaPattern, table,
 			scope, nullable, "");
 	}
 
@@ -2066,10 +2073,10 @@
 	 * set will conform to ODBC specifications.
 	 */
 	public ResultSet getBestRowIdentifierForODBC(String catalogPattern,
-		String schemaPattern, String tablePattern, int scope,
+		String schemaPattern, String table, int scope,
 		boolean nullable) throws SQLException {
 
-		return doGetBestRowId(catalogPattern, schemaPattern, tablePattern,
+		return doGetBestRowId(catalogPattern, schemaPattern, table,
 			scope, nullable, "odbc_");
 	}
 
@@ -2083,9 +2090,14 @@
 	 *	JDBC or ODBC specifications.
 	 */
 	private ResultSet doGetBestRowId(String catalogPattern,
-		String schemaPattern, String tablePattern, int scope,
+		String schemaPattern, String table, int scope,
 		boolean nullable, String queryPrefix) throws SQLException {
 
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+        
 		int nullableInIntForm = 0;
 		if (nullable)
 			nullableInIntForm = 1;
@@ -2098,10 +2110,6 @@
 		{
 			schemaPattern = "%";
 		}
-		if (tablePattern == null)
-		{
-			tablePattern = "%";
-		}
 
 			PreparedStatement ps;
 			boolean done;
@@ -2116,7 +2124,7 @@
 			ps = getPreparedQuery("getBestRowIdentifierPrimaryKey");
 			ps.setString(1,catalogPattern);
 			ps.setString(2,schemaPattern);
-			ps.setString(3,tablePattern);
+			ps.setString(3,table);
 	
 			ResultSet rs = ps.executeQuery();
 			done = rs.next();
@@ -2145,7 +2153,7 @@
 			ps = getPreparedQuery("getBestRowIdentifierUniqueConstraint");
 			ps.setString(1,catalogPattern);
 			ps.setString(2,schemaPattern);
-			ps.setString(3,tablePattern);
+			ps.setString(3,table);
 	
 			rs = ps.executeQuery();
 			done = rs.next();
@@ -2175,7 +2183,7 @@
 			ps = getPreparedQuery("getBestRowIdentifierUniqueIndex");
 			ps.setString(1,catalogPattern);
 			ps.setString(2,schemaPattern);
-			ps.setString(3,tablePattern);
+			ps.setString(3,table);
 	
 			rs = ps.executeQuery();
 			done = rs.next();
@@ -2203,7 +2211,7 @@
 			ps = getPreparedQuery(queryPrefix + "getBestRowIdentifierAllColumns");
 			ps.setString(1,catalogPattern);
 			ps.setString(2,schemaPattern);
-			ps.setString(3,tablePattern);
+			ps.setString(3,table);
 			ps.setInt(4,scope);
 			ps.setInt(5,nullableInIntForm);
 			return ps.executeQuery();
@@ -2266,10 +2274,15 @@
 	private ResultSet doGetVersionCols(String catalog, String schema,
 		String table, String queryName) throws SQLException {
 
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+        
 		PreparedStatement s = getPreparedQuery(queryName);
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484: Must match table name as stored
 		return s.executeQuery();
 	}
 
@@ -2328,9 +2341,15 @@
 	public ResultSet getPrimaryKeys(String catalog, String schema,
 			String table) throws SQLException {
 		PreparedStatement s = getPreparedQuery("getPrimaryKeys");
+
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484: Must match table name as stored
 		return s.executeQuery();
 	}	
 
@@ -2404,10 +2423,15 @@
      */
 	public ResultSet getImportedKeys(String catalog, String schema,
 				String table) throws SQLException {
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+
 		PreparedStatement s = getPreparedQuery("getImportedKeys");
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484: Must match table name as stored
 		return s.executeQuery();
 	}
 
@@ -2482,10 +2506,16 @@
      */
 	public ResultSet getExportedKeys(String catalog, String schema,
 				String table) throws SQLException {
+
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+
 		PreparedStatement s = getPreparedQuery("getCrossReference");
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484: Must match table name as stored
 		s.setString(4, swapNull(null));
 		s.setString(5, swapNull(null));
 		s.setString(6, swapNull(null));
@@ -2725,12 +2755,17 @@
 		boolean unique, boolean approximate, String queryName)
 		throws SQLException {
 
+        if (table == null) {
+            throw Util.generateCsSQLException(
+                           SQLState.TABLE_NAME_CANNOT_BE_NULL);
+        }
+
 		int approximateInInt = 0;
 		if (approximate) approximateInInt = 1;
 		PreparedStatement s = getPreparedQuery(queryName);
 		s.setString(1, swapNull(catalog));
 		s.setString(2, swapNull(schema));
-		s.setString(3, swapNull(table));
+		s.setString(3, table); //DERBY-1484: Must match table name as stored
 		s.setBoolean(4, unique);
 		s.setInt(5, approximateInInt);
 		return s.executeQuery();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java?view=diff&rev=537882&r1=537881&r2=537882
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/odbc_metadata.java
Mon May 14 08:33:46 2007
@@ -413,13 +413,13 @@
 
 		System.out.println("SQLForeignKeys: getImportedKeys");
 		s.execute(
-			"call sysibm.sqlforeignkeys (null, null, null, null, null, null, " +
+			"call sysibm.sqlforeignkeys (null, null, null, null, null, 'Louie', " +
 					"'IMPORTEDKEY=1;DATATYPE=''ODBC''')");
 		checkODBCNamesAndTypes(s.getResultSet(), GET_IMPORTED_KEYS);
 
 		System.out.println("SQLForeignKeys: getExportedKeys");
 		s.execute(
-			"call sysibm.sqlforeignkeys (null, null, null, null, null, null, " +
+			"call sysibm.sqlforeignkeys (null, null, 'Louie', null, null, null, " +
 				"'EXPORTEDKEY=1;DATATYPE=''ODBC''')");
 		checkODBCNamesAndTypes(s.getResultSet(), GET_EXPORTED_KEYS);
 



Mime
View raw message