use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class PostgreSqlDatabasePlatform method getCreateSymTriggerPermission.
@Override
public PermissionResult getCreateSymTriggerPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";
String triggerSql = "CREATE OR REPLACE FUNCTION TEST_TRIGGER() RETURNS trigger AS $$ BEGIN END $$ LANGUAGE plpgsql";
PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
try {
getSqlTemplate().update(triggerSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant CREATE TRIGGER permission and/or DROP TRIGGER permission");
}
return result;
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class DbExportImportTest method importUniqueKeywordTable.
@Test
public void importUniqueKeywordTable() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
DbImport dbImport = new DbImport(engine.getDatabasePlatform());
dbImport.setFormat(DbImport.Format.XML);
dbImport.setDropIfExists(true);
dbImport.setAlterCaseToMatchDatabaseDefaultCase(true);
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
Database testTables = platform.readDatabaseFromXml("/test-dbimport-unique.xml", true);
Table table = testTables.findTable("test_db_import_unique", false);
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
Assert.assertEquals(table.getColumnWithName("string_required_value").isUnique(), true);
DbImport importCsv = new DbImport(engine.getDatabasePlatform());
importCsv.setFormat(DbImport.Format.SQL);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-good.sql"));
Assert.assertEquals(5, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
try {
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.fail("Expected a sql exception");
} catch (SqlException ex) {
}
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
importCsv.setCommitRate(1);
importCsv.setForceImport(true);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.assertEquals(4, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class DbFill method insertRandomRecord.
/**
* Select a random row from the table and update all columns except for primary and foreign keys.
*
* @param sqlTemplate
* @param table
*/
private void insertRandomRecord(ISqlTransaction tran, Table table) {
DmlStatement insertStatement = createInsertDmlStatement(table);
Row row = createRandomInsertValues(insertStatement, table);
try {
tran.prepareAndExecute(insertStatement.getSql(), insertStatement.getValueArray(row.toArray(table.getColumnNames()), row.toArray(table.getPrimaryKeyColumnNames())));
} catch (SqlException ex) {
log.info("Failed to insert into {}: {}", table.getName(), ex.getMessage());
if (continueOnError) {
if (debug) {
logRow(row);
log.info("", ex);
}
selectRandomRecord(tran, table);
} else {
throw ex;
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class DbFill method deleteRandomRecord.
/**
* Delete a random row in the given table or delete all rows matching selectColumns
* in the given table.
*
* @param table Table to delete from.
* @param selectColumns If provided, the rows that match this criteria are deleted.
*/
private void deleteRandomRecord(ISqlTransaction tran, Table table) {
DmlStatement deleteStatement = createDeleteDmlStatement(table);
Row row = selectRandomRow(tran, table);
try {
tran.prepareAndExecute(deleteStatement.getSql(), row.toArray(table.getPrimaryKeyColumnNames()));
} catch (SqlException ex) {
log.info("Failed to delete from {}: {}", table.getName(), ex.getMessage());
if (continueOnError) {
if (debug) {
logRow(row);
log.info("", ex);
}
} else {
throw ex;
}
}
}
use of org.jumpmind.db.sql.SqlException in project symmetric-ds by JumpMind.
the class SqliteDatabasePlatform method getCreateSymTriggerPermission.
@Override
protected PermissionResult getCreateSymTriggerPermission() {
String delimiter = getDatabaseInfo().getDelimiterToken();
delimiter = delimiter != null ? delimiter : "";
String triggerSql = "CREATE TRIGGER TEST_TRIGGER AFTER UPDATE ON " + delimiter + PERMISSION_TEST_TABLE_NAME + delimiter + "FOR EACH ROW BEGIN SELECT 1; END";
PermissionResult result = new PermissionResult(PermissionType.CREATE_TRIGGER, Status.FAIL);
try {
getSqlTemplate().update(triggerSql);
result.setStatus(Status.PASS);
} catch (SqlException e) {
result.setException(e);
result.setSolution("Grant CREATE TRIGGER permission or TRIGGER permission");
}
return result;
}
Aggregations