/**
   * converts a date to an byte-array with the the length of 8.
   *
   * @return a byte[] containing the date in the format "yyyyMMdd"
   */
  public Object convertDateToNative(tsColumn coldef, Date d) throws tinySQLException {
    try {
      GregorianCalendar cal = new GregorianCalendar();
      cal.clear();

      cal.setTime(d);
      int year = cal.get(cal.YEAR);
      int mon = cal.get(cal.MONTH);
      int day = cal.get(cal.DAY_OF_MONTH);
      Log.debug("Converting. DATE: " + d);
      StringBuffer b = new StringBuffer(10);
      b.append(Utils.forceToSizeLeft(String.valueOf(year), 4, '0'));
      b.append('-');
      b.append(Utils.forceToSizeLeft(String.valueOf(mon), 2, '0'));
      b.append('-');
      b.append(Utils.forceToSizeLeft(String.valueOf(day), 2, '0'));
      System.out.println("Quoting: " + quoting);
      return quoting.doQuoting(b.toString(), coldef.getSize()).getBytes(encoding);
    } catch (UnsupportedEncodingException e) {
      throw new tinySQLException("Encoding not supported");
    }
  }
  /**
   * Converts a native value into a JDBC value. The type of cnversion is detected by looking at the
   * columndefinition. If the type of the is unknown to the conversion system, the value is returned
   * unchanged.
   *
   * @returns the converted value or null
   */
  public Object convertNativeToJDBC(tsColumn coldef, Object o) throws tinySQLException {
    int type = coldef.getType();
    if (o == null) {
      return convertNativeToNull(coldef);
    }

    try {

      switch (type) {
        case Types.BIT:
          return convertNativeToBoolean(coldef, o);

        case Types.TINYINT:
          return convertNativeToByte(coldef, o);

        case Types.SMALLINT:
          return convertNativeToShort(coldef, o);

        case Types.INTEGER:
          return convertNativeToInteger(coldef, o);

        case Types.BIGINT:
          return convertNativeToBigInteger(coldef, o);

        case Types.FLOAT:
          return convertNativeToFloat(coldef, o);

        case Types.REAL:
          return convertNativeToDouble(coldef, o);

        case Types.DOUBLE:
          return convertNativeToDouble(coldef, o);

        case Types.NUMERIC:
          return convertNativeToNumber(coldef, o);

        case Types.DECIMAL:
          return convertNativeToNumber(coldef, o);

        case Types.CHAR:
          return convertNativeToString(coldef, o);

        case Types.VARCHAR:
          return convertNativeToString(coldef, o);

        case Types.LONGVARCHAR:
          return convertNativeToString(coldef, o);

        case Types.DATE:
          return convertNativeToDate(coldef, o);

        case Types.TIME:
          return convertNativeToTime(coldef, o);

        case Types.TIMESTAMP:
          return convertNativeToTimestamp(coldef, o);

          // if we don't know how to handle a object, return it unchanged
        default:
          Log.warn("Unknown type, returning object unchanged.");

          return o;
      }
    } catch (Exception e) {
      Log.error("Convert Failed for column " + coldef, e);
    }
    return o;
  }