3 Star 0 Fork 0

GBase8s/go-gci

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gci_sql_go_113_test.go 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
617206652 提交于 2024-07-02 15:30 . go-gci add test
// +build go1.13
package gbase8s
import (
"context"
"testing"
)
// TestStatementCaching tests to ensure statement caching is working
func TestStatementCaching(t *testing.T) {
if TestDisableDatabase {
t.SkipNow()
}
t.Parallel()
var err error
db := testGetDB("?stmt_cache_size=10")
if db == nil {
t.Fatal("db is null")
}
defer func() {
err = db.Close()
if err != nil {
t.Fatal("db close error:", err)
}
}()
ctx, cancel := context.WithTimeout(context.Background(), TestContextTimeout)
conn, err := db.Conn(ctx)
cancel()
// we need to get access to the raw connection so we can access the different fields on the gbase8s.Stmt
var rawConn *Conn
// NOTE that conn.Raw() is only available with Go >= 1.13
_ = conn.Raw(func(driverConn interface{}) error {
rawConn = driverConn.(*Conn)
return nil
})
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout)
stmt, err := rawConn.PrepareContext(ctx, "select ?, ?, ? from dual")
cancel()
if err != nil {
t.Fatal("prepare error:", err)
}
rawStmt := stmt.(*Stmt)
if rawStmt.cacheKey != "select ?, ?, ? from dual" {
err := stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey)
}
// closing the statement should put the statement into the cache
err = stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout)
stmt, err = rawConn.PrepareContext(ctx, "select ?, ?, ? from dual")
cancel()
if err != nil {
t.Fatal("prepare error:", err)
}
rawStmt = stmt.(*Stmt)
if rawStmt.cacheKey != "select ?, ?, ? from dual" {
err := stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey)
}
err = stmt.Close()
if err != nil {
t.Fatal("stmt close error:", err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/GBase8s/go-gci.git
git@gitee.com:GBase8s/go-gci.git
GBase8s
go-gci
go-gci
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385