PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Running the query
  • Retrieving the query result
  • INSERT query
  • Managing text memos
  • Managing binary memos
  • SQL query (SQLExec function or queries created by the query editor)
  • Comparison with the syntax of HExecuteSQLQuery
  • SQLExec function and threads
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
Names and runs an SQL query.
Caution: SQLExec does not start the process for retrieving the result in memory. The result is retrieved during the first call to one of the following functions: SQLFirst, SQLTable or SQLFetch.
Remark: To handle a binary memo in a query, use the WDBinaryMemo keyword in the text of your query (see remarks for more details).
Remark: From version 19, HFSQL is the new name of HyperFileSQL.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
WINDEVUser code (UMC)HFSQLHFSQL Client/ServerHyper File 5.5OLE DBODBCNative Connectors (Native Accesses)
// Connexion à la base de données
// (Fonction SQLConnecte ou SQLConnecteWS)
 
// Exécuter la requête et récupérer le résultat ligne à ligne
i is int = 0
SQLExec("SELECT NOM, PRENOM, POSTE, PHOTO FROM CLIENT", "REQ1")
WHILE SQLFetch("REQ1") = 0  // Il y a encore une ligne à lire
i++
// Récupérer les données
NOM[i] = SQLGetCol("REQ1", 1)
PRENOM[i] = SQLGetCol("REQ1", 2)
POSTE[i] = SQLGetCol("REQ1", 3)
{"IMAGE"+i} = SQLGetMemo("REQ1", 4)
END
SQLClose("REQ1")
 
// Déconnexion (fonction SQLDéconnecte)
Syntax

Running an SQL query Hide the details

<Result> = SQLExec(<Text of SQL query> , <Name of the request>)
<Result>: Boolean
  • True if the query was executed,
  • False otherwise. If the query was not run, the error message can be returned by the SQL.MesError variable once SQLInfo has been run.
<Text of SQL query>: Character string (with quotes)
SQL code of query to run.
<Name of the request>: Character string (with quotes)
Name associated with the query text. Corresponds to:
  • the logical query name.
  • the name and full path of query (".WDR" file).
Java The query name corresponds to the logical query name only.
Remarks

Running the query

The information regarding the query execution is returned by SQLInfo. The SQL.NbCol variable contains the number of columns found in the query result.
Once it was run and processed, the query must be freed by SQLClose.

Retrieving the query result

Then, the query result can be:
  • Transferred into a table or into a list box (SQLTable).
  • Transferred into controls or variables (SQLAssociate).
  • Retrieved line by line (SQLFetch).
WINDEVUser code (UMC)HFSQLHFSQL Client/Server

INSERT query

When running an INSERT query, the SQL.IdAuto variable contains the automatic identifier that was added during the previous INSERT.
WINDEVUser code (UMC)HFSQLHFSQL Client/ServerHyper File 5.5OLE DBODBCNative Connectors (Native Accesses)

Managing text memos

In the <Query text> parameter, a text memo is used like a text variable. For example:
// Requête avec condition sur un mémo texte dont la valeur est "Bon client"
TexteRequête = "SELECT NOMCLI FROM CLIENT WHERE MEMOCLIENT = 'Bon client'"
SQLExec(TexteRequête, "REQ1")
WINDEVJavaUser code (UMC)ODBCNative Connectors (Native Accesses)

Managing binary memos

To write a binary memo in a table (using a SQL UPDATE or INSERT command), the following syntax must be used in the text of the query:
  • {WDMemoBinaire('<NomFichier>' [,'Fichier'])}

    where:
    • File (default value) indicates that the memo is a binary memo (coming from a file).
    • WDBinaryMemo is a reserved word.
    • <FileName> is the physical name of a file.
  • {WDMemoBinaire('<NomFichier>' [,'FichierTexte'])}
    where:
    • TextFile indicates that the memo is a text memo (coming from a file).
    • WDBinaryMemo is a reserved word.
    • <FileName> is the physical name of a file.
For example:
// Insertion du fichier C:\PHOTO\DUPONT.BMP dans un mémo binaire
TexteRequête = "INSERT INTO CLIENT VALUES ('DUPONT', 'Jean'," + ...
"{WDMemoBinaire('C:\PHOTO\DUPONT.BMP')})"
SQLExec(TexteRequête, "REQ1")
// Insertion du fichier C:\DOC\LETTRE.TXT dans un mémo texte
TexteRequête = "INSERT INTO CLIENT VALUES ('DUPUIS', 'Christophe'," + ...
"{WDMemoBinaire('C:\DOC\LETTRE.TXT', 'FichierTexte')})"
SQLExec(TexteRequête, "REQ1")

Remark: Inserting binary memos into a HFSQL file with the SQL functions is not possible and it triggers an error. The error message is as follows: "Unable to initialize the query. Unexpected {WDBinaryMemo( character".
WINDEVUser code (UMC)HFSQLHFSQL Client/ServerHyper File 5.5

SQL query (SQLExec function or queries created by the query editor)

When using the SQL DELETE, INSERT or UPDATE statements, no integrity check and no duplicate check are performed on an HFSQL database. This feature is not available in this version.
Solution: Use the HFSQL functions (HDelete, HAdd or HModify) on your data files. The integrity check and the duplicate check will be automatically performed.
Remark: HExecuteQuery and HExecuteSQLQuery are used to check the integrity and the duplicates on a HFSQL database.
WINDEVJavaUser code (UMC)HFSQLHFSQL Client/ServerHyper File 5.5OLE DBODBCNative Connectors (Native Accesses)

Comparison with the syntax of HExecuteSQLQuery

HExecuteSQLQuery can also be used to run an SQL query. The parameters of these two functions are identical but their order is reversed: indeed, HExecuteSQLQuery specifies the name of the query first then the text of the query (using the same standard as all the HFSQL functions).
The syntax of SQLExec is kept for backward compatibility.

SQLExec function and threads

When running SQLExec in a secondary thread, the connection used must be established in the same thread: the connection cannot be established in the main thread (project or window). The connection established by SQLConnect is not shared in the other threads.
Component: wd260hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo completo
ConnectionNum is int
SourceName is string
// Connection to a specific data source via ODBC MS ACCESS
SourceName = "MS Access 97 Database"
ConnectionNum = SQLConnect(SourceName, "", "", "", "ODBC") // <--------
IF ConnectionNum <> 0 THEN
// The connection was successful

// Run the query and retrieve the result line by line
i is int = 0
SQLExec("SELECT LASTNAME, FIRSTNAME, EXTENSION, PHOTO FROM CUSTOMER", "QRY1") // <--------
WHILE SQLFetch("QRY1") = 0 // There is still another line to read
i++
// Retrieve the data
LASTNAME[i] = SQLGetCol("QRY1", 1)
FIRSTNAME[i] = SQLGetCol("QRY1", 2)
EXTENSION[i] = SQLGetCol("QRY1", 3)
{"IMAGE"+i} = SQLGetMemo("QRY1", 4)
END
SQLClose("QRY1")

ELSE
// The connection failed: display an error message
SQLInfo()
Error("The connection to the data source " + SourceName + " failed." + CR + ...
"Error code: " + SQL.Error + CR + SQL.MesError)

END
// In any case (connection OK or not)
SQLDisconnect() // <--------
BOLLER
11 Sep. 2018