[go: nahoru, domu]

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

Allow loggers/debuggers to analyze Postgres statements #590

Open
Chrriis opened this issue Jun 22, 2016 · 2 comments
Open

Allow loggers/debuggers to analyze Postgres statements #590

Chrriis opened this issue Jun 22, 2016 · 2 comments

Comments

@Chrriis
Copy link
Contributor
Chrriis commented Jun 22, 2016

When debugging, it is important to easily understand the queries we are dealing with. When needed, getting at their parameters should also be relatively easy.
Similarly, custom loggers should be able to get such basic information without too much hassle.

Currently, it is quite hard to get that information from pgjdbc because it involves a lot of reflection, breaks at every upgrade of the library, and getting certain fields is definitely not easy.

Thus, I suggest the following:

  • PgPreparedStatement should be public so we can easily cast a PreparedStatement.
  • The default toString() of PgPreparedStatement and PgCallableStatement should be the raw SQL statement that was used to construct the statement (meaning with '?' for bind parameters).
  • Before any addBatch(), possibility to get all parameters. This should be done with methods like getParameterCount(), getSqlParameterTypes(), getPgParameterTypes(), getParameterValues() (using null or "?" if not bound, Sql Parameter Type allowing to differentiate).

A bit of background: all our stack goes through methods for statements to execute, add batch, execute batch. We can activate logging and get a lot of information (stacktrace of every call, time to execute, etc.) and with Postgres we are blind: it is not easy to get basic information about the statements. Moreover, when we debug in our IDE we get similar issues.

@vlsi
Copy link
Member
vlsi commented Jun 22, 2016

PgPreparedStatement should be public so we can easily cast a PreparedStatement

There's org.postgresql.PGStatement interface for public API

@Chrriis
Copy link
Contributor Author
Chrriis commented Jun 23, 2016

There's org.postgresql.PGStatement interface for public API

So, toString() should be defined in this class, with Javadoc specifying what it produces.
I guess we should create org.postgresql.PGPreparedStatement for type-related methods, don't you think?
We would also need org.postgresql.PGCallableStatement, but should it inherit org.postgresql.PGPreparedStatement or just replicate the type-related method definitions?

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