亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結構heap) container/list(容器數(shù)據(jù)結構list) container/ring(容器數(shù)據(jù)結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "database/sql/driver"

  • 概述

  • 索引

概述

軟件包驅(qū)動程序定義由 sql 包使用的數(shù)據(jù)庫驅(qū)動程序?qū)崿F(xiàn)的接口。

大多數(shù)代碼應該使用 sql包 。

索引

  • 變量(Variables)

  • func IsScanValue(v interface{}) bool

  • func IsValue(v interface{}) bool

  • type ColumnConverter

  • type Conn

  • type ConnBeginTx

  • type ConnPrepareContext

  • type Driver

  • type Execer

  • type ExecerContext

  • type IsolationLevel

  • type NamedValue

  • type NamedValueChecker

  • type NotNull

  • func (n NotNull) ConvertValue(v interface{}) (Value, error)

  • type Null

  • func (n Null) ConvertValue(v interface{}) (Value, error)

  • type Pinger

  • type Queryer

  • type QueryerContext

  • type Result

  • type Rows

  • type RowsAffected

  • func (RowsAffected) LastInsertId() (int64, error)

  • func (v RowsAffected) RowsAffected() (int64, error)

  • type RowsColumnTypeDatabaseTypeName

  • type RowsColumnTypeLength

  • type RowsColumnTypeNullable

  • type RowsColumnTypePrecisionScale

  • type RowsColumnTypeScanType

  • type RowsNextResultSet

  • type Stmt

  • type StmtExecContext

  • type StmtQueryContext

  • type Tx

  • type TxOptions

  • type Value

  • type ValueConverter

  • type Valuer

包文件

driver.go types.go

變量

Bool 是一個將輸入值轉(zhuǎn)換為布爾值的 ValueConverter。

轉(zhuǎn)換規(guī)則是:

 - 布爾值不變- 對于整數(shù)類型,     1是真的     0是假的,
     其他整數(shù)是一個錯誤- 對于字符串和[]字節(jié),與strconv.ParseBool相同的規(guī)則- 所有其他類型都是錯誤的
var Bool boolType

DefaultParameterConverter 是當 Stmt 沒有實現(xiàn)ColumnConverter 時使用的 ValueConverter 的默認實現(xiàn)。

如果是 IsValue(arg),DefaultParameterConverter 直接返回它的參數(shù)。否則,如果參數(shù)實現(xiàn)了 Valuer,則其 Value 方法用于返回值。作為回退,所提供的參數(shù)的基礎類型用于將其轉(zhuǎn)換為值:基礎整數(shù)類型轉(zhuǎn)換為 int64,浮動到 float64,bool,string 和 []byte。如果參數(shù)是一個零指針,ConvertValue 返回一個零值。如果參數(shù)是一個非零指針,則將其解除引用,并且遞歸地調(diào)用 ConvertValue 。其他類型是錯誤的。

var DefaultParameterConverter defaultConverter

ErrBadConn 應由驅(qū)動程序返回以向 sql 包發(fā)出信號,指出driver.Conn 處于不良狀態(tài)(例如服務器先前已關閉連接),并且 sql 包應該在新連接上重試。

為防止重復操作,如果數(shù)據(jù)庫服務器可能執(zhí)行了操作,則不應返回 ErrBadConn。即使服務器發(fā)回錯誤,也不應返回 ErrBadConn。

var ErrBadConn = errors.New("driver: bad connection")

可以從 NamedValueChecker 返回 ErrRemoveArgument 以指示 sql 包不將參數(shù)傳遞給驅(qū)動程序查詢接口。當接受查詢特定選項或不是 SQL 查詢參數(shù)的結構時返回。

var ErrRemoveArgument = errors.New("driver: remove argument from query")

ErrSkip 可能會由一些可選接口的方法返回,以在運行時指示快速路徑不可用,并且 sql 包應繼續(xù),就好像可選接口未實現(xiàn)一樣。ErrSkip 僅在明確記錄的情況下才受支持。

