Available

amalgame-mssql

MS SQL Server via ODBC and the Microsoft driver.

amc package add mssql GitHub ↗ ← Back to the ecosystem

Overview

Binding to MS SQL Server. Compatible with SQL Server 2017+ and Azure SQL. Dynamic link to unixODBC and Microsoft's official ODBC driver (ODBC Driver 18 or 17), which handles the TDS protocol.

Features

  • ✓Target: SQL Server 2017+ and Azure SQL Database
  • ✓Microsoft ODBC Driver 18 (or 17), picked in the connection string
  • ✓? parameters with ExecBind / QueryBindAll, Begin / Commit / Rollback transactions
  • ✓TLS set in the connection string (Encrypt=yes), handled by the driver
  • ✓Dynamic-link pattern — no vendored fork

Planned

  • ◐Prepared-statement reuse
  • ◐Typed column accessors: today every cell comes back as text
  • ◐Bulk insert (bcp) and async queries
  • ◐Table-valued parameters (TVP)

Example

Minimal usage example — copy-paste runnable after install.

import Amalgame.Database.MSSQL

public class Program {
    public static void Main() {
        let db = MSSQL.Open("Driver={ODBC Driver 18 for SQL Server};"
            + "Server=tcp:db.example.com,1433;Database=app;UID=app;PWD=secret;Encrypt=yes")
        if (!MSSQL.IsOpen(db)) {
            Console.WriteLine("connect failed: " + MSSQL.LastError(db))
            return
        }
        let params = new List<string>()
        params.Add("42")
        let rows = MSSQL.QueryBindAll(db, "SELECT id, total FROM orders WHERE customer_id = ?", params)
        for row in rows {
            Console.WriteLine(row.Get(0) + " : " + row.Get(1))
        }
        MSSQL.Close(db)
    }
}

At a glance

Related packages