ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Native Connectors/Native Accesses / Native PostgreSQL Connector
  • Overview
  • Importing the structure of files
  • The import steps
  • Taking into account the evolution of PostgreSQL database
  • Programming
  • 1. Establishing the connection
  • 2. Running queries
  • 3. Retrieving the result
  • 4. Closing the connection
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
Overview
To use a PostgreSQL database with Native Connector (also called Native Access), the structure of PostgreSQL tables must be imported into the WINDEV or WEBDEV analysis.
Differences compared to SQL programming:
The queries are not required to handle the PostgreSQL data. Indeed, the HFSQL functions can be directly used to read data, perform searches, implement filters, ...
However, the structure of PostgreSQL files must be imported into the WINDEV or WEBDEV analysis.
Remark: The queries run by HExecuteQuery and HExecuteSQLQuery are automatically "corrected" in order to be compatible with PostgreSQL.
Importing the structure of files

The import steps

To perform this import:
  1. Start the data model editor: click Load project analysis in the quick access buttons.
  2. On the "Import" tab, in the "Analysis" group, expand "Creation" and select "Import file/table descriptions...".
  3. The wizard starts. A connection to the PostgreSQL database is automatically established and associated with the data files imported into the analysis. This connection will have to be used to handle the PostgreSQL data file through programming.
    In the different steps of the wizard, choose the following options:
    • Type of database: PostgreSQL.
    • Characteristics of the connection: Data server, User and password, database.
    • The application will access the data in the current format.
    • When the connection is established, all you have to do is select the tables that will be imported into the WINDEV or WEBDEV analysis. These tables can be handled through programming with the HFSQL functions of WLanguage. These tables will be displayed in blue in the data model editor.

Taking into account the evolution of PostgreSQL database

To take into account the evolutions of the tables imported into the data model editor, go to the "Synchronization" tab, "Analysis" group, expand "Analysis" and select "Update analysis from external databases".
A wizard starts, allowing you to:
  • analyze the differences for the imported tables,
  • analyze the differences for all the PostgreSQL tables.
Programming

1. Establishing the connection

To establish the connection to the PostgreSQL database, call HOpenConnection and specify the name of the connection to open. The connection name was defined when importing the structure of files into the analysis.
Caution: If you are using another syntax, the name of the database to use must be specified.
To modify some parameters of this connection (username or password for example), call HConnect.
Remarks:
  • If you try to read the file directly (HReadFirst, ...), the connection associated with the file description in the analysis will be automatically opened.
  • You have the ability to set the "Server Port" for the connection to the PostgreSQL server. Simply add the corresponding string to the extended information of the connection (HDescribeConnection or HOpenConnection).
    • Example 1: "Server Port=3306;" to connect on port 3306 of the PostgreSQL server.
    • Example 2: "Server Port=3306; Client Flag=0;"
    • ...
      For more details, see the documentation about PostgreSQL.
  • The management mode of the Unicode items can be configured during the connection.
    To use Unicode strings, the "UTF8" charset must be specified when creating the PostgreSQL database. Caution: in this case, all the strings will be Unicode strings.
    To manage the Unicode items, the "WD Unicode Support" option must be added into the extended information of the connection (HDescribeConnection or HOpenConnection).
    If "WD Unicode Support = 0", the management of the Unicode format is disabled for the connection. All the values will be converted (if necessary) by the server into the default character set. In this case, the performance is improved but the Unicode items are not supported.
    If "WD Unicode Support = 1" (default value), the management of the Unicode format is enabled for the connection. All the exchanges with the server will be performed in Unicode. The Native Connector manages the necessary conversions by using the character set defined by ChangeCharset.
    Caution: ChangeCharset must be used BEFORE opening the connection. The connection must be closed and reopened after each call to ChangeCharset in order for the data to be properly converted to the specified character set.

2. Running queries

HExecuteQuery and HExecuteSQLQuery are used to run queries on the current database.
  • HExecuteQuery: is used to run a preset query with the query editor.
  • HExecuteSQLQuery: is used to execute a query by specifying the SQL code of the query and the name that will be assigned to this SQL code.
// Initialize the "CUSTOMER_84" query
HExecuteQuery(CUSTOMER_84, "PostgreSQLDatabase", hQueryWithoutCorrection)
HExecuteSQLQuery(QryCustomer, "PostgreSQLDatabase", hQueryWithoutCorrection, ...
"SELECT NAME FROM CUSTOMER")

3. Retrieving the result

The result is browsed by the standard read functions: HReadFirst, HReadNext, HReadSeek, ...
In this version, the records cannot be locked by the lock options of these functions. Only the locks set with SQLLock are supported.

4. Closing the connection

HCloseConnection is used to close the connection to the database once all the necessary queries have been run.
Minimum version required
  • Version 9
This page is also available for…
Comments
Como referenciar a uma porta diferente
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/4122-atencao-versao-28-driver-nativo-postgresql-teve-uma/read.awp
Boller
06 Jun. 2023

Last update: 05/26/2022

Send a report | Local help