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

Ability to handle statement / resultSet getWarnings() #43

Open
jukkasi opened this issue Mar 13, 2019 · 2 comments
Open

Ability to handle statement / resultSet getWarnings() #43

jukkasi opened this issue Mar 13, 2019 · 2 comments

Comments

@jukkasi
Copy link

jukkasi commented Mar 13, 2019

Because we are using MariaDB which sometimes does not behave that nice but only produces warnings when it actually should throw errors, I'm looking for similar feature that (Spring) JdbcTemplate has, which is flag ignoreWarnings = false that throws exceptions if there are warnings in result.

I understand that this can be achieved by using ResultSet.getWarnings() but because we are not currently using ResultSet in any way but only under the hood (= only Dalesbred built-in row mappers), I'm looking for more generic solution.

Also preparedStatement.getWarnings() cannot be used because stmt is well encapsulated inside Database class implementation. Using custom transaction manager I am able to access Connection after commit but calling getWarnings() for Connection is a different case and not sufficient.

Any ideas?

@komu
Copy link
Member

komu commented Mar 13, 2019

Sounds like a good idea. Currently there's no way to customize this, but this is the only place in Dalesbred's code that deals with ResultSets so it should be a matter of implementing it here:

try (ResultSet resultSet = ps.executeQuery()) {
logQueryExecution(query, currentTimeMillis() - startTime);
return processor.process(resultSet);
}

However, I'm torn between a specific high-level flag like ignoreWarnings = false and a more general event-listener that could be registered to Database and would be called every time that query has been executed (among various other events). Something like:

 try (ResultSet resultSet = ps.executeQuery()) { 
     long elapsedMillis = currentTimeMillis() - startTime;
     logQueryExecution(query, elapsedMillis); 
     callback.queryExecuted(query, resultSet, elapsedMillis);
     return processor.process(resultSet); 
} 

I'll have to give some though into this.

@jukkasi
Copy link
Author

jukkasi commented Mar 13, 2019

Yes, some kind of hook / event calback / interceptor mechanism could work and I believe something similar was requested in #23

However I'm not sure if resultSet or preparedStatement should be accessible, or perhaps both.

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