ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / Managing databases / SQL functions
  • Running the query
  • Retrieving the query result
  • INSERT query
  • Managing text memos
  • Managing binary memos
  • SQL query (SQLExec or queries created in the query editor)
  • Comparison with the syntax of HExecuteSQLQuery
  • SQLExec and threads
  • Limitations in PHP
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Names and runs an SQL query.
Caution: The SQLExec function does not start the memory result retrieval process.. The result is retrieved on the first call to one of the following functions: SQLFirst, SQLTable or SQLFetch.
Note: To handle a binary memo in a query, use the keyword WDMemoBinary in your query text (for more details, see remarks).
AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst This function is available when accessing external databases via a web service.
WEBDEV - Browser code The SQL functions are used to handle the local databases (such as Web SQL databases). For more details, see Accessing a database in local mode (SQLite).
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxHFSQL ClassicHFSQL 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(<SQL query text> , <Query name>)
<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.
<SQL query text>: Character string
SQL code of query to run.
<Query name>: Character string
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.
WEBDEV - Browser code

Running an SQL query in browser code Hide the details

<Result> = SQLExec(<SQL query text> , <Query name> [, <WLanguage procedure>])
<Result>: Boolean
  • True if the query was executed,
  • False otherwise. Query execution is asynchronous: the function requests execution of the query, then the current processing continues to run without retrieving the query result..
    The result of SQLExec can only be used to manage the connection problems. We advise you to check the proper query execution in the <Procedure name> procedure.
<SQL query text>: Character string
SQL code of query to run.
<Query name>: Character string
Name associated with the query text.
<WLanguage procedure>: Procedure name
Name of WLanguage procedure to run during the execution of the SQL query.
This procedure can be a browser procedure global to the project or a browser procedure local to the page that contains the code currently run. This procedure has the following format:
PROCEDURE <Nom de la procédure>(<Nom de la requête>)

where <Query name> is the name of query currently run.
This procedure is started at the end of real query execution (regardless of the query result). This browser procedure is used to:
  • check the proper execution of the query. SQLInfo is automatically run during the call to the procedure. Therefore, all the SQL variables are positioned. If an error occurred, SQL.Error will differ from "00000". The error message is returned by the SQL.MesError variable.
  • browse the query result.
If new queries are run in this procedure (to add records for example), you can:
  • use the same procedure: the parameter of this procedure is used to find out the query currently run.
  • use a different browser procedure to test the result of these new queries.
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).
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxHFSQL ClassicHFSQL Client/Server

INSERT query

When running an INSERT query, the SQL.IDAuto variable contains the automatic identifier that was added during the previous INSERT.
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)PHPAjaxHFSQL ClassicHFSQL 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")
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)ODBCNative Connectors (Native Accesses)

Managing binary memos

To write a binary memo in a table (using an 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.
      AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst Case of access to third-party databases via a web service: The path in the file corresponds to an path local to the application running the web service (i.e. an path on the mobile device)..
  • {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.
      AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst Case of access to third-party databases via a web service: The path in the file corresponds to an path local to the application running the web service (i.e. an path on the mobile device)..
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 on an HFSQL file with SQL functions is not possible and causes an error.. The error message is as follows: "Query cannot be initialized. Character {WDMemBinary( unexpected".
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxHFSQL ClassicHFSQL Client/ServerHyper File 5.5

SQL query (SQLExec or queries created in 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 HFSQL functions (HDelete, HAdd or HModify) on your data files. The integrity check and the duplicate check will be automatically performed.
Remarque: The HExecuteQuery and HExecuteSQLQuery functions can be used to check the integrity and duplicates of an HFSQL database.
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)PHPHFSQL ClassicHFSQL 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 Reverse: the HExecuteSQLQuery function specifies the query name first, followed by the query text (using the same standard as all HFSQL functions).
The syntax of SQLExec is kept for backward compatibility.

SQLExec and threads

When executing the SQLExec function in a secondary thread, the connection used must be made in the same thread: the connection cannot be made in the main the thread (project or window).. The connection established by SQLConnect is not shared in the other threads.
PHP

Limitations in PHP

  • The binary memos cannot be handled in this version. The query is run on a MySQL database.
  • The multiple queries are not supported. For example:
    DROP TABLE TEST ;
    CREATE TABLE TEST (`IDTEST` INTEGER  PRIMARY KEY ,
    `receveur` VARCHAR(50)  NOT NULL ,
    `nomtest` VARCHAR(50)  NOT NULL ,`NOMPRODUIT` VARCHAR(50)  NOT NULL );
Component: wd300hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo de conexao em Postgresql em outra porta
nDBConnection = SQLConnect(sServerIP,sUser,sPassword,sDBName,"PostgreSQL","","Server Port = 15433")
Boller
12 Apr. 2023

Last update: 09/18/2024

Send a report | Local help