本文整理汇总了Golang中database/sql/driver.Conn类的典型用法代码### 示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。

在下文中一共展示了Conn类的12个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: driverExec

func driverExec(t *testing.T, dc driver.Conn, query string) {
    st, err := dc.Prepare(query)
    if err != nil {
        t.Fatal(err)
    }
    defer func() {
        if err := st.Close(); err != nil && t != nil {
            t.Fatal(err)
        }
    }()

    r, err := st.Exec([]driver.Value{})
    if err != nil {
        if t != nil {
            t.Fatal(err)
        }
        return
    }
    _, err = r.RowsAffected()
    if err != nil {
        if t != nil {
            t.Fatalf("r.RowsAffected(%q ...) failed: %v", query, err)
        }
        return
    }
}

开发者ID:weave-lab,项目名称:odbc,代码行数:26,代码来源:mssql_test.go

示例2: ctxDriverBegin

func ctxDriverBegin(ctx context.Context, ci driver.Conn) (driver.Tx, error) {
    if ciCtx, is := ci.(driver.ConnBeginContext); is {
        return ciCtx.BeginContext(ctx)
    }

    if ctx.Done() == context.Background().Done() {
        return ci.Begin()
    }

    // Check the transaction level in ctx. If set and non-default
    // then return an error here as the BeginContext driver value is not supported.
    if level, ok := driver.IsolationFromContext(ctx); ok && level != driver.IsolationLevel(LevelDefault) {
        return nil, errors.New("sql: driver does not support non-default isolation level")
    }

    // Check for a read-only parameter in ctx. If a read-only transaction is
    // requested return an error as the BeginContext driver value is not supported.
    if ro := driver.ReadOnlyFromContext(ctx); ro {
        return nil, errors.New("sql: driver does not support read-only transactions")
    }

    txi, err := ci.Begin()
    if err == nil {
        select {
        default:
        case <-ctx.Done():
            txi.Rollback()
            return nil, ctx.Err()
        }
    }
    return txi, err
}

开发者ID:oshimaya,项目名称:go,代码行数:32,代码来源:ctxutil.go

示例3: ctxDriverBegin

func ctxDriverBegin(ctx context.Context, ci driver.Conn) (driver.Tx, error) {
    if ciCtx, is := ci.(driver.ConnBeginContext); is {
        return ciCtx.BeginContext(ctx)
    }

    if ctx.Done() == context.Background().Done() {
        return ci.Begin()
    }

    // Check the transaction level in ctx. If set and non-default
    // then return an error here as the BeginContext driver value is not supported.
    if level, ok := driver.IsolationFromContext(ctx); ok && level != driver.IsolationLevel(LevelDefault) {
        return nil, errors.New("sql: driver does not support non-default isolation level")
    }

    // Check for a read-only parameter in ctx. If a read-only transaction is
    // requested return an error as the BeginContext driver value is not supported.
    if ro := driver.ReadOnlyFromContext(ctx); ro {
        return nil, errors.New("sql: driver does not support read-only transactions")
    }

    type R struct {
        err   error
        panic interface{}
        txi   driver.Tx
    }
    rc := make(chan R, 1)
    go func() {
        r := R{}
        defer func() {
            if v := recover(); v != nil {
                r.panic = v
            }
            rc <- r
        }()
        r.txi, r.err = ci.Begin()
    }()
    select {
    case <-ctx.Done():
        go func() {
            <-rc
            close(rc)
        }()
        return nil, ctx.Err()
    case r := <-rc:
        if r.panic != nil {
            panic(r.panic)
        }
        return r.txi, r.err
    }
}

开发者ID:Harvey-OS,项目名称:go,代码行数:51,代码来源:ctxutil.go

示例4: queryConn

// queryConn executes a query on the given connection.
// The connection gets released by the releaseConn function.
func (db *DB) queryConn(ci driver.Conn, releaseConn func(error), query string, args []interface{}) (*Rows, error) {
    if queryer, ok := ci.(driver.Queryer); ok {
        dargs, err := driverArgs(nil, args)
        if err != nil {
            releaseConn(err)
            return nil, err
        }
        rowsi, err := queryer.Query(query, dargs)
        if err != driver.ErrSkip {
            if err != nil {
                releaseConn(err)
                return nil, err
            }
            // Note: ownership of ci passes to the *Rows, to be freed
            // with releaseConn.
            rows := &Rows{
                db:          db,
                ci:          ci,
                releaseConn: releaseConn,
                rowsi:       rowsi,
            }
            return rows, nil
        }
    }

    sti, err := ci.Prepare(query)
    if err != nil {
        releaseConn(err)
        return nil, err
    }

    rowsi, err := rowsiFromStatement(sti, args...)
    if err != nil {
        releaseConn(err)
        sti.Close()
        return nil, err
    }

    // Note: ownership of ci passes to the *Rows, to be freed
    // with releaseConn.
    rows := &Rows{
        db:          db,
        ci:          ci,
        releaseConn: releaseConn,
        rowsi:       rowsi,
        closeStmt:   sti,
    }
    return rows, nil
}

开发者ID:serge-hulne,项目名称:golang,代码行数:51,代码来源:sql.go

示例5: ctxDriverPrepare

func ctxDriverPrepare(ctx context.Context, ci driver.Conn, query string) (driver.Stmt, error) {
    if ciCtx, is := ci.(driver.ConnPrepareContext); is {
        return ciCtx.PrepareContext(ctx, query)
    }
    si, err := ci.Prepare(query)
    if err == nil {
        select {
        default:
        case <-ctx.Done():
            si.Close()
            return nil, ctx.Err()
        }
    }
    return si, err
}

开发者ID:oshimaya,项目名称:go,代码行数:15,代码来源:ctxutil.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng