4D v18OPEN DATABASE |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v18
OPEN DATABASE
|
OPEN DATABASE ( filePath ) | ||||||||
Parameter | Type | Description | ||||||
filePath | String |
![]() |
File name (.4db, .4dc, .4dbase, .4dproject, .4dz, or .4dlink) or complete access path of database to open | |||||
The OPEN DATABASE command closes the current 4D database and opens on-the-fly the database defined by filePath. This command is useful for automatic testing purposes, to reopen a database automatically after a compilation, or to allow a merged 4D remote application to select the a database server to connect.
In the filePath parameter, pass the name or full access path of the database to be opened. You can use files having one of the following extensions:
If you pass only a file name, this file must be placed at the same level as the structure file of the current database.
If the access path defines a valid database, 4D quits the database that is already open and then opens the specified database. In single-user mode, the On Exit database method of the database being closed and the On Startup database method (or the On Server Open Connection database method) of the database being opened are called successively.
Warning: Since this command causes the application to quit before re-opening with the specified database, it is not recommended to use it in the On Startup database method, or in a method called by this database method.
The command is executed in an asynchronous manner: after its call, 4D continues executing the rest of the method. Then, the application behaves as if the Quit command was selected in the File menu: open dialog boxes are cancelled, any open processes have 10 seconds to finish before being terminated, and so on.
If the target database file is not found or is invalid, a standard file system error is returned and 4D does nothing.
OPEN DATABASE("C:\\databases\\Invoices\\Invoices.4db")
This code could be added to the On Startup database method of a single-user application to select a server:
C_TEXT($xml)
$xml:="<?xml version=\"1.0\" encoding=\"UTF-8\"?><database_shortcut is_remote=\"true\" server_database_name=\"{databaseName}\" server_path=\"{IP}\"/>"
$databaseName:="myServer"
$IP:="192.168.6.7:19813"
If(Shift down)
$IP:=Request("IP address to connect to "+$databaseName;$IP)
Else
ok:=1
End if
If(ok=1)
$xml:=Replace string($xml;"{databaseName}";$databaseName)
$xml:=Replace string($xml;"{IP}";$IP)
C_OBJECT($link)
$link:=Folder(fk user preferences folder).file("server.4dlink")
$link.setText($xml)
OPEN DATABASE($link.platformPath)
Else
QUIT 4D
End if
Product: 4D
Theme: 4D Environment
Number:
1321
Created: 4D v14 R3
4D Language Reference ( 4D v18)