To retrieve data from a database, you will use the SQL SELECT statement in your sql query. As this statement will return values, you must have code to handle the values returned. To perform a retrieve operation, you can use the db.exec() functyion that we previously introduced, or you can use the db.select() function. Both will return data when used with a SELECT statement. We will demonstrate this in the following examples.
-
To use a db.exec() statement, create the SQL query as a variable as in the following example:
sqlQuery = "select * from [db0].[USER]";
-
Create the variable as shown below:
var record = db.select(sqlQuery);
-
Execute the query and then access the values returned. In this example, we will
var vUser = record[0].USER
var vClient = record[0].CLIENT
Note: The values returned from a database by a SELECT statement will be in the form of a dimensional array. You can include loops to get each column and row element in the table. We also recommend using try-catch blocks to handle any errors that may occur. Please see the
Examples section for additional details.