Reading values from an external file
Using external files
Often you want to set the Transaction object values from an
external file. For example, you might want to retrieve values from
your PowerBuilder initialization file when you are developing the
application or from an application-specific initialization file
when you distribute the application.
ProfileString function
You can use the PowerScript ProfileString function to retrieve
values from a text file that is structured into sections containing
variable assignments, like a Windows INI file.
The PowerBuilder initialization file is such a file, consisting of
several sections including PB, Application,
and Database:
1 |
[PB] |
1 |
<span>variables and their values</span> |
1 |
... |
1 |
[Application] |
1 |
<span>variables and their values</span> |
1 |
... |
1 |
[Database] |
1 |
<span>variables and their values</span> |
1 |
... |
The ProfileString function has this syntax:
1 |
ProfileString ( <span>file, section, key, default</span> ) |
Example
This script reads values from an initialization file to set
the Transaction object to connect to a database. Conditional code
sets the variable startupfile to the appropriate
value for each platform:
1 |
sqlca.DBMS = ProfileString(startupfile, "database",& |
1 |
   "dbms", "") |
1 |
sqlca.database = ProfileString(startupfile,& |
1 |
   "database", "database", "") |
1 |
sqlca.userid = ProfileString(startupfile, "database",& |
1 |
   "userid", "") |
1 |
sqlca.dbpass = ProfileString(startupfile, "database",& |
1 |
   "dbpass", "") |
1 |
sqlca.logid = ProfileString(startupfile, "database",& |
1 |
   "logid", "") |
1 |
sqlca.logpass = ProfileString(startupfile, "database",& |
1 |
   "LogPassWord","") |
1 |
sqlca.servername = ProfileString(startupfile,& |
1 |
   "database", "servername","") |
1 |
sqlca.dbparm = ProfileString(startupfile, "database",& |
1 |
   "dbparm", "") |