Skip to content

Commit

Permalink
0004362: SQL Server 2000 gets Invalid object name 'sys.triggers'
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Apr 27, 2020
1 parent 7db65c5 commit afc39ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
@@ -1,6 +1,13 @@
package org.jumpmind.symmetric.db.mssql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.IConnectionCallback;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.service.IParameterService;

Expand All @@ -19,4 +26,32 @@ protected String getDbSpecificDataHasChangedCondition(Trigger trigger) {
/* gets filled/replaced by trigger template as it will compare by each column */
return "$(anyColumnChanged)";
}

@Override
public boolean doesDdlTriggerExist(final String catalogName, final String schema, final String triggerName) {
return ((JdbcSqlTemplate) platform.getSqlTemplate()).execute(new IConnectionCallback<Boolean>() {
public Boolean execute(Connection con) throws SQLException {
String previousCatalog = con.getCatalog();
PreparedStatement stmt = con.prepareStatement("select count(*) from sys.triggers where name = ?");
try {
if (catalogName != null) {
con.setCatalog(catalogName);
}
stmt.setString(1, triggerName);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
int count = rs.getInt(1);
return count > 0;
}
} finally {
if (catalogName != null) {
con.setCatalog(previousCatalog);
}
stmt.close();
}
return Boolean.FALSE;
}
});
}

}
Expand Up @@ -374,35 +374,6 @@ public Boolean execute(Connection con) throws SQLException {
});
}

@Override
public boolean doesDdlTriggerExist(final String catalogName, final String schema, final String triggerName) {
return ((JdbcSqlTemplate) platform.getSqlTemplate())
.execute(new IConnectionCallback<Boolean>() {
public Boolean execute(Connection con) throws SQLException {
String previousCatalog = con.getCatalog();
PreparedStatement stmt = con
.prepareStatement("select count(*) from sys.triggers where name = ?");
try {
if (catalogName != null) {
con.setCatalog(catalogName);
}
stmt.setString(1, triggerName);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
int count = rs.getInt(1);
return count > 0;
}
} finally {
if (catalogName != null) {
con.setCatalog(previousCatalog);
}
stmt.close();
}
return Boolean.FALSE;
}
});
}

@Override
public void removeDdlTrigger(StringBuilder sqlBuffer, String catalogName, String schemaName, String triggerName) {
String sql = "drop trigger " + triggerName + " on database";
Expand Down

0 comments on commit afc39ae

Please sign in to comment.