f2s_db_name

Applies to: MS SQL, MySql/MariaDB, PostgreSQL Drivers

Syntax

set_attribute f2s_db_name of {DriverID} to {database}
get_attribute f2s_db_name of {DriverID} to {database}

Parameter

Description

DriverID

The ID of the driver for which this applies. In most cases, you should use _f2s_ActiveDriverID.

database

String. Name of the database

Description

All table actions (find, save, open, ect) will use the database set using this attribute. This can be done when the database needs to be dynamically changed for a certain query. By default, the database used during login will be returned.

If you are going to make a connection to a database on a different server, you will need to login to that server before setting this attribute.

Use caution with this attribute. Once you have set the connection to a different database all finds, saves, ect will be to that database until it is reset.

Note: Setting this attribute will NOT override the DATABASE_SPACE_NAME token in the .int file.

Examples

get_attribute

String sCurrentDB

get_attribute f2s_db_name of _f2s_ActiveDriverID to sCurrentDB
showln (sFormat("The current database is %1.", sCurrentDB))

set_attribute

String sCurrentDB sFirstCust sFirstDB

get_attribute f2s_db_name of _f2s_ActiveDriverID to sCurrentDB
Move sCurrentDB to sFirstDB

//open the customer table
Open Customer
//find the first customer
Clear Customer
Find ge Customer by Index.1
Move (Trim(Customer.Name)) to sFirstCust
Clear Customer
//close the customer table
Close Customer

Showln (SFormat("The current database is %1 and the first customer is %2.", sCurrentDB, sFirstCust))

//switch to the other database
set_attribute f2s_db_name of _f2s_ActiveDriverID to "OTHER_DATABASE_ON_THE_SAME_SERVER"

get_attribute f2s_db_name of _f2s_ActiveDriverID to sCurrentDB

//open the customer table on the "OTHER_DATABASE_ON_THE_SAME_SERVER"
Open Customer
//find the first customer
Clear Customer
Find ge Customer by Index.1
Move (Trim(Customer.Name)) to sFirstCust
Clear Customer
//close the customer table
Close Customer

Showln (SFormat("The current database is %1 and the first customer is %2.", sCurrentDB, sFirstCust))

//set the database back to the original one
set_attribute f2s_db_name of _f2s_ActiveDriverID to sFirstDB

//open the customer table
Open Customer

In this example, there are 2 databases on the same server each having a Customer table. The user has rights to both databases and the tables within. After quering the table but before switching databases, the table must be closed. This disconnects one database so a connection to the other can be made.

ESQL Equivalents

f2s_esql_db_name

Replaces: Commands SET_DATABASE_NAME and GET_DATABASE_NAME