Exemplo n.º 1
0
  @Test
  public void testAutoincrement() throws Exception {

    ISqlJetTableDef createTable =
        db.createTable(
            "CREATE TABLE `JOBLIST` ("
                + "`id` INTEGER PRIMARY KEY AUTOINCREMENT,"
                + "`jobname` VARCHAR(75) NOT NULL,"
                + "`startdate` LONG not null"
                + ");");

    final ISqlJetTable table = db.getTable(createTable.getName());
    db.beginTransaction(SqlJetTransactionMode.EXCLUSIVE);
    try {
      table.insert(null, "jobname", 123456);
      table.insert(null, "jobname", 123456);
    } finally {
      db.commit();
    }

    db.runReadTransaction(
        new ISqlJetTransaction() {
          public Object run(SqlJetDb db) throws SqlJetException {
            ISqlJetCursor open = table.open();
            try {
              while (!open.eof()) {
                long id = open.getInteger("id");
                Assert.assertNotNull(id);
                open.next();
              }
            } finally {
              open.close();
            }
            return null;
          }
        });
  }