Program: 150513
Project: 150513
Buggy source:
@Override protected final int execute(ExecuteContext ctx,ExecuteListener listener) throws SQLException {
  if (returning.isEmpty()) {
    return super.execute(ctx,listener);
  }
 else {
    int result=1;
    ResultSet rs;
switch (ctx.getDialect()) {
case SQLITE:
{
        listener.executeStart(ctx);
        result=ctx.statement().executeUpdate();
        listener.executeEnd(ctx);
        SQLiteFactory create=new SQLiteFactory(ctx.getConnection(),ctx.getSettings());
        returned=create.select(returning).from(getInto()).where(rowid().equal(rowid().getDataType().convert(create.lastID()))).fetchInto(getInto());
        return result;
      }
case SYBASE:
{
      listener.executeStart(ctx);
      result=ctx.statement().executeUpdate();
      listener.executeEnd(ctx);
      selectReturning(ctx.configuration(),create(ctx).lastID());
      return result;
    }
case ASE:
case CUBRID:
case DERBY:
case H2:
case INGRES:
case MYSQL:
case SQLSERVER:
{
    listener.executeStart(ctx);
    result=ctx.statement().executeUpdate();
    listener.executeEnd(ctx);
    rs=ctx.statement().getGeneratedKeys();
    try {
      List<Object> list=new ArrayList<Object>();
      while (rs.next()) {
        list.add(rs.getObject(1));
      }
      selectReturning(ctx,list.toArray());
      return result;
    }
  finally {
      rs.close();
    }
  }
case POSTGRES:
{
  listener.executeStart(ctx);
  rs=ctx.statement().executeQuery();
  listener.executeEnd(ctx);
  break;
}
case DB2:
case HSQLDB:
case ORACLE:
default :
{
listener.executeStart(ctx);
result=ctx.statement().executeUpdate();
listener.executeEnd(ctx);
rs=ctx.statement().getGeneratedKeys();
break;
}
}
ExecuteContext ctx2=new DefaultExecuteContext(ctx.configuration());
ExecuteListener listener2=new ExecuteListeners(ctx2);
ctx2.resultSet(rs);
returned=new CursorImpl<R>(ctx2,listener2,returning,getInto().getRecordType()).fetch();
return result;
}
}

Fixed version (ground truth):
@Override protected final int execute(ExecuteContext ctx,ExecuteListener listener) throws SQLException {
  if (returning.isEmpty()) {
    return super.execute(ctx,listener);
  }
 else {
    int result=1;
    ResultSet rs;
switch (ctx.getDialect()) {
case SQLITE:
{
        listener.executeStart(ctx);
        result=ctx.statement().executeUpdate();
        listener.executeEnd(ctx);
        SQLiteFactory create=new SQLiteFactory(ctx.getConnection(),ctx.getSettings());
        returned=create.select(returning).from(getInto()).where(rowid().equal(rowid().getDataType().convert(create.lastID()))).fetchInto(getInto());
        return result;
      }
case CUBRID:
case SYBASE:
{
      listener.executeStart(ctx);
      result=ctx.statement().executeUpdate();
      listener.executeEnd(ctx);
      selectReturning(ctx.configuration(),create(ctx).lastID());
      return result;
    }
case ASE:
case DERBY:
case H2:
case INGRES:
case MYSQL:
case SQLSERVER:
{
    listener.executeStart(ctx);
    result=ctx.statement().executeUpdate();
    listener.executeEnd(ctx);
    rs=ctx.statement().getGeneratedKeys();
    try {
      List<Object> list=new ArrayList<Object>();
      while (rs.next()) {
        list.add(rs.getObject(1));
      }
      selectReturning(ctx,list.toArray());
      return result;
    }
  finally {
      rs.close();
    }
  }
case POSTGRES:
{
  listener.executeStart(ctx);
  rs=ctx.statement().executeQuery();
  listener.executeEnd(ctx);
  break;
}
case DB2:
case HSQLDB:
case ORACLE:
default :
{
listener.executeStart(ctx);
result=ctx.statement().executeUpdate();
listener.executeEnd(ctx);
rs=ctx.statement().getGeneratedKeys();
break;
}
}
ExecuteContext ctx2=new DefaultExecuteContext(ctx.configuration());
ExecuteListener listener2=new ExecuteListeners(ctx2);
ctx2.resultSet(rs);
returned=new CursorImpl<R>(ctx2,listener2,returning,getInto().getRecordType()).fetch();
return result;
}
}