|
|
|
|
- Overview
- Programming
- 1. Establishing the connection
- 2. Running queries
- 3. Retrieving the result
- 4. Closing the connection
Native PostgreSQL Connector: Programming with SQL functions
Available only with this kind of connection
You can use SQL functions to handle the PostgreSQL database. Differences compared to HFSQL programming: The use of SQL functions to handle PostgreSQL data does not require importing the file structure into the analysis. However, the data must be handled by queries only. The content of the PostgreSQL files cannot be read directly. 1. Establishing the connection SQLConnect opens a connection to a PostgreSQL database via the Native Connector. The type of database used (PostgreSQL in this case) must be passed as parameter to SQLConnect. Remark: the name of the PostgreSQL data source ("PostgreSQLDatabase" in the example) is the name or the IP address of the computer where the database is available. In any case, the name of the "Database" must be specified.
ConnectionNum = SQLConnect("PostgreSQLDatabase", "", "", "", "PostgreSQL") // or // ConnectionNum = SQLConnect("PostgreSQLDatabase", "User", "Password", "MyDatabase", ... // "PostgreSQL") Â // Connection to a remote PostgreSQL database ConnectionNum = SQLConnect("192.168.1.51", "User", "Password", "test", "PostgreSQL")
Managing the character sets: All the exchanges are performed in the current character set (charset). An error occurs during the connection if the server does not support the conversions from or to the current character set. In this case, ChangeCharset must be used before SQLConnect to select a character set compatible with the server. 2. Running queries The queries are run by SQLExec. SQLExec expects the text of the SQL query as parameter, as well as the name that will be given to this query.
SQLExec("SELECT LASTNAME, FIRSTNAME, EXTENSION, PHOTO FROM CUSTOMER", "QRY1")
3. Retrieving the result Several methods can be used to retrieve the result: - SQLFirst: Retrieves the result and starts an SQLFirst/SQLCol browse.
- SQLTable: Retrieves the result of the query in a Table control populated programmatically in the WINDEV application or WEBDEV site. The result of the query can be retrieved by partial Fetch.
- SQLFetch: Used to browse the different lines of the query result. The browse performed in the query result is an SQLFetch/SQLGetCol browse.
SQLLock is used to lock the table records or the records selected by the query. On a PostgreSQL database, the timeout to lock or modify a locked record is infinite by default. To modify the timeout, it is recommended to use "WD Command Timeout" in the optional information of SQLConnect. In this case, the database will return an error when the timeout is reached. 4. Closing the connection SQLClose is used to close the connection to the database once all the necessary queries have been run.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|