SML# Document Version 4.0.0
22 SQL Expressions and Commands

22.3 Database Server Description: The _sqlserver Expression

The _sqlserver expressions denotes the following two things: the connection information of a database server, and the schema the database server has. When the evaluation result of a _sqlserver expression is applied to the SQL.connect function (see Section 22.8.1), it tries to connect the database server denoted by the _sqlserver expression. If the connection is established and it is confirmed that the database connected contains the schema denoted by the _sqlserver expression, the SQL.connect function returns a connection handle to the server.

A _sqlserver expression consists of the following three items in this order: a kind of database to be connected, a parameter specific to the database kind, and a record type representing the shchma that the database is expected to have. The following is the typical example of a _sqlserver expression:

_sqlserver SQL.postgresql "host=localhost port=5432"
  : {  
       employee : {id : int, name : string, age : int,
                   deptId : int option, salary : int option} list,
       department : {deptId : int, name : string} list
    }

This example denotes that the PostgreSQL server listening to localhost:5432 manages the database schema corresponding to the record type. See Section 22.8.1 for details of the database kinds and parameters supported in SML#.

In fact, an arbitrary function application expression appexp may occur between _sqlserver and :. Also in the above example, SQL.postgresql and "host=localhost port=5432" are actually a function and its argument. It is allowed to put here an expression that selects a server among different servers of the same schema at runtime. The expression must be of the SQL.backend type.

The type of _sqlserver appexp : ty is ty SQL.server. ty must be a record type representing a database schema as described in Section 22.1.3.

The following syntax are retained for backward compatibility, but it is discouraged to use them in a new program:

  • appexp may be omitted. If omitted, the PostgreSQL server with the default connection parameter is selected.

  • appexp may be a string literal. If so, the string is interpreted as a connection parameter to a PostgreSQL server.