开发者

DbUnit - Delete rows based on non-primary key field value

开发者 https://www.devze.com 2023-04-01 22:45 出处:网络
It looks like DbUnit is using JDBC metadata to determine the primary key fields and constructing delete statement using th开发者_如何转开发ose field:

It looks like DbUnit is using JDBC metadata to determine the primary key fields and constructing delete statement using th开发者_如何转开发ose 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)


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消