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 ma...@apache.org on 2013/08/02 21:03:46 UTC
svn commit: r1509814 - in /db/derby/code/branches/10.8/java:
engine/org/apache/derby/catalog/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: mamta
Date: Fri Aug 2 19:03:46 2013
New Revision: 1509814
URL: http://svn.apache.org/r1509814
Log:
DERBY-5750(Sending an empty string as table name to compress table procedure or empty string as index name to update statistics procedure makes the parser throw an exception.)
Backporting to 10.8
Modified:
db/derby/code/branches/10.8/java/engine/org/apache/derby/catalog/SystemProcedures.java
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=1509814&r1=1509813&r2=1509814&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/catalog/SystemProcedures.java Fri Aug 2 19:03:46 2013
@@ -721,14 +721,20 @@ public class SystemProcedures {
* SYSCS_UTIL.SYSCS_UPDATE_STATISTICS
* <p>
*
- * @param schemaname schema name of the index(es) whose statistics will
- * be updated. Must be non-null, no default is used.
+ * @param schemaname schema name of the table/index(es) whose
+ * statistics will be updated. null will mean use
+ * the current schema to resolve the table name.
+ * Empty string for schema name will raise an
+ * exception.
* @param tablename table name of the index(es) whose statistics will
- * be updated. Must be non-null.
- * @param indexname Can be null. If not null or emptry string then the
- * user wants to update the statistics for only this
- * index. If null, then update the statistics for all
- * the indexes for the given table name.
+ * be updated. A null value or an empty string will
+ * throw table not found exception. Must be non-null.
+ * @param indexname If null, then update the statistics for all the
+ * indexes for the given table name. If not null and
+ * not empty string, then the user wants to update the
+ * statistics for only the give index name.
+ * Empty string for index name will raise an
+ * exception.
*
* @exception StandardException Standard exception policy.
**/
@@ -738,16 +744,24 @@ public class SystemProcedures {
String indexname)
throws SQLException
{
- String escapedSchema = IdUtil.normalToDelimited(schemaname);
- String escapedTableName = IdUtil.normalToDelimited(tablename);
- String query = "alter table " + escapedSchema + "." + escapedTableName;
+ StringBuffer query = new StringBuffer();
+ query.append("alter table ");
+ query.append(basicSchemaTableValidation(schemaname,tablename));
+
+ //Index name can't be empty string
+ if (indexname != null && indexname.length()==0)
+ throw PublicAPI.wrapStandardException(
+ StandardException.newException(
+ SQLState.LANG_INDEX_NOT_FOUND,
+ indexname));
+
if (indexname == null)
- query = query + " all update statistics ";
+ query.append(" all update statistics ");
else
- query = query + " update statistics " + IdUtil.normalToDelimited(indexname);
+ query.append(" update statistics " + IdUtil.normalToDelimited(indexname));
Connection conn = getDefaultConn();
- PreparedStatement ps = conn.prepareStatement(query);
+ PreparedStatement ps = conn.prepareStatement(query.toString());
ps.executeUpdate();
ps.close();
@@ -755,6 +769,44 @@ public class SystemProcedures {
}
/**
+ * Do following checks
+ * a)Schema name can't be empty string
+ * b)If schema name is null, then we use current schema
+ * c)Table name can't be null or empty string
+ *
+ * @param schemaname If schema name is null, then we will use the
+ * current schema to resolve the table name. Empty
+ * string for schema name will raise an exception.
+ * @param tablename If table name is null or an empty string, we will
+ * throw table not found exception.
+ * @return schemaname.tablename or tablename
+ * @throws SQLException
+ * a)if schema name is empty string
+ * b)if table name is empty string
+ * c)if table name is null
+ */
+ private static String basicSchemaTableValidation(
+ String schemaname, String tablename)
+ throws SQLException
+ {
+ //Schema name can't be empty string
+ if (schemaname != null && schemaname.length()==0)
+ throw PublicAPI.wrapStandardException(
+ StandardException.newException(
+ SQLState.LANG_SCHEMA_DOES_NOT_EXIST,
+ schemaname));
+
+ //Table name can't be null or empty string
+ if ((tablename==null) || tablename.length()==0)
+ throw PublicAPI.wrapStandardException(
+ StandardException.newException(
+ SQLState.LANG_TABLE_NOT_FOUND,
+ tablename));
+
+ return IdUtil.mkQualifiedName(schemaname, tablename);
+ }
+
+ /**
* Compress the table.
* <p>
* Calls the "alter table compress {sequential}" sql. This syntax
@@ -764,31 +816,32 @@ public class SystemProcedures {
* SYSCS_UTIL.SYSCS_COMPRESS_TABLE
* <p>
*
- * @param schema schema name of the table to compress. Must be
- * non-null, no default is used.
- * @param tablename table name of the table to compress. Must be
- * non-null.
+ * @param schemaname schema name of the table to compress. null will
+ * mean use the current schema to resolve the table
+ * name. Empty string for schema name will raise an
+ * exception.
+ * @param tablename table name of the table to compress. A null value
+ * or an empty string will throw table not found
+ * exception. Must be non-null.
* @param sequential if non-zero then rebuild indexes sequentially,
* if 0 then rebuild all indexes in parallel.
*
* @exception StandardException Standard exception policy.
**/
public static void SYSCS_COMPRESS_TABLE(
- String schema,
+ String schemaname,
String tablename,
short sequential)
throws SQLException
{
-
- String escapedSchema = IdUtil.normalToDelimited(schema);
- String escapedTableName = IdUtil.normalToDelimited(tablename);
- String query =
- "alter table " + escapedSchema + "." + escapedTableName +
- " compress" + (sequential != 0 ? " sequential" : "");
+ StringBuffer query = new StringBuffer();
+ query.append("alter table ");
+ query.append(basicSchemaTableValidation(schemaname,tablename));
+ query.append(" compress" + (sequential != 0 ? " sequential" : ""));
Connection conn = getDefaultConn();
- PreparedStatement ps = conn.prepareStatement(query);
+ PreparedStatement ps = conn.prepareStatement(query.toString());
ps.executeUpdate();
ps.close();
Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java?rev=1509814&r1=1509813&r2=1509814&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CompressTableTest.java Fri Aug 2 19:03:46 2013
@@ -49,6 +49,53 @@ public class CompressTableTest extends B
TestConfiguration.embeddedSuite(CompressTableTest.class));
}
+ //DERBY-5750(Sending an empty string as table name to compress table
+ // procedure or empty string as index name to update statistics procedure
+ // makes the parser throw an exception.)
+ //
+ //No table name will result in the same exception that a user would
+ // get when issuing the compress table sql directly without the table name
+ // eg alter table compress sequential
+ // Notice that the table name is missing in the compress sql above
+ public void testCompressTableWithEmptyParamsDerby5750() throws SQLException {
+ Statement s = createStatement();
+ s.execute("create table DERBY5750_t1 (c11 int)");
+
+ //Following 2 statements will give exception since there is no schema
+ // named empty string
+ assertStatementError(
+ "42Y07", s,
+ "call syscs_util.syscs_compress_table('','DERBY5750_T1',1)");
+ assertStatementError(
+ "42Y07", s,
+ "call syscs_util.syscs_compress_table('','',1)");
+
+ //null schema name will translate to current schema
+ s.execute("call syscs_util.syscs_compress_table(null,'DERBY5750_T1',1)");
+
+ //Following 2 statements will give exception since there is no table
+ // named empty string
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.syscs_compress_table(null,'',1)");
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.syscs_compress_table('APP','',1)");
+
+ //Following 2 statements will give exception since table name can't
+ // be null
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.syscs_compress_table(null,null,1)");
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.syscs_compress_table('APP',null,1)");
+
+ s.execute("call syscs_util.syscs_compress_table('APP','DERBY5750_T1',1)");
+
+ s.execute("drop table DERBY5750_t1");
+ }
+
/**
* Test that SYSCS_COMPRESS_TABLE and SYSCS_INPLACE_COMPRESS_TABLE work
* when the table name contains a double quote. It used to raise a syntax
Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java?rev=1509814&r1=1509813&r2=1509814&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdateStatisticsTest.java Fri Aug 2 19:03:46 2013
@@ -60,6 +60,68 @@ public class UpdateStatisticsTest extend
return statsDisabled;
}
+ //DERBY-5750(Sending an empty string as table name to compress table
+ // procedure or empty string as index name to update statistics procedure
+ // makes the parser throw an exception.)
+ //
+ //No table name will result in exception since Derby doesn't know table
+ // whose statistics it needs to be update
+ public void testStatisticsProcsWithEmptyParamsDerby5750() throws SQLException {
+ Statement s = createStatement();
+ s.execute("create table DERBY5750_t1 (c11 int)");
+ s.executeUpdate("CREATE INDEX DERBY5750_I1 ON DERBY5750_t1(c11)");
+ //Following statements will give exceptions since there is no schema
+ // named empty string
+ assertStatementError(
+ "42Y07", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'','DERBY5750_T1','DERBY5750_I1')");
+ assertStatementError(
+ "42Y07", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'','','DERBY5750_I1')");
+
+ //null schema name will translate to current schema
+ s.execute("call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "null,'DERBY5750_T1','DERBY5750_I1')");
+
+ //Following statements will give exceptions since there is no table
+ // named empty string
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "null,'','DERBY5750_I1')");
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'APP','','DERBY5750_I1')");
+
+ //Following statements will give exceptions since table name can't
+ // be null
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "null,null,'DERBY5750_I1')");
+ assertStatementError(
+ "42X05", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'APP',null,'DERBY5750_I1')");
+
+ //Provide all the 3 params, schema, table and index name
+ s.execute("call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'APP','DERBY5750_T1','DERBY5750_I1')");
+
+
+ //Following statements will give exceptions since there is no index
+ // named empty string
+ assertStatementError(
+ "42X65", s,
+ "call syscs_util.SYSCS_UPDATE_STATISTICS("+
+ "'APP','DERBY5750_T1','')");
+
+ s.execute("drop table DERBY5750_t1");
+ }
+
/**
* Test for update statistics
*/