Documentation ¶
Overview ¶
Package freetds provides interface to Microsoft Sql Server database by using freetds C lib: http://www.freetds.org.
Index ¶
- Constants
- type Conn
- func (conn *Conn) Begin() error
- func (conn *Conn) Close()
- func (conn *Conn) Commit() error
- func (conn *Conn) DbUse() error
- func (conn *Conn) Exec(sql string) ([]*Result, error)
- func (conn *Conn) ExecSp(spName string, params ...interface{}) (*SpResult, error)
- func (conn *Conn) ExecuteSql(query string, params ...driver.Value) ([]*Result, error)
- func (conn *Conn) Rollback() error
- func (conn *Conn) SelectValue(sql string) (interface{}, error)
- type ConnPool
- type MssqlConn
- type MssqlConnTx
- type MssqlDriver
- type MssqlResult
- type MssqlRows
- type MssqlStmt
- type Result
- type ResultColumn
- type SpOutputParam
- type SpResult
Constants ¶
const ( //name database type go type SYBINT1 = 48 //tinyint uint8 SYBINT2 = 52 //smallint int16 SYBINT4 = 56 //int int32 SYBINT8 = 127 //bigint int64 SYBCHAR = 47 SYBVARCHAR = 39 //varchar string SYBNVARCHAR = 103 //nvarchar string XSYBNVARCHAR = 231 //nvarchar string XSYBNCHAR = 239 //nchar string SYBREAL = 59 //real float32 SYBFLT8 = 62 //float(53) float64 SYBBIT = 50 //bit bool SYBBITN = 104 //bit bool SYBMONEY4 = 122 //smallmoney float64 SYBMONEY = 60 //money float64 SYBDATETIME = 61 //datetime time.Time SYBDATETIME4 = 58 //smalldatetime time.Time SYBIMAGE = 34 //image []byte SYBBINARY = 45 //binary []byte SYBVARBINARY = 37 //varbinary []byte XSYBVARBINARY = 165 //varbinary []byte )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Connection to the database.
func ConnectWithConnectionString ¶
Connect to the database with connection string, returns new connection or error. Example:
conn, err := ConnectWithConnectionString("host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword;mirror=myMirror")
Mirror is optional, other params are mandatory.
func (*Conn) Close ¶
func (conn *Conn) Close()
If conn belongs to pool release connection to the pool. If not close connection.
func (*Conn) ExecSp ¶
Execute stored procedure by name and list of params.
Example:
conn.ExecSp("sp_help", "authors")
func (*Conn) ExecuteSql ¶
Execute sql query with arguments. ? in query are arguments placeholders.
ExecuteSql("select * from authors where au_fname = ?", "John")
func (*Conn) SelectValue ¶
Query database and return first column in the first row as result.
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool - connection pool for the maxCount connections.
Connection can be acquired from the pool by pool.Get().
Release conn to the pool by caling conn.Close() or pool.Release(conn).
Destroy pool and all connections by calling pool.Close().
Connections will be removed from the pool if not active for poolExpiresInterval. But there is always one connection in the pool.
Example:
pool, err := NewConnPool("host=myServerA;database=myDataBase;user=myUsername;pwd=myPassword", 100) ... conn, err := pool.Get() //use conn conn.Close() ... pool.Close()
func NewConnPool ¶
NewCoonPool creates new connection pool. Connection will be created using provided connection string. MaxConn is max number of connections in the pool.
New connections will be created when needed. There is always one connection in the pool.
Returns err if fails to create initial connection.
func (*ConnPool) Close ¶
func (p *ConnPool) Close()
Close connection pool. Closes all existing connections in the pool.
type MssqlConn ¶
type MssqlConn struct {
// contains filtered or unexported fields
}
implements Conn interface from http://golang.org/src/pkg/database/sql/driver/driver.go
func (*MssqlConn) Begin ¶
implements Begin for Conn interface from http://golang.org/src/pkg/database/sql/driver/driver.go
func (*MssqlConn) Close ¶
implements Close for Conn interface from http://golang.org/src/pkg/database/sql/driver/driver.go
type MssqlConnTx ¶
type MssqlConnTx struct {
// contains filtered or unexported fields
}
implements Tx interface from http://golang.org/src/pkg/database/sql/driver/driver.go
func (*MssqlConnTx) Commit ¶
func (t *MssqlConnTx) Commit() error
implements Commit for Tx interface from http://golang.org/src/pkg/database/sql/driver/driver.go
func (*MssqlConnTx) Rollback ¶
func (t *MssqlConnTx) Rollback() error
implements Rollback for Tx interface from http://golang.org/src/pkg/database/sql/driver/driver.go
type MssqlDriver ¶
type MssqlDriver struct{}
implements Driver interface from http://golang.org/src/pkg/database/sql/driver/driver.go
func (*MssqlDriver) Open ¶
func (d *MssqlDriver) Open(dsn string) (driver.Conn, error)
implements Open for Driver interface from http://golang.org/src/pkg/database/sql/driver/driver.go
type MssqlResult ¶
type MssqlResult struct {
// contains filtered or unexported fields
}
implements Result interface from http://golang.org/src/pkg/database/sql/driver/driver.go
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
}
implements Rows interface from http://golang.org/src/pkg/database/sql/driver/driver.go
type MssqlStmt ¶
type MssqlStmt struct {
// contains filtered or unexported fields
}
implements Stmt interface from http://golang.org/src/pkg/database/sql/driver/driver.go
type Result ¶
type Result struct { Columns []*ResultColumn Rows [][]interface{} ReturnValue int RowsAffected int Message string // contains filtered or unexported fields }
type SpOutputParam ¶
type SpOutputParam struct { Name string Value interface{} }
Stored procedure output parameter name and value.
type SpResult ¶
type SpResult struct { Results []*Result Status int OutputParams []*SpOutputParam }
Stored procedure execution result.
func (*SpResult) HasOutputParams ¶
Does the stored procedure has any output params.
func (*SpResult) HasResults ¶
Does the stored procedure returned any resultsets.