PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Using a character string for the OLE DB provider
  • If a failure occurs, the connection description is not stored
  • Two connections are opened on the server
  • Validity of connection
  • Pseudo-connection to HFSQL Classic database
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
gpwOpenConnection (Function)
In French: gpwOuvreConnexion
ODBCHFSQLNot available with these kinds of connection
Opens a connection to a specific Client/Server database to manage the files of user groupware in Client/Server mode. The connection remains opened until the end of application.
gpwOpenConnection is used to define and open a connection for the data files of user groupware. To use the same connection for all the data files of the application, all you have to do is use HChangeConnection. Then, gpwOpen is used to specify the location of data files for managing rights as well as the location of data files for identifying the users.
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Example
// Use the files of user groupware with a MySQL database
IF gpwOpenConnection("gpwCt", "Test", "PasswordMySQL", ...
"Apollon_server", "TEST", hNativeAccessMySQL) = False THEN
Error(ErrorInfo())
ELSE
// The files of user groupware
// are automatically created
// if the user has rights on MySQL.
nRes is int = gpwOpen()
// If the login failed
IF nRes <> gpwOk THEN
SWITCH nRes
CASE gpwError:
Error("Error at initialization.", ErrorInfo())
CASE gpwUnknownUser:
Error("Unknown user.")
CASE gpwInvalidPassword:
Error("Invalid password")
END
END
// Use the same connection for all data files
HChangeConnection("*", "gpwCt")
Trace(HNbRec(CEDEX))
END
// Change the password for the files of user groupware
// by programming
// Example with the GPWUSER file
gpwInitAnalysis()
GPWUSER is Data Source
CNT_GPWu_HFCS is Connection
sPasswordGPWu is string = "PCSGPW2001"

// Connection parameters
CNT_GPWu_HFCS..Provider = hAccessHFClientServer
CNT_GPWu_HFCS..User = "UserHFServer"
CNT_GPWu_HFCS..Password = "PasswordHFServer"
CNT_GPWu_HFCS..Server = "HFServer"
CNT_GPWu_HFCS..Database = "GPWu"
CNT_GPWu_HFCS..CryptMethod = hCryptNo

// Open the connection
gpwOpenConnection(CNT_GPWu_HFCS)
HChangeConnection(GPWUSER,CNT_GPWu_HFCS)
HPass(GPWUSER, sPasswordGPWu)
HCreationIfNotFound(GPWUSER)
HChangePassword(GPWUSER, "TEST")

CASE ERROR:
Error(HErrorInfo() + CR + ErrorInfo())
Syntax

Defining and opening a connection Hide the details

<Result> = gpwOpenConnection(<Connection Name> , <User Name> [, <Password>] , <Data Source> [, <Database>] , <OLE DB Provider or Native Access> [, <Access> [, <Extended Information>]] , <Additional Options>)
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurred. HErrorInfo is used to identify the error.
The effective connection opening is not performed by gpwOpenConnection. The function can return True even if the values passed in parameter are incorrect.
Use gpwOpen to specify the location of data files for managing rights as well as the location of data files for identifying the users. The directories must be specified in relation to the server directory.
<Connection Name>: Character string (with quotes)
Name of new connection to define and to open. This name must not be already used by another connection (defined in the analysis, or defined by HOpenConnection or HDescribeConnection).
<User Name>: Character string (with quotes)
Name of user who connects to the Client/Server database. This parameter is returned by ..CtUserName.
<Password>: Optional character string (with quotes)
Password defined for the connection to the Client/Server database (if this password exists). If no password is required, use an empty string ("") or the NULL keyword.
<Data Source>: Character string (with quotes)
Full path of data source. The connection will be created and opened for this data source. This parameter is returned by ..CtDatabase.
<Database>: Optional character string (with quotes)
Name of database that will be used on the data source. If this parameter is not required, use an empty string (""). This parameter is returned by ..CtInitialCatalog.
<OLE DB Provider or Native Access>: Character string or constant
  • Name of OLE DB provider used. To easily retrieve the string to use, select "Connection" in the data model editor (see the Notes).

    or
  • one of the following constants:
    hAccessHF7Pseudo-connection to a HFSQL Classic database (single-user or multi-user)
    hAccessHFClientServerConnection to HFSQL Client/Server database
    hNativeAccessAS400Native AS/400 access (optional module)
    hNativeAccessDB2Native DB2 access (optional module)
    hNativeAccessInformixNative Informix access (optional module)
    hNativeAccessMySQLNative MySQL access (optional module)
    hNativeAccessOracleNative Oracle access (optional module)
    hNativeAccessPostgreSQLNative PostgreSQL access (optional module)
    hNativeAccessProgressNative Progress access (optional module)
    hNativeAccessSQLServerNative SQL Server access (optional module)
    hNativeAccessSybaseNative Sybase access (optional module)
    hNativeAccessXBaseNative xBase access
    hODBCOLE DB provider for ODBC.
    Used to access an ODBC source declared in the ODBC data sources of Windows.
    hOledbAccess97OLE DB provider for Access 97
    hOledbAccess2000OLE DB provider for Access 2000
    hOledbDBase5OLE DB provider for dBase 5
    hOledbExcel2000OLE DB provider for Excel 2000
    hOledbExcel97OLE DB provider for Excel 97
    hOledbLotus4OLE DB provider for Lotus 4
    hOledbOracleOLE DB provider for Oracle
    hOledbSQLServerOLE DB provider for SQL Server
