ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / How to proceed? / Programming
  • Method
  • Example
  • Notes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
An SQL query can be directly created via the query editor (see Creating a query in SQL code). However, it may be useful to create an SQL query through programming.
Method
To create an SQL query through programming:
  1. Declare a string variable where the SQL code of the query will be stored.
  2. Declare a variable of type data source. This variable will represent the query at runtime.
  3. Use HExecuteSQLQuery to execute the query.
  4. To read and retrieve the query result, use the standard read functions: HReadXXX, FOR EACH, ...
  5. Don't forget to free the query when it is no longer used (HFreeQuery).
Tip
If the query uses parameters coming from variables, use StringBuild to build the string representing the SQL code. This tip is used in the example below.
Example
SQLCode is string
DS is Data Source
 
SQLCode = [
SELECT CustomerName, City FROM CUSTOMERS
WHERE Country='%1'
]
 
// List the customers living in France
SQLCode = StringBuild(SQLCode, "FRANCE")
 
IF HExecuteSQLQuery(DS, cntDatabBase, hQueryWithoutCorrection, SQLCode) THEN
// Loop through the result
FOR EACH DS
// Process the record read
Trace(DS.CustomerName, DS.City)
END
 
HFreeQuery(DS)
ELSE
Info("Error while running the query.")
END
Notes
This creation mode presents several drawbacks:
  • no completion on the names of items.
  • you must know and even master the SQL language.
  • no assisted input of SQL code.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/27/2022

Send a report | Local help