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

Optimise the logic for tableIsEmpty check constraint #4834

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding support for more databases.
  • Loading branch information
filipelautert committed Sep 13, 2023
commit 47acb9f6538124e3cfba51104dfb63b7be999016
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package liquibase.sqlgenerator.core;

import liquibase.database.Database;
import liquibase.database.core.HsqlDatabase;
import liquibase.database.core.OracleDatabase;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
Expand All @@ -27,7 +29,13 @@ public ValidationErrors validate(TableIsEmptyStatement tableIsEmptyStatement, Da
}

protected String generateCountSql(TableIsEmptyStatement statement, Database database) {
return String.format("SELECT COUNT(1) WHERE EXISTS (SELECT * FROM %s)", database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()));
String tableName = database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName());
if (database instanceof HsqlDatabase) {
return String.format("SELECT COUNT(1) FROM (VALUES(0)) WHERE EXISTS (SELECT * FROM %s)", tableName);
} else if (database instanceof OracleDatabase) {
return String.format("SELECT COUNT(1) FROM DUAL WHERE EXISTS (SELECT * FROM %s)", tableName);
}
return String.format("SELECT COUNT(1) WHERE EXISTS (SELECT * FROM %s)", tableName);
}


Expand Down