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

ConnectionWrapper.java ability to add casting from datetime2 to datetime #534

Open
Quindlen opened this issue Sep 3, 2021 · 2 comments
Open

Comments

@Quindlen
Copy link

Quindlen commented Sep 3, 2021

My local project, we would like to bring p6spy into production because of a datetime issue. JDBC takes Java timestamp and casts it now to a datetime2 field in SQL Server. So we needed ability to cast it. So, we modified ConnectionWrapper.java to call a new file QueryCastingHelper that checks ParameterMetaData for Parameter datetime and modify the ? to a CAST(? AS DATETIME). It would be nice to have a good jdbc driver like p6spy that we can through the flag into the properties file to do it for us instead of having us with a modified version. So can you please provide either functionality to do this casting automatically or be able to have an extra jar in the module directory that has a class callable to do application casting... We modified 6 places in ConnectionWrapper to call QueryCastingHelper to do cast, and then return.

Thank you.

@gavlyukovskiy
Copy link
Member

Do I understand right that this is effectively a request to manipulate query before sending it to underlying driver (#465)?

@Quindlen
Copy link
Author

We added p6Spy to our production servers. We added a NoLogger appender (which got ticket 535).
But since we also upgraded SQL Servers, what JDBC does is for the new SQL Server, it is defaulting datetime automatically to DATETIME2. The change we made to P6SPY was we created a new class called QueryCastingHelper which modified the query and added casting to all the date fields to cast to DATETIME. This class required us to modify ConnectionWrapper in 6 places to call it.

Other people may have this issue if their SQL tables are DATETIME, and JDBC defaults to DATETIME2. p6spy was able to intercept the call and cast back to datetime. My request was to have an option added to spy.properties to cast from datetime2 to datetime, and you have a class that does it.

The reason why we were unable to fix our java code was that we use ibatis/mybatis to call JDBC, and we have no control of the query it creates to add the casting. so p6 does it for us.
Thank you.
Peter

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

2 participants