getData()

Provides a way of interacting with databases: extracts data, calls stored procedures, and inserts data.

Syntax

getData(vector, service, query[, expr[, ...]]) 

Parameters

vector the name of the vector in which to return the selected records
service the name of the service to use to make the database query, a string
query a query for the database, a string
expr additional parameter to pass to the database along with the query, any of the basic datatypes (such as money, integer, string)

Usage

Specify the name of the vector you want the records returned in as the first argument. The function returns a vector with the name specified, containing the selected records.

Specify the service to use when querying the database as the second argument. The services that can be used to make the database queries are defined in the service.xml file. See the Configuration and Administration Guide for more information about this file and the services described in it.

Specify the query parameter as the third argument. The query can be in any database query language (such as SQL) as long as the appropriate service is defined in the service.xml file. How you want to use the getData () function affects what you specify. The following table provides instruction for each use.
When In the query parameter.
Extracting Data Specify the database query to make callouts to databases. Specify any additional parameters to pass to the database along with the query as subsequent arguments.
Note: The query statement must include placeholders, marked by a "?" character, for any additional parameters being passed.
Calling Stored Procedures Specify the appropriate command to execute the stored procedure. Provide any input parameters to the procedure as additional arguments.
Note: If the stored procedure returns a result set, its schema needs to match that of the vector parameter to store the results. If the stored procedure only performs insertion in the tables, than the dummy row datatype must match the return value.
Inserting Data Issue an INSERT statement to insert data into databases. Provide any parameters as additional arguments.

Example

Project logic looks for certain conditions and invokes getData() only when those conditions are met.

getData(v, 'MyService', 'SELECT col1, col2 FROM myTable WHERE id= ?', 'myId'); gets records from a table named “myTable” using a service named “MyService”, selects the first two columns of every row where the "id" is equal to the value of "myId" and returns them in a vector named “v”.