Purpose
Synopsis
procedure SQLconnect(s:string|text)
Argument
Example
The following connects to the MySQL database `test' as the user `yves' with the password `DaSH':
SQLconnect("DSN=mysql;DB=test;UID=yves;PWD=DaSH")
Open the database
mydata.sqlite with the integrated SQLite engine:
SQLconnect("mydata.sqlite")
Further information
1. This procedure establishes a connection to the database defined by the given connection string. If extended mode is in use (default) and the ODBC driver manager publishes its driver list, the connection string may be reduced to a file name as long as this name allows identification of the required driver (by using the filename extension).
2. Both
Unicode and
ANSI ODBC interfaces are supported. By default the Unicode interface is used on Windows and the ANSI interface is selected on Posix systems. It is possible to choose the interface by using the
"enc:" file name prefix: any of the UTF encodings (except UTF-8) will enable the Unicode interface. Otherwise the ANSI interface is selected using the specified encoding. For instance for using the ANSI interface under Windows with an Access database:
"enc:sys,mydb.mdb". Similarly, to use the Unicode interface of MySQL on a Unix machine, the connection strings looks like:
"enc:wchar,DSN=mysql;DB=test".
3. It is possible to open several connections but the connection established last becomes active. Each connection is assigned an identification number which can be obtained by getting the value of the parameter
SQLconnection after this procedure has been executed. This parameter can also be used to change the active connection.
4. ODBC drivers are not necessarily executed from the same working directory as the model. As a consequence, a driver expecting a file as data source may not be able to locate the file if its name is relative to the current directory (
e.g.
"DSN=Microsoft Access Driver; DBQ=mydb.mdb"). The use of the function
expandpath from
mmsystem allows to avoid this problem by generating an absolute path name for the given name (
e.g.
"DSN=Microsoft Access Driver; DBQ="+expandpath("mydb.mdb")).
5. When Mosel is running in restricted mode (see Section
mosel command: restricted mode), connections using a file name are not possible if restriction
NoRead or
NoWrite is active and connections using a DSN are disabled by restriction
NoDB.
6. The embedded SQLite database engine is selected when specifying a file name with extension
".db",
".db3",
".sqlite" or
".sqlite3". The driver may also be selected with the help of an extended connection string starting with the
DRIVER keyword and using
"mmsqlite" as the driver name. In this case the option
DB has to be set in order to select the database file and
READONLY may also be added to open the database read-only. The option
SYNC makes it possible to select the synchronous flag of the connection; possible values are 0 (off), 1 (normal), 2 (full) or 3 (extra). The option
TIMEOUT will define the
busy timeout for the connection: this is an amount of time (in milliseconds) indicating for how long SQLite will try to execute a query when the database is locked (by default the query fails if the database is already used by a concurrent connection). A typical connection string for this SQLite driver is therefore of the form:
"DRIVER=mmsqlite;READONLY=FALSE;TIMEOUT=0;DB=mydata.db" (that is the same as
"mydata.db"). When using this syntax a temporary database can be created by using an empty file name and an in-memory database is generated if the file name is
":memory:".
Related topics
Module
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the
property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not
convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except
solely for internal evaluation purposes to determine whether to purchase a license to the software
described in this documentation, or as otherwise set forth in a written software license agreement
between you and FICO (or a FICO affiliate). Use of this documentation and the software described in
it must conform strictly to the foregoing permitted uses, and no other use is permitted.