19.0.0 released Nov 08, 2023
|
Query result
Purpose: 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. <result> is allocated memory.
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.
Display table columns in an HTML table:
@<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>
end-query
@</table>
Using inline-code query-result:
run-query @mydb="select fileName, description, fileSize from files where fileID='%s'" output fileName, description, fileSize : file_id
@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&file_id=<<p-url file_id>>">Delete</a> or click the browser's Back button to go back.<br/>
end-query
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
end-query
end-query
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/>
end-query
Database
begin-transaction
commit-transaction
current-row
database-config-file
database-queries
delete-query
on-error
prepared-statements
query-result
rollback-transaction
run-query
See all
documentation
You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a dofollow link back to this page - see full license at
CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind. Icons from
table-icons.io copyright Paweł Kuna, licensed under
MIT license.