db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "mike bell (JIRA)" <j...@apache.org>
Subject [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
Date Tue, 20 May 2008 07:15:55 GMT

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

mike bell commented on DERBY-3676:
----------------------------------

Boy, I'm a java newbie, but I was inspired to look at the code after Rick's encouraging comments
on the list. . It looks easy to do, but the BUILDING looks......painful, judging from BUILDING.txt

Comment 1. Isn't it bad practice in general to do what Daniel says the code is doing, eg rely
on toString() for ANY formal meaning? I don't mean this as criticism, just curious.

Comment 2. If toString is being used anyway, why not just use toHumanString()

Comment 3. Ok, I dare expose myself to be made fun of :). The following seemed to work fine
with my primitive tests

   	 public String toHumanString() {  
  // I guess this is how you are making it threadsafe? Otherwise I am vague on this and in
fact the publicness of the Object[] _parameters to begin with! Boy all those publics make
my recently weened JCIP head feel scared. I want my mama.
	       synchronized(connection) {
	               if ((parameters_.length>0)) {
	            	   StringBuffer sb = new StringBuffer(sql_);
	            	   sb.append("\r\n ");
	            	   	for (int i=0;i<parameters_.length;i++) {
	            	   		if (i>0) sb.append(", ");
	            	   		sb.append("[");
	            	   		sb.append((i+1)+"]=");
	            	   		sb.append(parameters_[i]==null ? "uninitialized" : parameters_[i].toString());
	            	   	} 
	            	   	
	            	   	return sb.toString();
	               } else {
	            	   return sql_;
	               }
	               
	       }
   	 }

> 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: New Feature
>          Components: JDBC, Newcomer
>            Reporter: Rick Hillegas
>
> 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.


Mime
View raw message