コード例 #1
0
ファイル: ScriptCommand.java プロジェクト: a610569731/Lealone
 private int generateInsertValues(int count, Table table) throws IOException {
   PlanItem plan = table.getBestPlanItem(session, null, null);
   Index index = plan.getIndex();
   Cursor cursor = index.find(session, null, null);
   Column[] columns = table.getColumns();
   StatementBuilder buff = new StatementBuilder("INSERT INTO ");
   buff.append(table.getSQL()).append('(');
   for (Column col : columns) {
     buff.appendExceptFirst(", ");
     buff.append(Parser.quoteIdentifier(col.getName()));
   }
   buff.append(") VALUES");
   if (!simple) {
     buff.append('\n');
   }
   buff.append('(');
   String ins = buff.toString();
   buff = null;
   while (cursor.next()) {
     Row row = cursor.get();
     if (buff == null) {
       buff = new StatementBuilder(ins);
     } else {
       buff.append(",\n(");
     }
     for (int j = 0; j < row.getColumnCount(); j++) {
       if (j > 0) {
         buff.append(", ");
       }
       Value v = row.getValue(j);
       if (v.getPrecision() > lobBlockSize) {
         int id;
         if (v.getType() == Value.CLOB) {
           id = writeLobStream(v);
           buff.append("SYSTEM_COMBINE_CLOB(" + id + ")");
         } else if (v.getType() == Value.BLOB) {
           id = writeLobStream(v);
           buff.append("SYSTEM_COMBINE_BLOB(" + id + ")");
         } else {
           buff.append(v.getSQL());
         }
       } else {
         buff.append(v.getSQL());
       }
     }
     buff.append(')');
     count++;
     if ((count & 127) == 0) {
       checkCanceled();
     }
     if (simple || buff.length() > Constants.IO_BUFFER_SIZE) {
       add(buff.toString(), true);
       buff = null;
     }
   }
   if (buff != null) {
     add(buff.toString(), true);
   }
   return count;
 }
コード例 #2
0
ファイル: Merge.java プロジェクト: pologood/Lealone
 public void prepare() {
   if (columns == null) {
     if (list.size() > 0 && list.get(0).length == 0) {
       // special case where table is used as a sequence
       columns = new Column[0];
     } else {
       columns = table.getColumns();
     }
   }
   if (list.size() > 0) {
     for (Expression[] expr : list) {
       if (expr.length != columns.length) {
         throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
       }
       for (int i = 0; i < expr.length; i++) {
         Expression e = expr[i];
         if (e != null) {
           expr[i] = e.optimize(session);
         }
       }
     }
   } else {
     query.prepare();
     if (query.getColumnCount() != columns.length) {
       throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
     }
   }
   if (keys == null) {
     Index idx = table.getPrimaryKey();
     if (idx == null) {
       throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, "PRIMARY KEY");
     }
     keys = idx.getColumns();
   }
   StatementBuilder buff = new StatementBuilder("UPDATE ");
   buff.append(table.getSQL()).append(" SET ");
   for (Column c : columns) {
     buff.appendExceptFirst(", ");
     buff.append(c.getSQL()).append("=?");
   }
   buff.append(" WHERE ");
   buff.resetCount();
   for (Column c : keys) {
     buff.appendExceptFirst(" AND ");
     buff.append(c.getSQL()).append("=?");
   }
   String sql = buff.toString();
   update = session.prepare(sql);
 }