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

Inconsistent Timestamp conversion #412

Closed
fbiville opened this issue Feb 21, 2023 · 2 comments
Closed

Inconsistent Timestamp conversion #412

fbiville opened this issue Feb 21, 2023 · 2 comments

Comments

@fbiville
Copy link

fbiville commented Feb 21, 2023

Here is a simple program running with the 5.0 JDBC connector for Bolt (affects 4.x versions as well):

     public static void main(String[] args) throws SQLException {
        BoltDriver boltDriver = new BoltDriver();
        Properties props = new Properties();
        props.setProperty("username", "neo4j");
        props.setProperty("password", "<redacted>");
        String query = "WITH datetime('2015-06-24T12:50:35.556+0100') AS zonedDateTime " +
                "RETURN zonedDateTime, " +
                "       [zonedDateTime] AS zonedDateTimeList, " +
                "       {zonedDateTime: zonedDateTime} AS zonedDateTimeDictionary";
        try (Connection connection = boltDriver.connect("jdbc:neo4j:bolt://localhost", props);
             ResultSet results = connection.createStatement().executeQuery(query)) {

            while (results.next()) {
                Object theDateTime = results.getObject("zonedDateTime");
                System.out.println(theDateTime.getClass());
                theDateTime = ((Iterable<Object>)results.getObject("zonedDateTimeList")).iterator().next();
                System.out.println(theDateTime.getClass());
                theDateTime = ((Map<String, Object>)results.getObject("zonedDateTimeDictionary")).get("zonedDateTime");
                System.out.println(theDateTime.getClass());
            }

        }
    }

Expected behavior

I'd expect the program to print:

class java.sql.Timestamp
class java.sql.Timestamp
class java.sql.Timestamp

Actual behavior

class java.sql.Timestamp
class java.sql.Timestamp
class java.time.ZonedDateTime

This affects maps as well as node/relationship properties.

Fixing this is unfortunately a breaking change.

@michael-simons
Copy link
Collaborator

Next version will do

class java.time.ZonedDateTime
class java.time.ZonedDateTime
class java.time.ZonedDateTime

which I think is correct, when using results.getObject as baseline.
We decided going down the java.sql.Time|Date|Timestamp mess only when explicitly asked for.

@michael-simons
Copy link
Collaborator

Test is here

void mappingOfTimestampsMustBeConsistent() throws SQLException {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants