Vely logo what is  |  why  |  install  |  tutorials  |  examples  |  documentation  |  license  |  about
Current release 10.4.36 (Beta). This page last updated on Jul 01 2022

run-query



PURPOSE:


Execute a query and loop through result set.

SYNTAX:


run-query#<query name>@<database configuration file> [= <query text> [(output <column name> [, <column name>]...) | unknown-output]] [:<input parameter> [, <input parameter>]...]

run-prepared-query#<query name>@<database configuration file> [= <query text> [(output <column name> [, <column name>]...) | unknown-output]] [:<input parameter> [, <input parameter>]...]

DESCRIPTION:


run-query# is a combination of define-query, start-query (which assumes the input parameters and the database configuration of run-query) and loop-query in that order. Because of that, the order of clauses (query text, output and input parameters) must be as shown above. For example:

run-query#add_data@db = myqry output col1,col2 : "100", "200", "400"

is the same as:

define-query#add_data = myqry output col1,col2
start-query#add_data@db: "100", "200", "400"
loop-query#add_data

You can also use separate define-query and combine only start-query and loop-query:

define-query#add_data@db = myqry output col1,col2
run-query#add_data@db : "100", "200", "400"

is again the same as:

define-query#add_data@db = myqry output col1,col2
start-query#add_data@db: "100", "200", "400"
loop-query#add_data

run-query is convenient as a shortcut for a class of queries where there is only a single query text (i.e. no need for multiple start-querys), which probably covers a majority of queries.

run-prepared-query is the same as run-query except for a few important differences; see prepared_statements.

EXAMPLES:


Select first and last name (output is firstName and lastName) based on employee ID (specified by input parameter empid):

input-param empid
run-query#sel@db = "select firstName, lastName from employee where employeeId='%s'" output firstName, lastName : empid
    @Employee is <<query-result#sel, firstName>> <<query-result#sel, lastName>>
end-query

Prepared query:

run-prepared-query#add_data@db = qry : stock_name, stock_price, stock_price
end-query


SEE ALSO:


Database ( on-error   affected-rows   error-text   error   begin-transaction   column-count   column-data   database_queries   column-names   commit-transaction   prepared_statements   current-row   database_config_file   define-query   exec-query   loop-query   query-result   rollback-transaction   row-count   run-query   start-query  )  SEE ALL (documentation)



Copyright (c) 2017-2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. This web page is licensed under CC-BY-SA-4.0.