jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve A. Olson" <steve.ol...@ait-inc.com>
Subject RE: Startard Taglib- SQL bind variables
Date Thu, 23 May 2002 19:23:46 GMT
All,

 ... sql attribute already exists, sorry about item 2. Would just note that
bind variables would be allowed there as well.

--Steve


-----Original Message-----
From: Steve A. Olson [mailto:steve.olson@ait-inc.com]
Sent: Thursday, May 23, 2002 3:20 PM
To: 'Tag Libraries Developers List'
Subject: Startard Taglib- SQL bind variables


I'd like to propose an alternate syntax for binding variables to SQL
statements in the Standard SQL taglib.

1- Instead of using nested "param" tags that match a corresponding "?"
placeholder, allow developers to directly embed variables into the sql
string.  Depending on the complexity of the parsing it may be easier to use
"colon" variables instead of "$" variables-- I'm not sure about that.

2- Additionally, I'd like to propose an "sql" attribute that could be used
in-lieu of the tag body; again, for reducing extraneous text.

Here is an example of the proposed syntax:

   <sql:update>
    UPDATE account
    SET Balance = Balance - $transferAmount
    WHERE accountNo = $accountFrom
   </sql:update>

Again, using the sql attribute:

   <sql:update
        sql="UPDATE account
             SET Balance = Balance - $transferAmount
             WHERE accountNo = $accountFrom"
        />

*BTW, I'm not sure if line breaks are allowed within attribute assignments,
however, it makes for more readable code.

Again, using current syntax:

  <sql:update>
    UPDATE account
    SET Balance = Balance - ?
    WHERE accountNo = ?
    <sql:param value="$transferAmount">
    <sql:param value="$accountFrom">
  </sql:update>

Finally, with this simplified syntax, we can collapse all of the tags
required to implement a prepared query into a single concise tag as follows!
(I find this syntax much more usable and far less "wordy".)

  <sql:query
       var="q"
       sql="select balance from account where accountNo = $accountFrom">
    <%-- body processed for each fetch in resultSet ... --%>
  </sql:query>


I look forward to your comments.
--
Steve Olson
steve@ait-inc.com



--
To unsubscribe, e-mail:   <mailto:taglibs-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-dev-help@jakarta.apache.org>


Mime
View raw message