OLE DB Caution: To use an OLE DB connection, you must:
  • install MDAC version 2.6 or later (setup performed by WINDEV or WEBDEV and when creating the setup program)
  • install the OLE DB provider corresponding to the database used.
    This parameter is returned by ..CtOLEDBProvider.
<Access>: Optional constant
Configures the type of access to the database.
hOReadWrite
(default value)
The database can be accessed in read/write. You have the ability to read the records and to write new records.
hOReadThe database can be accessed in read-only. You only have the ability to read the records. No record can be added or deleted.
This parameter is returned by ..CtAccess.
<Extended Information>: Optional character string (with quotes)
Optional information inserted into the string for connecting to the database. If specific keywords are recognized, the corresponding information is extracted from the connection string. The rest of the connection string is sent to the database. Then, the extracted parameters are processed by the native access or by the OLE DB access used.
These keywords must be indicated as follows: "<Keyword> = <Value>".
Native Accesses The keywords recognized by the native MySQL access:
Server PortSee the documentation about MySQL (keyword = 'mysql_real_connect') for more details.
Unix Socket
Client Flag
OLE DB The recognized keywords for the access by an OLE DB provider:
WD Command TimeoutDefines the maximum time-out (in seconds) for running a command (command time-out). Does not operate on the native MySQL access.
WD Connect TimeoutDefines the maximum time-out (in seconds) for establishing the connection (connection time-out). Does not operate on the native MySQL access.
HFSQL Client/Server Keywords recognized for the access by HFSQL Client/Server:
ENCRYPTIONEnables the encryption of data exchanged between the Client and the Server. This keyword can take two values:
  • FAST
  • RC5_16 for a RC5 encryption (16 rounds).
This parameter is returned by ..CtExtendedInfo.
<Additional Options>: Constant
If this parameter is not specified, the HFSQL engine automatically defines the best parameters to use according to the database accessed and to the OLE DB provider used.
To force some parameters, you have the ability to combine the following constants:
  • Location of cursors
    hClientCursorCursor managed by MDAC. Offers more features than a server cursor. A client cursor must necessarily be a static cursor.
    hServerCursorCursor managed by the database. This cursor can easily apply the changes performed by the other users to the data.
  • Type of cursor
    hDynamicCursorCursor offering a lot of features but consuming a lot of memory. This cursor allows all types of moves. It allows you to access all the modifications, additions and deletions performed by the other users.
    hForwardOnlyCursorFast cursor consuming little memory. The move is performed from the first record to the last one. The data modified by the other users is not visible.
    hOpenKeysetCursorCursor that handles a fixed set of records. Only the keys corresponding to the record are stored and not the records (consumes less memory). The deleted records can no longer be accessed. The modifications performed by the other users are visible (but not the additions).
    hStaticCursorRetrieves a copy of all the query records in memory (consumes a lot of memory). All types of moves are allowed.
  • Lock mode
    hReadOnlyCursorThe set of records cannot be modified.
    hOptimisticCursorThe record is locked when it is updated
    hPessimisticCursorThe record is locked as soon as it becomes in edit to be modified.
Caution: some types of cursors may not be supported by all the OLE DB providers.
This parameter is returned by ..CtCursorOptions.

Opening a connection defined by a Connection variable Hide the details