var ErrSkip = errors.New("driver: skip fast-path; continue as if unimplemented")

Int32 是一個 ValueConverter,它將輸入值轉(zhuǎn)換為 int64 ,并考慮到 int32 值的限制。

var Int32 int32Type

ResultNoRows 是驅(qū)動程序在 DDL 命令(例如 CREATE TABLE)成功時返回的預定義結果。它為 LastInsertId 和RowsAffected 都返回一個錯誤。

var ResultNoRows noRows

字符串是一個將其輸入轉(zhuǎn)換為字符串的 ValueConverter。如果該值已經(jīng)是字符串或[]字節(jié),則不會改變。如果該值是另一種類型,則使用 fmt.Sprintf(“%v”,v)完成對字符串的轉(zhuǎn)換。

var String stringType

func IsScanValue

func IsScanValue(v interface{}) bool

IsScanValue 等同于 IsValue。它存在的兼容性。

func IsValue

func IsValue(v interface{}) bool

IsValue 報告 v 是否是有效的 Value 參數(shù)類型。

type ColumnConverter

如果語句知道它自己的列的類型并且可以從任何類型轉(zhuǎn)換為驅(qū)動程序的值,那么 ColumnConverter 可以選擇由 Stmt 實現(xiàn)。

不推薦使用:驅(qū)動程序應該實現(xiàn) NamedValueChecker 。

