/** * * Given a tsColumn object, returns its value as a String. * * @param column the tsColumn object * */ public String columnAsString(TsColumn column) { String outputString, valueString, functionName, argList, nextArg; java.lang.StringBuffer functionBuffer; FieldTokenizer ft1, ft2; /* * Next try to retrieve as a group function, which will not have a * tablename prefix. */ outputString = (String)get(column.name); if (outputString != (String)null) { return(outputString); } ft1 = new FieldTokenizer(column.name, '(', false); if (ft1.countFields() == 2) { /* * The column is a function. If it is a group function, the value * will be stored in the record. Otherwise, the function value * will be determined here by retrieving and processing all the * columns in the function arguments. */ outputString = (String)get(column.name); if (outputString != (String)null) { return(outputString); } functionName = ft1.getField(0); argList = ft1.getField(1); ft2 = new FieldTokenizer(argList, ',', false); functionBuffer = new java.lang.StringBuffer(); /* * Function arguments must consist of table.column names or constants. */ while (ft2.hasMoreFields()) { nextArg = ft2.nextField(); valueString = (String)get(nextArg); if (debug) { java.lang.SystemJ.outJ.println("Function " + functionName + " argument " + nextArg + " has value " + valueString); } /* * If the valueString is null then it is a constant rather than * a database column. Remove enclosing quotes. */ if (valueString == (String)null) { valueString = UtilString.removeQuotes(nextArg); } else { valueString = valueString.trim(); } if (functionName.equals("CONCAT")) { functionBuffer.append(valueString); } } outputString = functionBuffer.toString(); } else if (column.tableName == (String)null) { /* * This is a constant. Return the table name which will be equal to * the constant value. */ outputString = UtilString.removeQuotes(column.name); } else { /* * Retrieve as a simple database column. */ outputString = (String)get(column.tableName + "." + column.name); if (Utils.isDateColumn(column.type)) { /* * Format dates as DD-MON-YY for output. Note that the value * stored in the database may already be in this format because * of incorrect storage of date strings prior to version 2.3. */ try { outputString = UtilString.toStandardDate(outputString); } catch (Exception dateEx) { java.lang.SystemJ.outJ.println(dateEx.getMessage()); } } } return(outputString); }
public int compareTo(Object inputObj) //throws tinySQLException { String thisYMD, inputYMD; TsColumn inputColumn; int inputType, returnValue; double thisValue, inputValue; inputColumn = (TsColumn)inputObj; inputType = inputColumn.type; thisValue = java.lang.Double.MIN_VALUE; inputValue = java.lang.Double.MIN_VALUE; returnValue = 0; if (Utils.isCharColumn(type)) { /* * Compare character java.sql.Types. */ if (!Utils.isCharColumn(inputType)) { throw new TinySQLException("Type mismatch between " + getString() + " and " + inputColumn.getString()); } else if (stringValue == (String)null | inputColumn.stringValue == (String)null) { throw new TinySQLException("One of the values is NULL"); } else { returnValue = stringValue.compareTo(inputColumn.stringValue); } } else if (Utils.isDateColumn(type)) { /* * Compare date java.sql.Types. */ if (!Utils.isDateColumn(inputType)) { throw new TinySQLException("Type mismatch between " + getString() + " and " + inputColumn.getString()); } else if (stringValue == (String)null | inputColumn.stringValue == (String)null) { throw new TinySQLException("One of the values is NULL"); } else { inputYMD = UtilString.toStandardDate(inputColumn.stringValue); thisYMD = UtilString.toStandardDate(stringValue); returnValue = thisYMD.compareTo(inputYMD); } } else if (Utils.isNumberColumn(type)) { if (type == java.sql.Types.INTEGER) { thisValue = (double)intValue; } else if (type == java.sql.Types.FLOAT) { thisValue = (double)floatValue; } if (inputType == java.sql.Types.INTEGER) { inputValue = (double)inputColumn.intValue; } else if (inputType == java.sql.Types.FLOAT) { inputValue = (double)inputColumn.floatValue; } if (thisValue > inputValue) { returnValue = 1; } else if (thisValue < inputValue) { returnValue = -1; } } else { java.lang.SystemJ.outJ.println("Cannot sort unknown type"); } if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Comparing " + getString() + " to " + inputColumn.getString() + " gave " + returnValue); } return(returnValue); }