Documentation ¶
Index ¶
Constants ¶
Variables ¶
var DriverMSSQL = "mssql"
DriverMSSQL uses the https://github.com/denisenkom/go-mssqldb library. This is the driver for this package.
var DriverODBC = "odbc"
DriverODBC uses the https://github.com/alexbrainman/odbc library
var ErrInvalidEncrypt = errors.New("invalid encrypt: expected (blank), Optional, Yes, No, Mandatory, or Strict")
https://learn.microsoft.com/en-us/troubleshoot/sql/connect/certificate-chain-not-trusted?tabs=odbc-driver-18x https://techcommunity.microsoft.com/t5/sql-server-blog/odbc-driver-18-0-for-sql-server-released/ba-p/3169228 https://learn.microsoft.com/en-us/sql/connect/odbc/windows/release-notes-odbc-sql-server-windows?view=sql-server-ver16
Functions ¶
func Open ¶
Open connects to a SQL Server. It accepts "host[\instance]", "host:port", or "host,port".
func QuoteName ¶
QuoteName wraps a string in [brackets]. It tries to match the functionality of SQL Server's QUOTENAME()
func QuoteString ¶
QuoteString wraps a string in single-quotes and tries to handle embedded quotes
Types ¶
type Connection ¶
type Connection struct { // Driver sets the GO driver that will be used. // Leaving this blank defaults to DriverMSSQL (the native GO driver). Driver string FQDN string User string Password string Database string Application string DialTimeout int ConnectTimeout int ODBCDriver string Encrypt string }
Connection is the basis for building connection strings
func NewConnection ¶
func NewConnection(server, user, password, database, app string) Connection
NewConnection returns a connection with sane defaults. You can specify the server "host[\instance]", "host:port", or "host,port" format.
func (Connection) Computer ¶
func (c Connection) Computer() string
Computer returns the computer (or host) name from FQDN
func (Connection) Instance ¶
func (c Connection) Instance() string
Instance returns the instance from FQDN
func (Connection) Open ¶
func (c Connection) Open() (*sql.DB, error)
Open connects to the SQL Server
func (Connection) Port ¶
func (c Connection) Port() int
Port returns the port from FQDN. It returns 0 if no port.
func (Connection) Redacted ¶
func (c Connection) Redacted(n int) string
Redacted returns a connection string with the password replaced with "redacted". Optionally, you can specify how many characters of the password to include
func (Connection) ServerName ¶
func (c Connection) ServerName() string
ServerName buids a string in the format server\instance or server:host. Most likely you won't have an instance and a port. Plus I don't think that works. This should be roughly what it tries to connect to.
func (Connection) String ¶
func (c Connection) String() string
String returns a connection string for the given connection. Setting Driver to an invalid type returns an unusable connection string but not an error. It should be caught on Open
type Server ¶
type Server struct { // Name holds the result of @@SERVERNAME Name string Computer string Instance string Domain string DNSSuffix string FQDN string EngineEdition int ProductVersion string ProductMajorVersion int }
Server holds information about an instance of SQL Server
type Session ¶
type Session struct { Server string `db:"atat_server_name"` ID int `db:"session_id"` ConnectTime time.Time `db:"connect_time"` LoginTime time.Time `db:"login_time"` ClientInterface string `db:"client_interface_name"` ClientVersion int `db:"client_version"` AuthScheme string `db:"auth_scheme"` Application string Login string Database string }
Session stores information about the connection to SQL Server