Beispiel #1
0
 /**
  * Compare two values with the current comparison mode. The values may be of different type.
  *
  * @param a the first value
  * @param b the second value
  * @return 0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
  */
 public int compareTypeSave(Value a, Value b) {
   if (a == b) {
     return 0;
   }
   int dataType = Value.getHigherOrder(a.getType(), b.getType());
   a = a.convertTo(dataType);
   b = b.convertTo(dataType);
   return a.compareTypeSave(b, compareMode);
 }
Beispiel #2
0
 private ValueResultSet getTable(
     Session session, Expression[] argList, boolean onlyColumnList, boolean distinctRows) {
   int len = columnList.length;
   Expression[] header = new Expression[len];
   Database db = session.getDatabase();
   for (int i = 0; i < len; i++) {
     Column c = columnList[i];
     ExpressionColumn col = new ExpressionColumn(db, c);
     header[i] = col;
   }
   LocalResult result = new LocalResult(session, header, len);
   if (distinctRows) {
     result.setDistinct();
   }
   if (!onlyColumnList) {
     Value[][] list = new Value[len][];
     int rows = 0;
     for (int i = 0; i < len; i++) {
       Value v = argList[i].getValue(session);
       if (v == ValueNull.INSTANCE) {
         list[i] = new Value[0];
       } else {
         ValueArray array = (ValueArray) v.convertTo(Value.ARRAY);
         Value[] l = array.getList();
         list[i] = l;
         rows = Math.max(rows, l.length);
       }
     }
     for (int row = 0; row < rows; row++) {
       Value[] r = new Value[len];
       for (int j = 0; j < len; j++) {
         Value[] l = list[j];
         Value v;
         if (l.length <= row) {
           v = ValueNull.INSTANCE;
         } else {
           Column c = columnList[j];
           v = l[row];
           v = c.convert(v);
           v = v.convertPrecision(c.getPrecision(), false);
           v = v.convertScale(true, c.getScale());
         }
         r[j] = v;
       }
       result.addRow(r);
     }
   }
   result.done();
   ValueResultSet vr = ValueResultSet.get(getSimpleResultSet(result, Integer.MAX_VALUE));
   return vr;
 }