Skip to content

Commit

Permalink
0002050: dropping a table before dropping trigger causes NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Nov 4, 2014
1 parent 03bf253 commit eb87d81
Showing 1 changed file with 28 additions and 21 deletions.
Expand Up @@ -161,28 +161,35 @@ protected boolean doesTriggerExistOnPlatform(String catalogName, String schema,
}

@Override
public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String schemaName, String triggerName,
String tableName) {
public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String schemaName,
String triggerName, String tableName) {
Table table = platform.getTableFromCache(catalogName, schemaName, tableName, false);
String quoteChar = platform.getDatabaseInfo().getDelimiterToken();
schemaName = table.getSchema() == null ? "" : (quoteChar + table.getSchema() + quoteChar + ".");
final String dropSql = "drop trigger " + triggerName + " on " + schemaName + quoteChar + table.getName() + quoteChar;
logSql(dropSql, sqlBuffer);
final String dropFunction = "drop function " + schemaName + "f" + triggerName + "() cascade";
logSql(dropFunction, sqlBuffer);
if (parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
String sql = null;
try {
sql = dropSql;
platform.getSqlTemplate().update(dropSql);
} catch (Exception e) {
log.warn("Tried to remove trigger using: {} and failed because: {}", sql, e.getMessage());
}
try {
sql = dropFunction;
platform.getSqlTemplate().update(dropFunction);
} catch (Exception e) {
log.warn("Tried to remove function using: {} and failed because: {}", sql, e.getMessage());
if (table != null) {
String quoteChar = platform.getDatabaseInfo().getDelimiterToken();
schemaName = table.getSchema() == null ? "" : (quoteChar + table.getSchema()
+ quoteChar + ".");
final String dropSql = "drop trigger " + triggerName + " on " + schemaName + quoteChar
+ table.getName() + quoteChar;
logSql(dropSql, sqlBuffer);
final String dropFunction = "drop function " + schemaName + "f" + triggerName
+ "() cascade";
logSql(dropFunction, sqlBuffer);
if (parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
String sql = null;
try {
sql = dropSql;
platform.getSqlTemplate().update(dropSql);
} catch (Exception e) {
log.warn("Tried to remove trigger using: {} and failed because: {}", sql,
e.getMessage());
}
try {
sql = dropFunction;
platform.getSqlTemplate().update(dropFunction);
} catch (Exception e) {
log.warn("Tried to remove function using: {} and failed because: {}", sql,
e.getMessage());
}
}
}
}
Expand Down

0 comments on commit eb87d81

Please sign in to comment.