Cernunnos Manual


${sql()}

Description:

Executes the specified SQL statement and returns the result.

Reagents:

Name XPath Description Reagent Type Expected Type Required
DATA_SOURCE @data-source The DataSource to use for executing the SQL. If omitted the request attribute under the name 'SqlAttributes.DATA_SOURCE' will be used PHRASE javax.sql.DataSource No
CONNECTION @connection **DEPRECATED: Use DATA_SOURCE instead.** Optional Connection object. The default is the value of the 'SqlAttributes.CONNECTION' request attribute (if specified) or null. PHRASE java.sql.Connection No
SQL descendant-or-self::text() The SQL expression to evaluate. PHRASE java.lang.String Yes

Examples:

Loads a Spring bean container defined in 'datasourceContext.xml' which contains a DataSource, then begins a transaction, then queries that DataSource for the 'user_id' associated with the 'admin' account, then performs an 'upsert' operation on the 'up_user_profile' table:

 
       
        <spring-beans location="datasourceContext.xml"> 
          <with-attribute key="SqlAttributes.DATA_SOURCE" value="${PortalDb}"> 
            <sql-transaction> 
              <sql-upsert> 
                <update-statement>UPDATE up_user_profile SET profile_name = 'HTML browser profile' WHERE user_id = ?</update-statement>  
                <insert-statement>INSERT INTO up_user_profile(user_id, profile_id, profile_name, description, layout_id, structure_ss_id, theme_ss_id) VALUES(?, 1, 'HTML browser profile', 'A sample profile for common web browsers', 1, 1 1)</insert-statement>  
                <parameter value="${sql(SELECT user_id FROM up_user WHERE user_name = 'admin')}"/> 
              </sql-upsert> 
            </sql-transaction> 
          </with-attribute> 
        </spring-beans>