sql. Retrieving string from a database

^string:sql{SQL-query}
^string:sql{SQL-query}[$.limit(1) $.offset(o) $.default{code}
 $.bind[variables hash]]

Note: this is method, not a constructor!

Returns
string retrieved from database through SQL-query. The query must result in only one column of only one row. For this operator to work, you must have connection with database server established (see operator connect).

Optional parameters:
$.limit(1) - limit response to one row only;
$.offset(o) - ignore first o records in the query results;
$.bind[hash] - variables to bind, see «Queries with bound variables» [3.1.4].

if SQL-server response was empty (0 records), …
$.default{code} …the given code will be executed and string result returned;
$.default(expression) …the given expression will be evaluated returned;
$.default[string] …the given string returned;
$.default not specified …an error message will be thrown.

Example

^string:sql{select name from company where company_id=$company_id}

While using this method, it is recommendable to construct SQL-query in such a way as to limit response to one column in one row only.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 25.01.2021