Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHOENIX-6574 Executing "DROP TABLE" drops all sequences #1334

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -1466,6 +1467,27 @@ public void testNoFromClause() throws Exception {
assertEquals(5, rs.getInt(2));
}

@Test
public void testBug6574() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();

try(Statement stmt = conn.createStatement()) {
stmt.execute("CREATE SEQUENCE " + sequenceName);
stmt.execute("CREATE TABLE " + tableName + " (id integer primary key)");

String query = "SELECT * FROM SYSTEM.\"SEQUENCE\" where SEQUENCE_NAME = '" + getNameWithoutSchema(sequenceName) + "'";
ResultSet rs = stmt.executeQuery(query);
assertTrue(rs.next());
rs.close();

stmt.execute("DROP TABLE " + tableName);
rs = stmt.executeQuery(query);
assertTrue(rs.next());
rs.close();
}
}

private static String getSchemaName(String tableName) {
return tableName.substring(0, tableName.indexOf("."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ public static void deleteViewIndexSequences(PhoenixConnection connection, PName
throws SQLException {
String schemaName = getViewIndexSequenceSchemaName(name, isNamespaceMapped);
String sequenceName = getViewIndexSequenceName(name, null, isNamespaceMapped);
connection.createStatement().executeUpdate("DELETE FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " WHERE "
+ PhoenixDatabaseMetaData.SEQUENCE_SCHEMA
+ (schemaName.length() > 0 ? "='" + schemaName + "'" : " IS NULL") + (isNamespaceMapped
? " AND " + PhoenixDatabaseMetaData.SEQUENCE_NAME + " = '" + sequenceName + "'" : ""));

connection.createStatement().executeUpdate("DELETE FROM "
+ PhoenixDatabaseMetaData.SYSTEM_SEQUENCE
+ " WHERE " + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA
+ (schemaName.length() > 0 ? "='" + schemaName + "'" : " IS NULL")
+ " AND " + PhoenixDatabaseMetaData.SEQUENCE_NAME + " = '" + sequenceName + "'" );
}

/**
Expand Down