<Result> = gpwOpenConnection(<Connection Name>)
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurred. HErrorInfo is used to identify the error.
The effective connection opening is not performed by gpwOpenConnection. The function can return True even if the values passed in parameter are incorrect.
Use gpwOpen to specify the location of data files for managing rights as well as the location of data files for identifying the users. The directories must be specified in relation to the server directory.
<Connection Name>: Connection variable
Name of Connection variable to open. This name must not be used by another connection (defined in the analysis, or by HOpenConnection or HDescribeConnection).
Remarks

Using a character string for the OLE DB provider

To easily find the character string that must be used to define the OLE DB provider, we recommend that you proceed as follows:
  1. In the data model editor, display the description window of connections ("Analysis .. Connection").In the data model editor, display the description window of connections: on the "Analysis" pane, in the "Connection" group, click "Connections".
  2. Select the provider to use ("Connect via" combo box).
  3. The character string corresponding to the provider is displayed. This character string can be used in the syntax 2 instead of constants.

If a failure occurs, the connection description is not stored

If the connection fails to open, the description of this connection is not validated. Therefore, it is possible to redefine a connection with the same name.
For example, if the attempt to connect with the default password fails, you have the ability to perform a new attempt with another password.

Two connections are opened on the server

Two HFSQL contexts are used by the User Groupware. In the HFSQL Control Center, you will notice two connections for a single instance of the application.

Validity of connection

gpwOpenConnection behaves like HDescribeConnection: this function does not establish the connection immediately.
gpwOpenConnection identifies the connection parameters that will be used thereafter to establish the connection.
To validate this connection, you have the ability to call HOpenConnection before gpwOpenConnection with the same parameters. Therefore, the connection parameters will be already checked during the call to gpwOpenConnection.
WINDEVWEBDEV - Server codeWindowsLinuxAjax

Pseudo-connection to HFSQL Classic database

OLE DB data files or native data files are described in the data model editor. To handle these descriptions with a HFSQL Classic database, <OLE DB Provider or Native Access> must correspond to the hAccessHF7 constant.
The data files in HFSQL Classic format corresponding to the description of the OLE DB or native files will be created (if necessary) in the directory defined by <Data Source>.
Components
WINDEVWEBDEV - Server code wd230gpu.dll
Linux wd230gpu.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Exemplo de uso do Driver MS SQL Server
//Conexao
ok1, ok2 is boolean

myConn is Connection
myConn..Provider = hNativeAccessSQLServer
myConn..User = "adriano"
myConn..Password = "adriano@2016"
myConn..Source = "192.168.0.1\Projeto01"
myConn..Database = "Projeto01"
myConn..Access = hOReadWrite

ok1 = HOpenConnection(myConn)

ok2 = gpwOpenConnection(myConn)

NextTitle("Atenção")

If ok1 = true and ok2 = true

IF gpwInitAnalysis() = False THEN
Error(ErrorInfo())
ELSE
Info("Conexão ok com o banco de dados SQL Server e ativou o groupware")
END

end


IF ok = False THEN

Info("Falha ao tentar conectar no Servidor")

ELSE

Info("Conectou com sucesso no banco de dados!")

END
BOLLER
Nov. 28 2016
gpw in Client Server
Using Manual mode and ClientServer doesn't work as expected, however it does work
You need to set the connection parameters in both the connection AND then use gpwOpenConnection with all the parameters. The trick is that those parameters ARE NOT optional. (Just because the compiler doesn't crash, doesn't mean that it works)

Like so -
Make your usual connection settings and open your connection
myConn is Connection
myConn..Database = "TheDatabaseName"
myConn ..Provider = "MSSQL or whatever"
myConn..Username="ME"
...
HOpenConnection(myConn )

then open the gpw connection using the same settings -
gpwOpenConnection(myConn,sUserName,sPassword,gsDatebaseSource,gsDatebaseName,szConnectionType)

Then you can use HChangeConnection( "somefiles", MyConn)

HTH,
Chris
ccordes
Jan. 22 2014
2nd syntax doesn't work
1 - In the first example it should read Error(HErrorInfo())
ErrorInfo() will not return anything.

2 - To me, it seems that using a connection variable like in gpwOpenConnection(MyGpwConnection) doesn't work at all.
It always returns Result = False and no Error-number.

3 - The classic approach with all parameters in the same line works just fine.
Jimbo
Aug. 15 2013
Spelling mistake in the example
IF nRes <> gpwOk THEN
SWITCH nRes
CASE gpwError: Error("Error while initializing the groupware.", ErrorInfo())
CASE gpwUnknownUser: Error("Unknown user.") //gpwUnknwonUser
CASE gpwInvalidPassword: Error("Invalid password")
END
END
Riebens
Mar. 13 2012