Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've found the answer, it was in the <a href="http://search.cpan.org/~adrianwit/Test-DBUnit-0.20/lib/Test/DBUnit.pm#Working_with_sequences">Official Documentation</a>. It was as easy as in the dataset you are using to prepare the database, add a <strong>reset_sequences</strong> attribute with a list of the ones you want to reset.</p> <pre><code> &lt;?xml version='1.0' encoding='UTF-8'?&gt; &lt;dataset reset_sequences="emp_seq, dept_seq"&gt; &lt;emp empno="1" ename="Scott" deptno="10" job="project manager" /&gt; .... &lt;/dataset&gt; </code></pre> <p>This solution is not working perfectly, as it didn't really reset the sequence, only simulates the reset on the inserted rows. If you want to effectively reset it, you should execute some commands. I've extended the DatabaseOperation for that purpose with this class.</p> <pre><code>public static final DatabaseOperation SEQUENCE_RESETTER_POSTGRES = new DatabaseOperation() { @Override public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException { String[] tables = dataSet.getTableNames(); Statement statement = connection.getConnection().createStatement(); for (String table : tables) { int startWith = dataSet.getTable(table).getRowCount() + 1; statement.execute("alter sequence " + table + "_PK_SEQ RESTART WITH "+ startWith); } } }; public static final DatabaseOperation SEQUENCE_RESETTER_ORACLE = new DatabaseOperation() { @Override public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException { String[] tables = dataSet.getTableNames(); Statement statement = connection.getConnection().createStatement(); for (String table : tables) { int startWith = dataSet.getTable(table).getRowCount() + 1; statement.execute("drop sequence " + table + "_PK_SEQ if exists"); statement.execute("create sequence " + table + "_PK_SEQ START WITH " + startWith); } } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload