Skip to content

Commit

Permalink
0000021: SQLite - added replacement token parsing to SQLScript for DB…
Browse files Browse the repository at this point in the history
…ExportImport tests and replacement timestamp and date tokens for SQLite.
  • Loading branch information
mhanes committed Dec 10, 2012
1 parent 3c196d8 commit 392af25
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Expand Up @@ -70,7 +70,7 @@ public static IDatabasePlatform dropDatabaseTables(String databaseType, ISymmetr
platform.resetDataSource();

String sql = builder.dropTables(db2drop);
SqlScript dropScript = new SqlScript(sql, platform.getSqlTemplate(), false);
SqlScript dropScript = new SqlScript(sql, platform.getSqlTemplate(), false, platform.getSqlScriptReplacementTokens());
dropScript.execute(true);

platform.resetDataSource();
Expand Down
Expand Up @@ -134,7 +134,7 @@ public long getClearCacheModelTimeoutInMs() {

public void dropDatabase(Database database, boolean continueOnError) {
String sql = ddlBuilder.dropTables(database);
new SqlScript(sql, getSqlTemplate(), !continueOnError).execute(true);
new SqlScript(sql, getSqlTemplate(), !continueOnError, null).execute(true);
}

public void createTables(boolean dropTablesFirst, boolean continueOnError, Table... tables) {
Expand Down
6 changes: 3 additions & 3 deletions symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java
Expand Up @@ -69,10 +69,10 @@ public SqlScript(URL url, ISqlTemplate sqlTemplate, boolean failOnError, String
}
}

public SqlScript(String sqlScript, ISqlTemplate sqlTemplate, boolean failOnError) {
this(sqlScript, sqlTemplate, failOnError, SqlScriptReader.QUERY_ENDS, null);
public SqlScript(String sqlScript, ISqlTemplate sqlTemplate, boolean failOnError,Map<String, String> replacementTokens) {
this(sqlScript, sqlTemplate, failOnError, SqlScriptReader.QUERY_ENDS, replacementTokens);
}

public SqlScript(String sqlScript, ISqlTemplate sqlTemplate, boolean failOnError,
String delimiter, Map<String, String> replacementTokens) {
init(new StringReader(sqlScript), sqlTemplate, failOnError, delimiter, replacementTokens);
Expand Down
Expand Up @@ -22,6 +22,8 @@ public SqliteDatabasePlatform(DataSource dataSource, SqlTemplateSettings setting
super(dataSource, settings);
sqlScriptReplacementTokens = new HashMap<String, String>();
sqlScriptReplacementTokens.put("current_timestamp", "strftime('%Y-%m-%d %H:%M:%f','now','localtime')");
sqlScriptReplacementTokens.put("\\{ts([^<]*?)\\}","$1");
sqlScriptReplacementTokens.put("\\{d([^<]*?)\\}","$1");
}


Expand Down
Expand Up @@ -111,7 +111,7 @@ public void testUpgradePrimaryKeyAutoIncrementFromIntToBigInt() throws Exception

Assert.assertFalse(alterSql, alterSql.toLowerCase().contains("create table"));

new SqlScript(alterSql, platform.getSqlTemplate(), true).execute(true);
new SqlScript(alterSql, platform.getSqlTemplate(), true, platform.getSqlScriptReplacementTokens()).execute(true);

tableFromDatabase = platform.getTableFromCache(table.getName(), true);

Expand Down

0 comments on commit 392af25

Please sign in to comment.