4

It looks like DbUnit is using JDBC metadata to determine the primary key fields and constructing delete statement using those field:

delete from tbl_name where pk_field1=? and pk_field2=? and pk_field3=?

Is there a way to delete rows based on one field value of a composite key or value of a non-primary key field (e.g. delete rows where created_date = xyz)

dsatish
  • 1,041
  • 15
  • 27

1 Answers1

3

You can create a QueryDataSet and set DatabaseOperation to DELETE.

For exemple, if you are extending DBTestCase:

protected IDataSet getDataSet() {
    QueryDataSet queryDataSet = null;
    String query = "SELECT * FROM tbl_name pk_field1=? and pk_field2=?";
    try {
        queryDataSet = new QueryDataSet(super.getConnection());
        queryDataSet.addTable("tbl_name",query);
    } catch (Exception e) {
        e.printStackTrace();            
    }
    return queryDataSet;
}

protected DatabaseOperation getSetUpOperation() throws Exception {
    return DatabaseOperation.DELETE;
}
Guilherme Torres Castro
  • 15,135
  • 7
  • 59
  • 96