Documentation ¶
Overview ¶
package mssql implements the TDS protocol used to connect to MS SQL Server (sqlserver) database servers.
This package registers two drivers:
sqlserver: uses native "@" parameter placeholder names and does no pre-processing. mssql: expects identifiers to be prefixed with ":" and pre-processes queries.
If the ordinal position is used for query parameters, identifiers will be named "@p1", "@p2", ... "@pN".
Please refer to the README for the format of the DSN.
Index ¶
- Constants
- Variables
- func CopyIn(table string, options MssqlBulkOptions, columns ...string) string
- func NewTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn
- func SetLogger(logger Logger)
- type Auth
- type DataValue
- type Decimal
- type Error
- func (e Error) Error() string
- func (e Error) SQLErrorClass() uint8
- func (e Error) SQLErrorLineNo() int32
- func (e Error) SQLErrorMessage() string
- func (e Error) SQLErrorNumber() int32
- func (e Error) SQLErrorProcName() string
- func (e Error) SQLErrorServerName() string
- func (e Error) SQLErrorState() uint8
- type KeySlice
- type Logger
- type MssqlBulk
- type MssqlBulkOptions
- type MssqlConn
- func (c *MssqlConn) Begin() (driver.Tx, error)
- func (c *MssqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *MssqlConn) Close() error
- func (c *MssqlConn) Commit() error
- func (cn *MssqlConn) CreateBulk(table string, columns []string) (_ *MssqlBulk)
- func (c *MssqlConn) Ping(ctx context.Context) error
- func (c *MssqlConn) Prepare(query string) (driver.Stmt, error)
- func (c *MssqlConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *MssqlConn) Rollback() error
- type MssqlDriver
- type MssqlResult
- type MssqlRows
- func (rc *MssqlRows) Close() error
- func (r *MssqlRows) ColumnTypeDatabaseTypeName(index int) string
- func (r *MssqlRows) ColumnTypeLength(index int) (int64, bool)
- func (r *MssqlRows) ColumnTypeNullable(index int) (nullable, ok bool)
- func (r *MssqlRows) ColumnTypePrecisionScale(index int) (int64, int64, bool)
- func (r *MssqlRows) ColumnTypeScanType(index int) reflect.Type
- func (rc *MssqlRows) Columns() (res []string)
- func (rc *MssqlRows) HasNextResultSet() bool
- func (rc *MssqlRows) Next(dest []driver.Value) error
- func (rc *MssqlRows) NextResultSet() error
- type MssqlStmt
- func (s *MssqlStmt) Close() error
- func (s *MssqlStmt) Exec(args []driver.Value) (driver.Result, error)
- func (s *MssqlStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *MssqlStmt) NumInput() int
- func (s *MssqlStmt) Query(args []driver.Value) (driver.Rows, error)
- func (s *MssqlStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- func (s *MssqlStmt) QueryMeta() (cols []columnStruct, err error)
- func (s *MssqlStmt) SetQueryNotification(id, options string, timeout time.Duration)
- type NTLMAuth
- type Param
- type ProcId
- type SerializableBulkConfig
- type StreamError
- type UniqueIdentifier
Constants ¶
const ( NEGOTIATE_MESSAGE = 1 CHALLENGE_MESSAGE = 2 AUTHENTICATE_MESSAGE = 3 )
const ( NEGOTIATE_UNICODE = 0x00000001 NEGOTIATE_OEM = 0x00000002 NEGOTIATE_TARGET = 0x00000004 NEGOTIATE_SIGN = 0x00000010 NEGOTIATE_SEAL = 0x00000020 NEGOTIATE_DATAGRAM = 0x00000040 NEGOTIATE_LMKEY = 0x00000080 NEGOTIATE_NTLM = 0x00000200 NEGOTIATE_ANONYMOUS = 0x00000800 NEGOTIATE_OEM_DOMAIN_SUPPLIED = 0x00001000 NEGOTIATE_OEM_WORKSTATION_SUPPLIED = 0x00002000 NEGOTIATE_ALWAYS_SIGN = 0x00008000 NEGOTIATE_TARGET_TYPE_DOMAIN = 0x00010000 NEGOTIATE_TARGET_TYPE_SERVER = 0x00020000 NEGOTIATE_EXTENDED_SESSIONSECURITY = 0x00080000 NEGOTIATE_IDENTIFY = 0x00100000 REQUEST_NON_NT_SESSION_KEY = 0x00400000 NEGOTIATE_TARGET_INFO = 0x00800000 NEGOTIATE_VERSION = 0x02000000 NEGOTIATE_128 = 0x20000000 NEGOTIATE_KEY_EXCH = 0x40000000 NEGOTIATE_56 = 0x80000000 )
const NEGOTIATE_FLAGS = NEGOTIATE_UNICODE | NEGOTIATE_NTLM | NEGOTIATE_OEM_DOMAIN_SUPPLIED | NEGOTIATE_OEM_WORKSTATION_SUPPLIED | NEGOTIATE_ALWAYS_SIGN | NEGOTIATE_EXTENDED_SESSIONSECURITY
const PLP_NULL = 0xFFFFFFFFFFFFFFFF
const PLP_TERMINATOR = 0x00000000
const UNKNOWN_PLP_LEN = 0xFFFFFFFFFFFFFFFE
Variables ¶
var ( Sp_Cursor = ProcId{1, ""} Sp_CursorOpen = ProcId{2, ""} Sp_CursorPrepare = ProcId{3, ""} Sp_CursorExecute = ProcId{4, ""} Sp_CursorPrepExec = ProcId{5, ""} Sp_CursorUnprepare = ProcId{6, ""} Sp_CursorFetch = ProcId{7, ""} Sp_CursorOption = ProcId{8, ""} Sp_CursorClose = ProcId{9, ""} Sp_ExecuteSql = ProcId{10, ""} Sp_Prepare = ProcId{11, ""} Sp_PrepExec = ProcId{13, ""} Sp_PrepExecRpc = ProcId{14, ""} Sp_Unprepare = ProcId{15, ""} )
Functions ¶
Types ¶
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
http://msdn.microsoft.com/en-us/library/ee780893.aspx
func Float64ToDecimal ¶
func (Decimal) UnscaledBytes ¶
type Error ¶
type Error struct { Number int32 State uint8 Class uint8 Message string ServerName string ProcName string LineNo int32 }
Error represents an SQL Server error. This type includes methods for reading the contents of the struct, which allows calling programs to check for specific error conditions without having to import this package directly.
func (Error) SQLErrorClass ¶
func (Error) SQLErrorLineNo ¶
func (Error) SQLErrorMessage ¶
func (Error) SQLErrorNumber ¶
SQLErrorNumber returns the SQL Server error number.
func (Error) SQLErrorProcName ¶
func (Error) SQLErrorServerName ¶
func (Error) SQLErrorState ¶
type Logger ¶
type Logger interface { Printf(format string, v ...interface{}) Println(v ...interface{}) }
type MssqlBulk ¶
type MssqlBulk struct { Options MssqlBulkOptions Debug bool // contains filtered or unexported fields }
type MssqlBulkOptions ¶
type MssqlConn ¶
type MssqlConn struct {
// contains filtered or unexported fields
}
func (*MssqlConn) CreateBulk ¶
func (*MssqlConn) Ping ¶
Ping is used to check if the remote server is available and satisfies the Pinger interface.
func (*MssqlConn) PrepareContext ¶
type MssqlDriver ¶
type MssqlDriver struct {
// contains filtered or unexported fields
}
func (*MssqlDriver) OpenConnection ¶
func (d *MssqlDriver) OpenConnection(dsn string) (*MssqlConn, error)
func (*MssqlDriver) SetLogger ¶
func (d *MssqlDriver) SetLogger(logger Logger)
type MssqlResult ¶
type MssqlResult struct {
// contains filtered or unexported fields
}
func (*MssqlResult) LastInsertId ¶
func (r *MssqlResult) LastInsertId() (int64, error)
func (*MssqlResult) RowsAffected ¶
func (r *MssqlResult) RowsAffected() (int64, error)
type MssqlRows ¶
type MssqlRows struct {
// contains filtered or unexported fields
}
func (*MssqlRows) ColumnTypeDatabaseTypeName ¶
RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return the database system type name without the length. Type names should be uppercase. Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT", "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML", "TIMESTAMP".
func (*MssqlRows) ColumnTypeLength ¶
RowsColumnTypeLength may be implemented by Rows. It should return the length of the column type if the column is a variable length type. If the column is not a variable length type ok should return false. If length is not limited other than system limits, it should return math.MaxInt64. The following are examples of returned values for various types:
TEXT (math.MaxInt64, true) varchar(10) (10, true) nvarchar(10) (10, true) decimal (0, false) int (0, false) bytea(30) (30, true)
func (*MssqlRows) ColumnTypeNullable ¶
The nullable value should be true if it is known the column may be null, or false if the column is known to be not nullable. If the column nullability is unknown, ok should be false.
func (*MssqlRows) ColumnTypePrecisionScale ¶
It should return the precision and scale for decimal types. If not applicable, ok should be false. The following are examples of returned values for various types:
decimal(38, 4) (38, 4, true) int (0, 0, false) decimal (math.MaxInt64, math.MaxInt64, true)
func (*MssqlRows) ColumnTypeScanType ¶
It should return the value type that can be used to scan types into. For example, the database column type "bigint" this should return "reflect.TypeOf(int64(0))".
func (*MssqlRows) HasNextResultSet ¶
func (*MssqlRows) NextResultSet ¶
type MssqlStmt ¶
type MssqlStmt struct {
// contains filtered or unexported fields
}
func (*MssqlStmt) ExecContext ¶
func (*MssqlStmt) QueryContext ¶
type NTLMAuth ¶
func (*NTLMAuth) InitialBytes ¶
type SerializableBulkConfig ¶
type SerializableBulkConfig struct { TableName string ColumnsName []string Options MssqlBulkOptions }
type StreamError ¶
type StreamError struct {
Message string
}
func (StreamError) Error ¶
func (e StreamError) Error() string
type UniqueIdentifier ¶
type UniqueIdentifier [16]byte
func (*UniqueIdentifier) Scan ¶
func (u *UniqueIdentifier) Scan(v interface{}) error
func (UniqueIdentifier) String ¶
func (u UniqueIdentifier) String() string
Source Files ¶
- buf.go
- bulkcopy.go
- bulkcopy_sql.go
- charset.go
- collation.go
- cp1250.go
- cp1251.go
- cp1252.go
- cp1253.go
- cp1254.go
- cp1255.go
- cp1256.go
- cp1257.go
- cp1258.go
- cp437.go
- cp850.go
- cp874.go
- cp932.go
- cp936.go
- cp949.go
- cp950.go
- decimal.go
- doc.go
- error.go
- log.go
- mssql.go
- mssql_go1.3.go
- mssql_go18.go
- net.go
- ntlm.go
- parser.go
- rpc.go
- tds.go
- token.go
- token_string.go
- tran.go
- types.go
- uniqueidentifier.go