You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Rick Hillegas (JIRA)" <ji...@apache.org> on 2009/09/02 15:52:32 UTC

[jira] Commented: (DERBY-3676) Make the toString() method of Derby PreparedStatements print out SQL text with ? parameters replaced by the values that have been set so far

    [ https://issues.apache.org/jira/browse/DERBY-3676?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12750440#action_12750440 ] 

Rick Hillegas commented on DERBY-3676:
--------------------------------------

Hi Mark,

Thanks for looking at this issue and posting a patch. I think that your code will work in most cases. However, it will do the wrong thing if there is an embedded ? in a literal inside the SQL text or inside a delimited identifier. For instance, it will produce odd output for the following queries:

  select * from T where a like 'Am I blue?%' and b = ?

  select "foo?" from T where b = ?

My gut feeling is that these edge cases are important enough that we should handle them. I think that the problems are handled by Thomas' approach, which Mike coded in his ick.txt patch: just append a bracketed parameter list at the end of the sql text.

The public API issue will need to be addressed too. We don't want to put EmbedPreparedStatement in the public API. Maybe we could add a new interface to the public API: org.apache.derby.jdbc.DerbyPreparedStatement. Then, regardless of whether you are working with an embedded or network connection, the following code would work:

  String sqlText = ((DerbyPreparedStatement) ps).toHumanReadableString();

> Make the toString() method of Derby PreparedStatements print out SQL text with ? parameters replaced by the values that have been set so far
> --------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-3676
>                 URL: https://issues.apache.org/jira/browse/DERBY-3676
>             Project: Derby
>          Issue Type: Improvement
>          Components: JDBC
>            Reporter: Rick Hillegas
>         Attachments: humanstringprepared.txt, ick.txt, ick.txt
>
>
> This topic came up in the following email thread on the user list: http://www.nabble.com/PreparedStatement.toString%28%29---nice-formatting-td17250811.html#a17250811 Here's what the thread requests: 
> "In mysql, a toString() on a PreparedStatement will do this, eg "select x
> from foo where x.a = ?" will become "select x from foo where x.a = 1" with
> the appropriate setValue() call."
> At first blush, this seems like it might be a simple project for a newcomer.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.