Vely logo Empower C
install     tutorials     examples     documentation     license     about

11.0.11 released on Jul 25, 2022



Get query results.


query-result#<query name>, <column name> \
    [ to [ define ] <result> ] \
    [ urlencode | noencode | webencode ] \
    [ length [ define ] <length> ]


Use query-result to obtain results of a query <query name>. An instance of query-result obtains a string value of a single query column named <column name>. Note that <column name> can be a computed column, and is not necessarily the same as a table column.

If query-result is used without "to" clause, then the result is printed out. If "to" clause is used, then the result is not printed out, rather it is stored into a string variable <result>, which can be created with "define" clause if it doesn't exist.

The result can be either not encoded (if "noencode" clause is used), URL encoded (if "urlencode" is used) or web (HTML) encoded (if "webencode" is used). By default, if without "to" clause (i.e. if the result is output), then webencode is used, and with "to" clause (i.e. if the result is stored in a variable <result>), then noencode is used.

query-result is often used as inline_code, especially when output.

A NULL value is always represented as an empty string ("").

Since queries can be nested, any result must always be used directly under the inner-most run-query or loop-query. Query results can be re-used with loop-query.

Optional "length" clause places the binary length of a result into number variable <length>, with optional "define" creating such a variable of type "num" if it does not exist. Note the length is the same regardless of encoding and always represents the number of bytes used for data, not counting any trailing null byte for strings. In case of binary data, <length> is the actual number of bytes used by such data, regardless of if (and how) is such binary data represented in string form.

Note that <result> always points to memory allocated by Vely and such memory is automatically freed when request finishes. If you want to free such memory before that, use delete-mem, although generally that is rarely needed and without a good reason to do so is not recommended.


Display table columns in an HTML table:
run-query#employees@mydb="select firstName, lastName from employee" output firstName, lastName
@   <tr>
@       <td>
           query-result#employees, firstName
@       </td>
@       <td>
           query-result#employees, lastName length define lastName_len
@          (length of last name is <<p-num lastName_len>>)
@       </td>
@   </tr>

Using inline_code query-result#:
run-query#get_file@mydb="select fileName, description, fileSize  from files where fileID='%s'" output fileName, description, fileSize : file_id
    // ask user if sure to delete
    @Are you sure you want to delete file <<query-result#get_file,fileName>> (<<query-result#get_file,description>>) of size <<query-result#get_file,fileSize>>? Click <a href="?req=delete_file&amp;action=delete&amp;file_id=<<p-url file_id>>">Delete</a> or click the browser's Back button to go back.<br/>

Nested queries and usage of define clause:
run-query#query1@mydb="select id from user" output id
   query-result#query1,id to define id
   run-query#query2@mydb="select timeout from settings where id='%s'" output timeout : id

Obtain query results first in variables and then use them to build HTML output:
run-query#some_query@mydb="select firstName, lastName from employee" output firstName, lastName
   query-result#some_query, firstName to define first_name
   query-result#some_query, lastName to define last_name
   @Employee (
   p-web first_name
   p-web last_name
   @) found<br/>

Reusing the query results with loop-query:
run-query#my_query@mydb="select name, extract(year from dateOfHire) yearOfHire from employee" output name, yearOfHire
   query-result#my_query, name

   @Again: <<query-result#my_query, name>>


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) 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.