Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fractional seconds with MySql #20

Open
archmage74 opened this issue Apr 25, 2013 · 0 comments
Open

fractional seconds with MySql #20

archmage74 opened this issue Apr 25, 2013 · 0 comments

Comments

@archmage74
Copy link

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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant