DB Access Module for PostgreSQL User’s Guide : Chapter 2 Technical Information : Databases and Connections
Databases and Connections
This section describes the arguments used to create an instance of RWDBDatabase for the DB Access module of PostgreSQL. In order for a SourcePro DB application to interact with a database, an RWDBDatabase instance must be created by calling:
 
RWDBManager::database(accessLib, serverName, userName,
passWord, databaseName);
All arguments are of type RWCString. These parameters are used to build a connection string which is passed to the libpq function PQconnectdb.
The arguments you must provide to RWDBManager::database() are:
accessLib: If your DB Access Module for PostgreSQL is compiled as a DLL or shared library, provide the name of the DLL or shared library. See the document Building Your Applications for information about naming conventions. If you are using a static library, supply the string "POSTGRESQL".
serverName: Supply the name of the PostgreSQL host. Or, for direct control of connection parameters, pass a full connect string of the form required by PQconnectdb(); for example:
For example:
"host = somehost user = someUser dbname = someDBname"
In this case, the string is passed to PQconnectdb() without modification, and the userName, passWord, and databaseName parameters are ignored.
userName: Supply a login of a valid user.
passWord: Supply the password for the login specified by userName.
NOTE >> You can instead provide a password using the callback API, which may provide more security. For more information, see Chapter 10, “Callbacks” in the DB Interface Module User’s Guide.
databaseName: Supply the name of the PostgreSQL database to use.
Examples of Opening a Database
Here are two examples of opening a database.
Example 1 – Opening a specific database
Notice that the accessLib is defined as POSTGRESQL, indicating that the application will use the static version of the access library and must be linked with it:
 
RWDBDatabase aDB = RWDBManager::database ("POSTGRESQL",
"myHost", "cratchitt","scrooge", "SALES");
Example 2 – Opening a database from a Windows application
The second example shows opening the same database from a Windows application. In this case, the accessLib is defined as pgs<ver>15d.dll, indicating that the application will dynamically load the Access Module at runtime:
 
RWDBDatabase aDB = RWDBManager::database ("pgs<ver>15d.dll",
"INHOUSE", "cratchitt", "scrooge", "SALES");