PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Method
  • Example
  • Notes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 by programming.
Method
To create an SQL query by programming:
  1. Declare a string variable where the SQL code of the query will be stored.
  2. Declare a data source variable. This variable will represent the query at run time.
  3. Use HExecuteSQLQuery to run 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 is using 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
// Browse 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 required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment