예제 #1
0
 public Result delete(Table table, String condition) throws SQLException {
   String sql = "DELETE FROM " + table.getName();
   if (condition != null) {
     sql += "  WHERE " + condition;
   }
   log(sql + ";");
   Statement stat = conn.createStatement();
   Result result = new Result(sql, stat.executeUpdate(sql));
   return result;
 }
예제 #2
0
  /**
   * Create a new random table.
   *
   * @param config the configuration
   * @return the table
   */
  static Table newRandomTable(TestSynth config) {
    Table table = new Table(config);
    table.name = "T_" + config.randomIdentifier();

    // there is a difference between local temp tables for persistent and
    // in-memory mode
    // table.temporary = config.random().getBoolean(10);
    // if(table.temporary) {
    // if(config.getMode() == TestSynth.H2_MEM) {
    // table.globalTemporary = false;
    // } else {
    // table.globalTemporary = config.random().getBoolean(50);
    // }
    // }

    int len = config.random().getLog(10) + 1;
    table.columns = new Column[len];
    for (int i = 0; i < len; i++) {
      Column col = Column.getRandomColumn(config);
      table.columns[i] = col;
    }
    if (config.random().getBoolean(90)) {
      int pkLen = config.random().getLog(len);
      table.primaryKeys = new Column[pkLen];
      for (int i = 0; i < pkLen; i++) {
        Column pk = null;
        do {
          pk = table.columns[config.random().getInt(len)];
        } while (pk.getPrimaryKey());
        table.primaryKeys[i] = pk;
        pk.setPrimaryKey(true);
        pk.setNullable(false);
      }
    }
    return table;
  }
예제 #3
0
 public Result update(Table table, Column[] columns, Value[] values, String condition)
     throws SQLException {
   String sql = "UPDATE " + table.getName() + " SET ";
   for (int i = 0; i < columns.length; i++) {
     if (i > 0) {
       sql += ", ";
     }
     sql += columns[i].getName() + "=" + values[i].getSQL();
   }
   if (condition != null) {
     sql += "  WHERE " + condition;
   }
   log(sql + ";");
   Statement stat = conn.createStatement();
   Result result = new Result(sql, stat.executeUpdate(sql));
   return result;
 }
예제 #4
0
 public Result insert(Table table, Column[] c, Value[] v) throws SQLException {
   String sql = table.getInsertSQL(c, v);
   execute(sql);
   return new Result(sql, 1);
 }
예제 #5
0
 public void dropTable(Table table) throws SQLException {
   execute(table.getDropSQL());
 }
예제 #6
0
 public void createTable(Table table) throws SQLException {
   execute(table.getCreateSQL());
 }