Skip to main content
Version: 20 R7 BETA

SQL GET DATA SOURCE LIST

SQL GET DATA SOURCE LIST ( sourceType ; sourceNamesArr ; driversArr )

ParameterTypeDescription
sourceTypeIntegerSource type: user or system
sourceNamesArrText arrayArray of data source names
driversArrText arrayArray of drivers for sources

This command is not thread-safe, it cannot be used in preemptive code.

Description

The SQL GET DATA SOURCE LIST command returns, in the sourceNamesArr and driversArr arrays, the names and drivers of the sourceType type data sources defined in the ODBC manager of the operating system.

4D allows you to connect to an external ODBC data source directly via the language and execute SQL queries within a Begin SQL/End SQL tag structure. This works as follows: the SQL GET DATA SOURCE LIST command can be used to get a list of data sources present on the machine. The SQL LOGIN command can then be used to designate the source to be used. You can then execute SQL queries using a Begin SQL/End SQL tag structure in the “current” source. To carry out queries using the 4D internal engine again, simply pass the SQL LOGOUT command. For more information about SQL commands in the Method editor, please refer to the 4D SQL Reference manual.

In sourceType, pass the type of data source that you want to retrieve. You can use one of the following constants, found in the “SQL” theme:

ConstantTypeValue
System data sourceLongint2
User data sourceLongint1

Note: This command does not take file type data sources into account.

The command fills and sizes the sourceNamesArr and driversArr arrays with the corresponding values.

Note: If you want to connect to an external 4D data source via ODBC, you will need to have installed the 4D ODBC Driver on your machine. For more information, please refer to the 4D ODBC Driver Installation manual.

Example

Example using a user data source:

 ARRAY TEXT(arrDSN;0)
 ARRAY TEXT(arrDSNDrivers;0)
 SQL GET DATA SOURCE LIST(User data source;arrDSN;arrDSNDrivers)

System variables and sets

If the command is executed correctly, the OK system variable is set to 1. Otherwise, it is set to 0 and an error is generated.

See also

SQL Get current data source
SQL LOGIN
SQL LOGOUT