sql_query Function
Syntax
p Result = sql_query(C cnIn | SQL::Connection cnIn, c statement [, sql::arguments argsIn [, L flagPortableSQL[, L formatJSON]]]);
Arguments
- cnInCharacter SQL::Connection
Either an open SQL::Connection object or connection string.
- statementCharacter
SQL statement to execute. Must be a SELECT statement.
- argsInSQL::Arguments
A SQL::Arguments object containing the arguments used in the SQL statement.
- flagPortableSQLLogical
Default = .T.. Specify if SQL statement is portable (.T.) or native (.F.) syntax.
- formatJSONLogical
Default = .F.. Specify if the JSON should be nicely formatted.
Returns
- ResultPointer
Returns an object with the following properties:
- errorLogical
.T. if an error occurred. Otherwise .F.
- errorTextCharacter
If an error occurred, contains the error message.
- jsonCharacter
If no error occurred, contains the JSON data returned by the function.
Description
Performs a SQL select query and returns the results as JSON data.
Discussion
This function is a convenience function. It is a wrapper around the low level Xbasic AlphaDAO commands.
Example
dim result as p dim sql as c = "SELECT FIRST 10 * FROM customers" dim cnIn as c = "::Name::northwind" result = sql_query(cnIn, sql) ? result.error = .F. ? result.json = [ {"CustomerID" : "ALFKI"}, {"CustomerID" : "ANATR"}, {"CustomerID" : "ANTON"}, {"CustomerID" : "AROUT"}, {"CustomerID" : "BERGS"}, {"CustomerID" : "BLAUS"}, {"CustomerID" : "BLONP"}, {"CustomerID" : "BOLID"}, {"CustomerID" : "BONAP"}, {"CustomerID" : "BOTTM"} ]