Documentation ¶
Overview ¶
package mssql implements the TDS protocol used to connect to MS SQL Server (sqlserver) database servers.
This package registers the driver:
sqlserver: uses native "@" parameter placeholder names and does no pre-processing.
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. There are multiple DSN formats accepted: ADO style, ODBC style, and URL style. The following is an example of a URL style DSN:
sqlserver://sa:mypass@localhost:1234?database=master&connection+timeout=30
Index ¶
- func CopyIn(table string, options BulkOptions, columns ...string) string
- func SetLogger(logger Logger)
- type Bulk
- type BulkOptions
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error
- func (c *Conn) Close() error
- func (c *Conn) Commit() error
- func (cn *Conn) CreateBulk(table string, columns []string) (_ *Bulk)
- func (cn *Conn) CreateBulkContext(ctx context.Context, table string, columns []string) (_ *Bulk)
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *Conn) ResetSession(ctx context.Context) error
- func (c *Conn) Rollback() error
- type Connector
- type DataValue
- type DateTime1
- type DateTimeOffset
- type Decimal
- type Driver
- 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 Logger
- type MssqlBulk
- type MssqlBulkOptions
- type MssqlConn
- type MssqlDriver
- type MssqlResult
- type MssqlRows
- type MssqlStmt
- type NVarCharMax
- type Result
- type Rows
- func (rc *Rows) Close() error
- func (r *Rows) ColumnTypeDatabaseTypeName(index int) string
- func (r *Rows) ColumnTypeLength(index int) (int64, bool)
- func (r *Rows) ColumnTypeNullable(index int) (nullable, ok bool)
- func (r *Rows) ColumnTypePrecisionScale(index int) (int64, int64, bool)
- func (r *Rows) ColumnTypeScanType(index int) reflect.Type
- func (rc *Rows) Columns() (res []string)
- func (rc *Rows) HasNextResultSet() bool
- func (rc *Rows) Next(dest []driver.Value) error
- func (rc *Rows) NextResultSet() error
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- func (s *Stmt) SetQueryNotification(id, options string, timeout time.Duration)
- type StreamError
- type UniqueIdentifier
- type VarChar
- type VarCharMax
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bulk ¶
type Bulk struct { Options BulkOptions Debug bool // contains filtered or unexported fields }
type BulkOptions ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) CheckNamedValue ¶
func (c *Conn) CheckNamedValue(nv *driver.NamedValue) error
func (*Conn) CreateBulkContext ¶
func (*Conn) Ping ¶
Ping is used to check if the remote server is available and satisfies the Pinger interface.
func (*Conn) PrepareContext ¶
type Connector ¶
type Connector struct { // SessionInitSQL is executed after marking a given session to be reset. // When not present, the next query will still reset the session to the // database defaults. // // When present the connection will immediately mark the session to // be reset, then execute the SessionInitSQL text to setup the session // that may be different from the base database defaults. // // For Example, the application relies on the following defaults // but is not allowed to set them at the database system level. // // SET XACT_ABORT ON; // SET TEXTSIZE -1; // SET ANSI_NULLS ON; // SET LOCK_TIMEOUT 10000; // // SessionInitSQL should not attempt to manually call sp_reset_connection. // This will happen at the TDS layer. // // SessionInitSQL is optional. The session will be reset even if // SessionInitSQL is empty. SessionInitSQL string // contains filtered or unexported fields }
Connector holds the parsed DSN and is ready to make a new connection at any time.
In the future, settings that cannot be passed through a string DSN may be set directly on the connector.
func NewConnector ¶
NewConnector creates a new connector from a DSN. The returned connector may be used with sql.OpenDB.
type DateTimeOffset ¶
DateTimeOffset encodes parameters to DateTimeOffset, preserving the UTC offset.
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 Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) OpenConnector ¶
OpenConnector opens a new connector. Useful to dial with a context.
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 = Bulk // Deprecated: users should transition to the new name when possible.
type MssqlBulkOptions ¶
type MssqlBulkOptions = BulkOptions // Deprecated: users should transition to the new name when possible.
type MssqlConn ¶
type MssqlConn = Conn // Deprecated: users should transition to the new name when possible.
type MssqlDriver ¶
type MssqlDriver = Driver // Deprecated: users should transition to the new name when possible.
type MssqlResult ¶
type MssqlResult = Result // Deprecated: users should transition to the new name when possible.
type MssqlRows ¶
type MssqlRows = Rows // Deprecated: users should transition to the new name when possible.
type MssqlStmt ¶
type MssqlStmt = Stmt // Deprecated: users should transition to the new name when possible.
type NVarCharMax ¶
type NVarCharMax string
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func (*Result) LastInsertId ¶
func (*Result) RowsAffected ¶
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
func (*Rows) 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 (*Rows) 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 (*Rows) 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 (*Rows) 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 (*Rows) 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 (*Rows) HasNextResultSet ¶
func (*Rows) NextResultSet ¶
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
func (*Stmt) ExecContext ¶
func (*Stmt) QueryContext ¶
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
type VarCharMax ¶
type VarCharMax string