Skip to content

fractional seconds with MySql #20

@archmage74

Description

@archmage74

drizzle-jdbc drops fractions within timestamps of a MySql database. The tables were created to support fractional seconds.

We changed the listed methods as stated below. It worked for us, but we tested it only against MySQL Server (not Drizzle Server):

org.drizzle.jdbc.internal.common.AbstractValueObject:

public Timestamp getTimestamp() throws ParseException {
    if (rawBytes == null) {
        return null;
    }
    String rawValue = getString();
    SimpleDateFormat sdf;

    if (rawValue.length() > 20) {
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    } else if (rawValue.length() >= 19) {
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    } else {
        sdf = new SimpleDateFormat("yyyy-MM-dd");
    }
    sdf.setLenient(false);
    final java.util.Date utilTime = sdf.parse(rawValue);
    return new Timestamp(utilTime.getTime());
}

org.drizzle.jdbc.internal.common.query.parameters.TimeParameter:

public TimeParameter(final long timestamp) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
    byteRepresentation = ("'" + sdf.format(new Date(timestamp)) + "'").getBytes();
}

org.drizzle.jdbc.internal.common.query.parameters.TimestampParameter:

public TimestampParameter(final long timestamp) {
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    byteRepresentation = String.valueOf("'" + sdf.format(new Date(timestamp)) + "'").getBytes();
}

public TimestampParameter(final long timestamp, final Calendar cal) {
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    sdf.setCalendar(cal);
    byteRepresentation = String.valueOf("'" + sdf.format(new Date(timestamp)) + "'").getBytes();

}

org.drizzle.jdbc.internal.mysql.MySQLValueObject:

@Override
public Time getTime() throws ParseException {
    if (getBytes() == null) {
        return null;
    }
    final String rawValue = getString();
    final SimpleDateFormat sdf;
    if (rawValue.length() > 8) {
        sdf = new SimpleDateFormat("HH:mm:ss.SSS");

    } else {
        sdf = new SimpleDateFormat("HH:mm:ss");
    }
    final java.util.Date utilTime = sdf.parse(rawValue);
    return new Time(utilTime.getTime());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions