Share:
Developers » Scripting Code Samples » Binding Parameters with Custom Tables

PREVIOUS  |  NEXT

Binding Parameters with Custom Tables

Quick Links


Notice: We are currently working to improve this content. Once revisions are finalized, we will add the article to the Recently Updated Articles section on the product's Documentation Home page. Learn more.


Custom table queries that execute often and that vary only in one condition can affect system performance. You can use binding parameters to improve query execution speed since the database doesn't need to compile the query each time it executes. 

Binding parameters are defined as a map data type that contains an index and a value for the query. The index represents the position of the parameter in the query and the value represents what will be passed to the query when it executes. 

You can use binding parameters in the following methods:

        
        Map<String, String> findFirst(String query, Map<Integer, String> bindParams)
        List <Map<String, String>> findAll(String query, Map<Integer, String> bindParams)
        List <Map<String,String>> findAll(String query, Integer pageSize, Integer pageNumber, Map<Integer, String> bindParams)
        Integer executeQuery(String query, Map bindParams)

Binding Parameter Examples

[Back to top]

Map <String, String>findFirst(String query, Map<Integer, String> bindParams)

def bindParams = new HashMap();
bindParams.put(1, "Johnson");
bindParams.put(2, "Tom");
def query = "select * from table1 where lastname = ? and firstname = ?";
def result = resp.customTable.findFirst(query, bindParams);
List <Map<String, String> >findAll(String query, Map<Integer, String> bindParams)
def bindParams = new HashMap();
bindParams.put(1, "John%");
def query = "select * from table1 where lastname like ? order by firstname";
def result = resp.customTable.findAll(query, bindParams);
List <Map<String,String>> findAll(String query, Integer pageSize, Integer pageNumber, Map<Integer, String> bindParams)
def bindParams = new HashMap();
bindParams.put(1, "Johnson");
bindParams.put(2, "Mike");
def query = "select * from table1 where lastname like ? or firstname = ? order by firstname desc";
def result = resp.customTable.findAll(query, 2, 1, bindParams);
Insert query using Integer executeQuery(String query, Map bindParams)
def bindParams = new HashMap();
bindParams.put(1, "Tom");
bindParams.put(2, "Smith");
def query = "insert into table1 (firstname, lastname) values (?, ?)";
def oid = resp.customTable.executeQuery(query, bindParams);
Update query using Integer executeQuery(String query, Map<Integer, String> bindParams)
def bindParams = new HashMap();
bindParams.put(1, "Stojakovic");
bindParams.put(2, "Johnson");
def query = "update table1 set lastname = ? where lastname = ?";
def numberOfUpdatedRows = resp.customTable.executeQuery(query, bindParams);
Delete query using Integer executeQuery(String query, Map<Integer, String> bindParams)
def bindParams = new HashMap();
bindParams.put(1, "Tom");
bindParams.put(2, "Mike");
def query = "delete from table1 where firstname = ? or firstname = ?";
def numberOfDeletedRows = resp.customTable.executeQuery(query, bindParams);
      
   




Related Articles