revDataFromQuery | |||||||||||||||||||
Type | function | ||||||||||||||||||
Dictionary | LCS | ||||||||||||||||||
Library | LiveCode Script | ||||||||||||||||||
Syntax |
| ||||||||||||||||||
Synonyms | revdb_querylist | ||||||||||||||||||
Associations | database library | ||||||||||||||||||
Summary | Gets records from a database according to a SQL query and places the resulting data in a variable, without creating a record set. | ||||||||||||||||||
Introduced | 1.1.1 | ||||||||||||||||||
Changes | The ability to specify array elements in the varsList was added in 2.9. | ||||||||||||||||||
OS | mac, windows, linux, ios, android | ||||||||||||||||||
Platforms | desktop, server, mobile | ||||||||||||||||||
Parameters |
| ||||||||||||||||||
Example |
| ||||||||||||||||||
Values |
| ||||||||||||||||||
Related | Keyword: string Glossary: function, LiveCode custom library, return, variable, database, record set, record, Standalone Application Settings, standalone application, SQL query, delimit, prepend Command: revCloseCursor, revExecuteSQL Function: base64Encode, revQueryDatabase, revDatabaseColumnNamed Library: Database library Control Structure: function | ||||||||||||||||||
Security | disk, network | ||||||||||||||||||
Description | Use the revDataFromQuery function when you want to use or display data from a database, but not continue to work with the records that contain it. It is convenient to use the revDataFromQuery function, instead of revQueryDatabase, when you want to obtain the data for use but don't need to retain a reference to the records that the data came from. The revDataFromQuery function executes the SQLQuery, gets the records found by the query, closes the record set created by the query, and returns the data. *Important*: The revDataFromQuery function should not be used if any of the data being retrieved is binary, doing so will probably produce unexpected results. If you wish to use this function to return things like image data, the data should be encoded before being stored in the database, this could for example be done with the base64Encode function. Also remember to specify a columDelim and rowDelim that will not appear in the data. Alternatively, both these problems can be avoided by using the revQueryDatabase function to generate a record set, then using revDatabaseColumnNamed to retrieve each field individually. The SQLQuery may contain one or more placeholders, which are sequential numbers prepended by a colon. The revDataFromQuery function substitutes the corresponding variable name in the variablesList for each of these placeholders. For example, if you have two variables called "valueX" and "valueY", you can use a SQLQuery that includes placeholders as follows:
The content of the variable valueX is substituted for the ":1" in the SQLQuery (in both places where ":1" appears), and the content of valueY is substituted for ":2". To pass binary data in a variable in the variablesList, prepend
You can also use the name of a numerically indexed array, instead of a
list of variable names. In this case, the elements of the array are
substituted for the corresponding placeholders. To pass binary data in
an array element, prepend
To pass an asterisk as part of the query, substitute a percent sign (%).
For example, to use the query
If the query is not successful, the revDataFromQuery function returns an error message beginning with the string "revdberr,". You can test for success by checking whether the first item of the returned value is "revdberr".
| ||||||||||||||||||
Tags | database |