How do I connect to a database?

LyciaStudio is database-agnostic and allows 4GL applications to work with one or multiple databases of the following types: Informix, Oracle, MS SQL Server, MySQL, DB2, PostgreSQL.

In Querix 4GL all database connections are made to emulate Informix connection conventions what ensures that your 4GL source code requires no changes to access multiple RDBMSs.

Database.cfg

Database connection details need to be specified in the database.cfg configuration file which can be found in (below is the default installation directory):

  • Windows OS - C:\Program Files\Querix\Lycia 3 Development Suite 7.1\Lycia\etc\
  • Linux OS - /opt/Querix/Lycia/etc/


Below example shows the database.cfg structure to be followed in order to configure a database connection

dbname {					//dbname = alias that will be used in 4GL code as the database name

driver = "dbtype"			//driver = parameter which represents the database type (optional)
source = "database"			//source = name of the database as it is specified on the database server (optional)
username = "user"			//username = user's login (optional)
password = "pwd"			//password = user's password (optional)
}


CONNECT TO

This statement allows a program to connect to several databases at a time which can be located on different servers and be of different types. It can be used to specify only the runtime database connections. The syntaxis of this statement is as follows:

CONNECT TO


Database = the name of the database to connect to

Session = the session name for the connection

Login = the username valid on the database server

Password = the password valid for the username


DATABASE

Use this statement to open a database which will become the default database and the current database. It can be used if the application needs to connect to one database at a time. The syntaxis of this statement is as follows:

DATABASE


Database Name = the name of the database

Server = the name of the host system where the database resides

Variable = a variable that contains the database specification



Step-by-step database connection setup scheme

Actions to be taken to connect to a database/s:

Step 1 - Set up the connection between the database server and the database client. This topic describes how to do it for Informix, Oracle and ODBC connections with the SQL Server as an example.

Step 2 - Add the database connection details to the database.cfg file.

Step 3 - Use the DATABASE statement in an application to connect to a single database and use the CONNECT TO statement to connect to several databases simultaneously.

Step 4 - Set up the database driver. It will be used at compilation and runtime if the database connection details for the database name referenced by the application were not found in the database.cfg.



More information about setting up a database connection can be found here - https://querix.com/go/lycia/index.htm#07_db_connect/db_connectivity.htm