type ColumnConverter interface {        // ColumnConverter為所提供的返回一個ValueConverter        // 列索引(column index)。 如果特定列的類型未知        // 或者不應該專門處理,DefaultValueConverter        // 可以返回。        ColumnConverter(idx int) ValueConverter}

type Conn

Conn 是與數(shù)據(jù)庫的連接。它不是由多個 goroutine 同時使用。

Conn 被認為是有狀態(tài)的。

type Conn interface {        // Prepare返回一個準備好的語句,綁定到這個連接。        Prepare(query string) (Stmt, error)        // Close無效并可能停止任何當前        // 準備好的陳述和交易,標記這一點        // 連接不再使用。        //        // 因為sql包維護著一個空閑的池        // 連接和只有調(diào)用在有剩余時關閉        // 空閑的連接,它不應該是驅(qū)動程序需要        // 做自己的連接緩存。        Close() error        // 開始并返回一個新的事務。        //        // 不推薦使用:驅(qū)動程序應該(或另外)實現(xiàn)ConnBeginTx。        Begin() (Tx, error)}

type ConnBeginTx

ConnBeginTx 通過上下文和 TxOptions 增強了 Conn 接口。

type ConnBeginTx interface {        // BeginTx啟動并返回一個新的事務。        // 如果上下文被用戶取消,那么sql包會        // 在丟棄和關閉連接之前調(diào)用Tx.Rollback。        //        // 這必須檢查opts.Isolation以確定是否有一個集合        // 隔離級別。 如果驅(qū)動程序不支持非默認        // 級別和一個設置,或者如果有一個非默認的隔離級別        // 如果不支持,則必須返回錯誤。        //        // 這還必須檢查opts.ReadOnly以確定是否只讀        // 如果支持,則設置只讀事務屬性的值為true        // 或者如果不支持則返回錯誤。        BeginTx(ctx context.Context, opts TxOptions) (Tx, error)}

type ConnPrepareContext

ConnPrepareContext 通過上下文增強了 Conn 接口。

type ConnPrepareContext interface {        // PrepareContext返回一個準備好的語句,綁定到這個連接。        // context是編寫聲明,        // 它不能在語句本身內(nèi)存儲上下文。        PrepareContext(ctx context.Context, query string) (Stmt, error)}

type Driver

驅(qū)動程序是必須由數(shù)據(jù)庫驅(qū)動程序?qū)崿F(xiàn)的接口。

type Driver interface {        // 打開返回到數(shù)據(jù)庫的新連接。        // 該名稱是一個驅(qū)動程序特定格式的字符串。        //        // 打開可能會返回一個緩存的連接(之前一個        // 關閉),但這樣做是不必要的; sql包        // 維護一個空閑連接池以便有效地重用。        //        // 返回的連接僅由時間的一個goroutine使用        // 時間。        Open(name string) (Conn, error)}

type Execer

Execer 是一個可選接口,可由 Conn 實施。

如果 Conn 沒有實現(xiàn) Execer,那么 sql 包的 DB.Exec 將首先準備一個查詢,執(zhí)行該語句,然后關閉該語句。

Exec 可能會返回 ErrSkip。

棄用:驅(qū)動程序應該實現(xiàn) ExecerContext (或另外)。

type Execer interface {        Exec(query string, args []Value) (Result, error)}

type ExecerContext

ExecerContext 是一個可以由 Conn 實現(xiàn)的可選接口。

如果 Conn 沒有實現(xiàn) ExecerContext,sql 包的 DB.Exec 將首先準備一個查詢,執(zhí)行該語句,然后關閉該語句。

ExecerContext 可能會返回 ErrSkip。

ExecerContext 必須遵守上下文超時并在上下文被取消時返回。

type ExecerContext interface {        ExecContext(ctx context.Context, query string, args []NamedValue) (Result, error)}

type IsolationLevel

IsolationLeve l是存儲在 TxOptions 中的事務隔離級別。

這個類型應該被認為與 sql.IsolationLevel 以及在其上定義的任何值相同。

type IsolationLevel int

type NamedValue

NamedValue 包含值名稱和值。

type NamedValue struct {        // 如果名稱不是空的,它應該用于參數(shù)標識符和        // 而不是次序位置。        //        // 名稱不會有符號前綴。
        Name string        // 從一開始的參數(shù)序號位置始終設置。
        Ordinal int        // 值是參數(shù)值。
        Value Value}

type NamedValueChecker

NamedValueChecker 可以選擇由 Conn 或 Stmt 實現(xiàn)。它為驅(qū)動程序提供了更多的控制來處理 Go 和數(shù)據(jù)庫類型,超出了允許的默認值類型。

sql 包按以下順序檢查值檢查器,在第一個找到的匹配處停止:Stmt.NamedValueChecker,Conn.NamedValueChecker,Stmt.ColumnConverter,DefaultParameterConverter。

如果 CheckNamedValue 返回 ErrRemoveArgument,那么NamedValue 將不會包含在最終的查詢參數(shù)中。這可以用來將特殊選項傳遞給查詢本身。

如果返回 ErrSkip ,則列轉(zhuǎn)換器錯誤檢查路徑用于參數(shù)。駕駛員可能希望在用盡特殊情況后返回 ErrSkip。

type NamedValueChecker interface {        // 在將參數(shù)傳遞給驅(qū)動程序之前調(diào)用CheckNamedValue        // 并被調(diào)用來代替任何ColumnConverter。 CheckNamedValue必須輸入        // 驗證和轉(zhuǎn)換適合驅(qū)動程序。        CheckNamedValue(*NamedValue) error}

type NotNull

NotNull 是一種類型,它通過禁止 nil 值來實現(xiàn)ValueConverter,否則委托給另一個 ValueConverter。

type NotNull struct {
        Converter ValueConverter}

func (NotNull) ConvertValue

func (n NotNull) ConvertValue(v interface{}) (Value, error)

type Null

Null 是一種通過允許 nil 值實現(xiàn) ValueConverter 的類型,但是可以委托給另一個 ValueConverter。

type Null struct {
        Converter ValueConverter}

func (Null) ConvertValue

func (n Null) ConvertValue(v interface{}) (Value, error)

type Pinger

Pinger 是可由 Conn 實施的可選接口。

如果 Conn 沒有實現(xiàn) Pinger,則 sql 包的 DB.Ping 和DB.PingContext 將檢查是否至少有一個可用的 Conn。

如果 Conn.Ping 返回 ErrBadConn,則 DB.Ping 和DB.PingContext 將從池中移除 Conn。

type Pinger interface {        Ping(ctx context.Context) error}

type Queryer

Queryer 是一個可選的接口,可由 Conn 實施。

如果 Conn 沒有實現(xiàn) Queryer,那么 sql 包的 DB.Query 將首先準備一個查詢,執(zhí)行該語句,然后關閉該語句。

Query 可能會返回 ErrSkip。

棄用:驅(qū)動程序應該實現(xiàn) QueryerContext(或另外)。

type Queryer interface {        Query(query string, args []Value) (Rows, error)}

type QueryerContext

QueryerContext 是一個可選接口,可由 Conn實施。

如果 Conn 沒有實現(xiàn) QueryerContext,則 sql 包的 DB.Query將首先準備一個查詢,執(zhí)行該語句,然后關閉該語句。

QueryerContext 可能會返回 ErrSkip。

QueryerContext 必須遵守上下文超時并在上下文被取消時返回。

type QueryerContext interface {        QueryContext(ctx context.Context, query string, args []NamedValue) (Rows, error)}

type Result

結果是查詢執(zhí)行的結果。

type Result interface {        // LastInsertId返回數(shù)據(jù)庫的自動生成的ID        // 例如,在將一個INSERT插入到具有主要表的表中        // 鍵(key)。        LastInsertId() (int64, error)        // RowsAffected返回受下列影響的行數(shù)        RowsAffected() (int64, error)}

type Rows

行是對已執(zhí)行的查詢結果的迭代器。

type Rows interface {        // 列將返回列的名稱。 以下的數(shù)量        // 結果的列從長度推斷        // slice。 如果某個特定的列名未知,則為空        // 應該為該條目返回字符串。        Columns() []string        // Close關閉行迭代器。        Close() error        // 接下來被調(diào)用來填充下一行數(shù)據(jù)        // 提供的切片(slice)。 提供的切片將是相同的        // 大小與Columns()一樣寬。        //        // 當沒有更多行時,Next應返回io.EOF。        Next(dest []Value) error}

type RowsAffected

RowsAffected 實現(xiàn)了一個 INSERT 或 UPDATE 操作的 Result,該操作使多行變異。

type RowsAffected int64

func (RowsAffected) LastInsertId

func (RowsAffected) LastInsertId() (int64, error)

func (RowsAffected) RowsAffected

func (v RowsAffected) RowsAffected() (int64, error)

type RowsColumnTypeDatabaseTypeName

RowsColumnTypeDatabaseTypeName 可以通過行來實現(xiàn)。它應該返回沒有長度的數(shù)據(jù)庫系統(tǒng)類型名稱。類型名稱應該是大寫的。返回類型的示例:"VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT", "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML", "TIMESTAMP"。

type RowsColumnTypeDatabaseTypeName interface {
        Rows        ColumnTypeDatabaseTypeName(index int) string}

type RowsColumnTypeLength

RowsColumnTypeLength 可以通過行來實現(xiàn)。如果列是可變長度類型,它應該返回列類型的長度。如果該列不是可變長度類型,則應返回 false。如果長度不限于系統(tǒng)限制,它應該返回math.MaxInt64。以下是各種類型返回值的示例:

TEXT          (math.MaxInt64, true)varchar(10)   (10, true)nvarchar(10)  (10, true)decimal       (0, false)int           (0, false)bytea(30)     (30, true)
type RowsColumnTypeLength interface {
        Rows        ColumnTypeLength(index int) (length int64, ok bool)}

type RowsColumnTypeNullable

RowsColumnTypeNullable 可以由 Rows實現(xiàn)。如果已知列可能為空,則可為空的值應為 true ;如果列已知為不可空,則可為空值。如果列可空性未知,那么 ok 應該是錯誤的。

type RowsColumnTypeNullable interface {
        Rows        ColumnTypeNullable(index int) (nullable, ok bool)}

type RowsColumnTypePrecisionScale

RowsColumnTypePrecisionScale 可以通過行來實現(xiàn)。它應該返回十進制類型的精度和小數(shù)位數(shù)。如果不適用,確定應該是錯誤的。以下是各種類型返回值的示例:

decimal(38, 4)    (38, 4, true)int               (0, 0, false)decimal           (math.MaxInt64, math.MaxInt64, true)
type RowsColumnTypePrecisionScale interface {
        Rows        ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool)}

type RowsColumnTypeScanType

RowsColumnTypeScanType 可以通過行來實現(xiàn)。它應該返回可用于掃描類型的值類型。例如,數(shù)據(jù)庫列類型 “bigint” 應該返回 “reflect.TypeOf(int64(0))”。

type RowsColumnTypeScanType interface {
        Rows        ColumnTypeScanType(index int) reflect.Type}

type RowsNextResultSet

RowsNextResultSet 通過提供一種方式來通知驅(qū)動程序前進到下一個結果集,從而擴展了 Rows 接口。

type RowsNextResultSet interface {
        Rows        // HasNextResultSet在當前結果集和結尾處被調(diào)用        // 報告當前之后是否存在另一個結果集。        HasNextResultSet() bool        // NextResultSet將驅(qū)動程序提前到下一個結果集        // 如果當前結果集中有剩余的行。        //        // 當沒有更多的結果集時,NextResultSet應該返回io.EOF。        NextResultSet() error}

type Stmt

Stmt 是一個準備好的聲明。它與 Conn 綁定,并且不被多個goroutine 同時使用。

type Stmt interface {        // Close關閉聲明。        //        // 從Go 1.1開始,Stmt在使用時不會關閉        // 任何查詢。        Close() error        // NumInput返回占位符參數(shù)的數(shù)量。        //        // 如果NumInput returns> = 0,則sql包將進行完整性檢查        // 來自調(diào)用者的參數(shù)計數(shù)并將錯誤返回給調(diào)用者        // 在語句的Exec或Query方法被調(diào)用之前。        //        // 如果驅(qū)動程序不知道,NumInput也可能返回-1        // 其占位符的數(shù)量。 在那種情況下,sql包        // 將不會執(zhí)行檢查Exec或Query參數(shù)計數(shù)。        NumInput() int        // Exec執(zhí)行不返回行的查詢,例如        // INSERT或UPDATE。        //        // 棄用(Deprecated):驅(qū)動程序應該實現(xiàn)StmtExecContext(或另外)。        // Query執(zhí)行可能返回行的查詢,例如一個        // SELECT。        //        // 棄用(Deprecated):驅(qū)動程序應該實現(xiàn)StmtQueryContext(或另外)。        Query(args []Value) (Rows, error)}
  • import "database/sql"

  • 概述

  • 索引

  • 示例

  • 子目錄

概述

Package sql 提供了一個圍繞SQL(或類似SQL)數(shù)據(jù)庫的通用接口。

sql 包必須與數(shù)據(jù)庫驅(qū)動程序一起使用。查看https://golang.org/s/sqldrivers獲取驅(qū)動程序列表。

不支持上下文取消的驅(qū)動程序直到查詢完成后才會返回。

有關使用示例,請參閱https://golang.org/s/sqlwiki上的wiki頁面。

索引

  • Variables

  • func Drivers() []string

  • func Register(name string, driver driver.Driver)

  • type ColumnType

  • func (ci *ColumnType) DatabaseTypeName() string

  • func (ci *ColumnType) DecimalSize() (precision, scale int64, ok bool)

  • func (ci *ColumnType) Length() (length int64, ok bool)

  • func (ci *ColumnType) Name() string

  • func (ci *ColumnType) Nullable() (nullable, ok bool)

  • func (ci *ColumnType) ScanType() reflect.Type

  • type Conn

  • func (c *Conn) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error)

  • func (c *Conn) Close() error

  • func (c *Conn) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)

  • func (c *Conn) PingContext(ctx context.Context) error

Previous article: Next article: