mssqlodbc

package module
v0.0.0-...-e7ee662 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2023 License: MIT Imports: 5 Imported by: 0

README

mssqlodbc

A simple helper library for GO MSSQL ODBC connections. This has been tested with https://github.com/alexbrainman/odbc

cxn := Connection{
    Server:              "localhost\\SQL2014",
    Database:            "tempdb",
    AppName:             "gosql",
    Trusted:             true,
    MultiSubnetFailover: true,
}

s, err := cxn.ConnectionString()
if err != nil {
    return err
}

db, err := sql.Open("odbc", s)
if err != nil {
    return err
}
defer db.Close()

Includes the following features:

  • List the valid drivers installed
  • Select the "best" driver based on my subjective ranking of them
  • Parse a SQL Server ODBC connection string into a Connection

Includes support for:

  • The generic SQL Server ODBC driver
  • The SQL Server ODBC Driver v11, v13, v17, v18
  • The SQL Server Native Client ODBC driver v10 and v11

Documentation

Index

Constants

View Source
const (
	// NativeClient11 is an Native SQL Server Driver version 11
	NativeClient11 string = "SQL Server Native Client 11.0"

	// NativeClient10 is an Native SQL Server Driver version 10
	NativeClient10 string = "SQL Server Native Client 10.0"

	// ODBC18 is an ODBC SQL Server Driver version 18
	ODBC18 string = "ODBC Driver 18 for SQL Server"

	// ODBC17 is an ODBC SQL Server Driver version 17
	ODBC17 string = "ODBC Driver 17 for SQL Server"

	// ODBC13 is an ODBC SQL Server Driver version 13
	ODBC13 string = "ODBC Driver 13 for SQL Server"

	// ODBC11 is an ODBC SQL Server Driver version 11
	ODBC11 string = "ODBC Driver 11 for SQL Server"

	// GenericODBC is the Generic ODBC SQL Server driver
	GenericODBC string = "SQL Server"
)
View Source
const (
	EncryptYes       string = "Yes"
	EncryptMandatory string = "Mandatory"
	EncryptNo        string = "No"
	EncryptOptional  string = "Optional"
	EncryptStrict    string = "Strict"
)

Variables

View Source
var ErrInvalidDriver = errors.New("invalid driver")

ErrInvalidDriver indiates that an ODBC SQL Server driver is invalid

View Source
var ErrInvalidEncrypt = errors.New("invalid encrypt: expected (blank), Optional, Yes, No, Mandatory, Strict")
View Source
var ErrNoDrivers = errors.New("no odbc drivers found")

ErrNoDrivers is returned if no valid ODBC SQL Server drivers are found

Functions

func BestDriver

func BestDriver() (string, error)

BestDriver returns the "best" driver installed on the machine

func InstalledDrivers

func InstalledDrivers() ([]string, error)

InstalledDrivers returns the available SQL Server drivers on the computer

func ValidDriver

func ValidDriver(d string) error

ValidDriver tests if a string is a valid SQL Server Driver on this machine

Types

type Connection

type Connection struct {
	Server              string
	User                string
	Password            string
	Trusted             bool
	AppName             string
	Database            string
	Encrypt             string
	MultiSubnetFailover bool
	// contains filtered or unexported fields
}

Connection holds information about an ODBC SQL Server connection

func Parse

func Parse(s string) (Connection, error)

Parse converts a connection string into a Connection

func (*Connection) ConnectionString

func (c *Connection) ConnectionString() (string, error)

ConnectionString returns a connection string

func (*Connection) Driver

func (c *Connection) Driver() string

Driver gets the driver for the connection

func (*Connection) SetDriver

func (c *Connection) SetDriver(d string) error

SetDriver sets the driver for a connection

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL