com.arsdigita.acs.db
Class SqlStatement

java.lang.Object
  |
  +--com.arsdigita.acs.db.SqlStatement

public class SqlStatement
extends Object

Utility class for bundling a SQL statement with its bind values.


Constructor Summary
SqlStatement()
           
 
Method Summary
 void addBindValue(Object o)
          Deprecated.  
 void addBindValue(String name, Object o)
          Deprecated.  
 SqlStatement append(SqlStatement s)
          Allows combining of SQL statements, including their bind variables.
 SqlStatement append(String s)
          Adds to the SQL command string for this statement.
 void bind(Object o)
          Adds a bind value to this statement.
 void bind(String name, Object o)
          Adds a named bind value to this statement.
 void bindFixup()
          This is called by the end of a SqlTag (e.g., db_query) to tell us that we're done with bind variables, and that we should go put the extra (named) ones in their places.
 void clear()
          Clears this statement.
 Object[] getBindValues()
          Returns a list of bind values.
 String getSql()
           
 boolean isSet()
           
 void setSql(String s)
          Sets the SQL command string for this statement.
 String toString()
          Performs a fixup and returns a string containg the SQL followed by the bind values.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SqlStatement

public SqlStatement()
Method Detail

clear

public void clear()
Clears this statement.

getSql

public String getSql()
Returns:
the SQL command string.

isSet

public boolean isSet()
Returns:
True if this statement has an associated SQL command; false otherwise.

setSql

public void setSql(String s)
Sets the SQL command string for this statement.
Parameters:
s - The SQL command

append

public SqlStatement append(String s)
Adds to the SQL command string for this statement. Does not adjust the bind variables.
Parameters:
s - The SQL command.
Returns:
This SqlStatement (useful for chaining multiple appends on one line).

append

public SqlStatement append(SqlStatement s)
Allows combining of SQL statements, including their bind variables. Useful for building up fragments of SQL statements, such as a date ("select to_date(:the_date, 'YYYY-MM-DD HH24:MI:SS')" and the value of :the_date) and then inserting them into a larger SQL statement (stmnt.append("SELECT ").append(dateStmnt).append(" FROM dual")).

Note that bind values from the appended statement are not bound with other variables in this statement. So, extending the above example: (stmnt.append("SELECT ").append(dateStmnt).append(", :the_date").append(" FROM dual")). ":the_date" inside of dateStmnt will be bound in this statement, but the ":the_date" which was appended afterwards is not presently bound. stmnt.bind("the_date", someValue); is necessary to bind this second "the_date".

Parameters:
SqlStatement - to append.
Returns:
This SqlStatement (useful for chaning multiple appends on one line).

addBindValue

public void addBindValue(Object o)
Deprecated.  

Adds a bind value to this statement.
Parameters:
o - The object to bind

bind

public void bind(Object o)
Adds a bind value to this statement.
Parameters:
o - The object to bind

addBindValue

public void addBindValue(String name,
                         Object o)
Deprecated.  

Adds a named bind value to this statement.
Parameters:
name - The name of the bind variable
o - The object to bind

bind

public void bind(String name,
                 Object o)
Adds a named bind value to this statement.
Parameters:
name - The name of the bind variable
o - The object to bind

bindFixup

public void bindFixup()
This is called by the end of a SqlTag (e.g., db_query) to tell us that we're done with bind variables, and that we should go put the extra (named) ones in their places. Goes through the SQL code looking for bind variables (? or :var).

getBindValues

public Object[] getBindValues()
Returns a list of bind values.
Returns:
The list of bind values

toString

public String toString()
Performs a fixup and returns a string containg the SQL followed by the bind values. For occassional debugging purposes; should never be manually combined with SQL. Use the append method to combine SqlStatements.
Overrides:
toString in class Object