scanning

DSN Parser

The Data Source Name parser is a simple subprogram library. The subprograms can be used to parse a DSN string which specifies how to connect to a database system. After parsing, the pieces of the data source information are available through querying functions. DSNs include for example ODBC connect strings. The idea is to connect programs to databases chosen at start-up time or at run time, using external DSN strings without any need to change the program. Examples of this kind of database connection control include configuration file settings and run-time configuration over networks.

The parser recovers from a few errors in DSNs. A programmer-supplied procedure can report these errors.

The library is distributed as a source code archive. The archive also contains the source text of the documentation. A PDF file of the documentation is available online.

Examples

db2://joe@big.disk.net/pictures
A DB/2 database server is running on host big.disk.net. The name of the database to use is pictures. Connect to the database system as user joe.
oci://joe:1"!4-@tcp+big.disk.net:1502
An Oracle database server is running on host big.disk.net. It is listening on port 1502, tcp is the protocol to use. Use a default database. Connect to the database system as user joe and supply the string 1"!4- as password.
sqlite:///c:\data\base.db?mode=0666&persistent=true
Connection to SQLite. The database is c:\data\base.db. Additional parameter values for mode and persistent are specified using CGI query string syntax.
odbc(msql)://Unix(/tmp/s15bc3)
Connect via ODBC to an MSQL server. The connection uses the “protocol parameter” /tmp/s15bc3 to specify more details about the database connection.

Examples of query functions

Each of the following functions is called with a parse result, dsn. The parse result is what the library's parsing function produces from an input DSN. Here, the input string to the parser has been the DSN string in the first example above.

db2database_system_name(dsn)

joeuser_name(dsn)

big.disk.nethost_name(dsn)

picturesdatabase_name(dsn)

Grammar

DSN DB ConSpec
DSN AccessMethod ‘(’ DB ‘)’ ConSpec
DB“access” | “dbase” | “db2” | “ifx” | “mimer” | “monetdb”
DB“msql” | “mssql” | “mysql” | “navision”
DB“oci” | “pgsql” | “solid” | “sqlite” | “sybase”
AccessMethod“adbc” | “jdbc” | “odbc”
ConSpec
ConSpec ‘:’ ‘/’ ‘/’ DBTail
ConSpec ‘:’ ‘/’ ‘/’ Login QS
ConSpec ‘:’ ‘/’ ‘/’ Login DBTail
Login Server
Login User ‘@’ Server
Login User ‘@’
User NAME
User NAME ‘:’ PASSWORD
Server HostPort
Server Protocol ‘+’ HostPort
Server Protocol ‘(’ HostPort ‘)’
Server Protocol ‘(’ BAL_NOTQMARKS_NOTATSIGNS ‘)’
HostPort Host
HostPort Host ‘:’ Port
Host IP | HOSTNAME
Protocol“tcp” | “unix”
DBTail ‘/’ Database QS
Database NOTQMARKS
Port DECIMAL_DIGITS
QS ‘?’ PARAMETERS
QS

$Date: Sat, 18 Jun 2005 00:35:30 +0200 $