Vely logo install examples
documentation about

14.2.0 released on Nov 29, 2022



Get query results.


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


Use query-result to obtain query results. 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 optional "define" clause.

Without "to" clause, 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, webencode is used. With "to" clause (i.e. if the result is stored in a variable <result>), then no encoding takes place (you can then use encode-url or encode-web to convert it as desired).

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, to which it refers.

Optional "length" clause places the binary length of a result into number variable <length>, with optional "define". 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 where 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.


Display table columns in an HTML table:

run-query @mydb="select firstName, lastName from employee" output firstName, lastName
@   <tr>
@       <td>
           query-result firstName
@       </td>
@       <td>
           query-result lastName length define lastName_len
@          (length of last name is <<p-num lastName_len>>)
@       </td>
@   </tr>

Using inline_code query-result:

run-query @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 fileName>> (<<query-result description>>) of size <<query-result fileSize>>? Click <a href="<<p-path>>/delete_file?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 @mydb="select id from user" output id
   query-result id to define id
   run-query @mydb="select timeout from settings where id='%s'" output timeout : id
       query-result timeout

Obtain query results first in variables and then use them to build HTML output:

run-query @mydb="select firstName, lastName from employee" output firstName, lastName
   query-result firstName to define first_name
   query-result lastName to define last_name
   @Employee (
   p-web first_name
   p-web last_name
   @) found<br/>


Database ( begin-transaction   commit-transaction   current-row   database_config_file   database_queries   on-error   prepared_statements   query-result   rollback-transaction   run-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. Some icons copyright PaweĊ‚ Kuna licensed under MIT. Vely elephant logo copyright DaSoftver LLC. This web page is licensed under CC-BY-SA-4.0.