String sql = createTestDatabase(TABLE_CONSTRAINT_TEST_SCHEMA);
// Since we have no way of knowing the auto-generated variables in the SQL,
// we simply try to extract it from the SQL
Pattern declarePattern = new Perl5Compiler().compile("DECLARE @([\\S]+) [^@]+@([\\S]+)");
PatternMatcherInput input = new PatternMatcherInput(sql);
PatternMatcher matcher = new Perl5Matcher();
String[] tableNameVars = { "tablename", "tablename", "tablename" };
String[] constraintNameVars = { "constraintname", "constraintname", "constraintname" };
for (int idx = 0; (idx < 3) && matcher.contains(input, declarePattern); idx++)
{
MatchResult result = matcher.getMatch();
tableNameVars[idx] = result.group(1);
constraintNameVars[idx] = result.group(2);
input.setCurrentOffset(result.endOffset(2));
}
assertEqualsIgnoringWhitespaces(
"SET quoted_identifier on;\n"+
"IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'F' AND name = 'testfk')\n"+
" ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+