當前位置: 首頁>>代碼示例>>Golang>>正文


Golang driver.Stmt類代碼示例

本文整理匯總了Golang中database/sql/driver.Stmt的典型用法代碼示例。如果您正苦於以下問題:Golang Stmt類的具體用法?Golang Stmt怎麽用?Golang Stmt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Stmt類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: noteUnusedDriverStatement

// noteUnusedDriverStatement notes that si is no longer used and should
// be closed whenever possible (when c is next not in use), unless c is
// already closed.
func (db *DB) noteUnusedDriverStatement(c driver.Conn, si driver.Stmt) {
	db.mu.Lock()
	defer db.mu.Unlock()
	if db.outConn[c] {
		db.onConnPut[c] = append(db.onConnPut[c], func() {
			si.Close()
		})
	} else {
		si.Close()
	}
}
開發者ID:serge-hulne,項目名稱:golang,代碼行數:14,代碼來源:sql.go

示例2: noteUnusedDriverStatement

// noteUnusedDriverStatement notes that si is no longer used and should
// be closed whenever possible (when c is next not in use), unless c is
// already closed.
func (db *DB) noteUnusedDriverStatement(c *driverConn, si driver.Stmt) {
	db.mu.Lock()
	defer db.mu.Unlock()
	if c.inUse {
		c.onPut = append(c.onPut, func() {
			si.Close()
		})
	} else {
		c.Lock()
		defer c.Unlock()
		if !c.finalClosed {
			si.Close()
		}
	}
}
開發者ID:arnold8,項目名稱:go,代碼行數:18,代碼來源:sql.go

示例3: benchPreparedMockQuery

func benchPreparedMockQuery(b *testing.B, c *conn, stmt driver.Stmt) {
	rows, err := stmt.Query(nil)
	if err != nil {
		b.Fatal(err)
	}
	defer rows.Close()
	var dest [1]driver.Value
	for {
		if err := rows.Next(dest[:]); err != nil {
			if err == io.EOF {
				break
			}
			b.Fatal(err)
		}
	}
}
開發者ID:CadeLaRen,項目名稱:traffic_control,代碼行數:16,代碼來源:bench_test.go

示例4: ctxDriverStmtQuery

func ctxDriverStmtQuery(ctx context.Context, si driver.Stmt, nvdargs []driver.NamedValue) (driver.Rows, error) {
	if siCtx, is := si.(driver.StmtQueryContext); is {
		return siCtx.QueryContext(ctx, nvdargs)
	}
	dargs, err := namedValueToValue(nvdargs)
	if err != nil {
		return nil, err
	}
	if ctx.Done() == context.Background().Done() {
		return si.Query(dargs)
	}

	type R struct {
		err   error
		panic interface{}
		rowsi driver.Rows
	}

	rc := make(chan R, 1)
	go func() {
		r := R{}
		defer func() {
			if v := recover(); v != nil {
				r.panic = v
			}
			rc <- r
		}()
		r.rowsi, r.err = si.Query(dargs)
	}()
	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.rowsi, r.err
	}
}
開發者ID:achanda,項目名稱:go,代碼行數:43,代碼來源:ctxutil.go

示例5: ctxDriverStmtExec

func ctxDriverStmtExec(ctx context.Context, si driver.Stmt, nvdargs []driver.NamedValue) (driver.Result, error) {
	if siCtx, is := si.(driver.StmtExecContext); is {
		return siCtx.ExecContext(ctx, nvdargs)
	}
	dargs, err := namedValueToValue(nvdargs)
	if err != nil {
		return nil, err
	}

	resi, err := si.Exec(dargs)
	if err == nil {
		select {
		default:
		case <-ctx.Done():
			return resi, ctx.Err()
		}
	}
	return resi, err
}
開發者ID:oshimaya,項目名稱:go,代碼行數:19,代碼來源:ctxutil.go

示例6: resultFromStatement

func resultFromStatement(si driver.Stmt, args ...interface{}) (Result, error) {
	// -1 means the driver doesn't know how to count the number of
	// placeholders, so we won't sanity check input here and instead let the
	// driver deal with errors.
	if want := si.NumInput(); want != -1 && len(args) != want {
		return nil, fmt.Errorf("sql: expected %d arguments, got %d", want, len(args))
	}

	dargs, err := driverArgs(si, args)
	if err != nil {
		return nil, err
	}

	resi, err := si.Exec(dargs)
	if err != nil {
		return nil, err
	}
	return result{resi}, nil
}
開發者ID:serge-hulne,項目名稱:golang,代碼行數:19,代碼來源:sql.go

示例7: ctxDriverStmtQuery

func ctxDriverStmtQuery(ctx context.Context, si driver.Stmt, nvdargs []driver.NamedValue) (driver.Rows, error) {
	if siCtx, is := si.(driver.StmtQueryContext); is {
		return siCtx.QueryContext(ctx, nvdargs)
	}
	dargs, err := namedValueToValue(nvdargs)
	if err != nil {
		return nil, err
	}

	rowsi, err := si.Query(dargs)
	if err == nil {
		select {
		default:
		case <-ctx.Done():
			rowsi.Close()
			return nil, ctx.Err()
		}
	}
	return rowsi, err
}
開發者ID:oshimaya,項目名稱:go,代碼行數:20,代碼來源:ctxutil.go

示例8: ctxDriverStmtExec

func ctxDriverStmtExec(ctx context.Context, si driver.Stmt, dargs []driver.Value) (driver.Result, error) {
	if siCtx, is := si.(driver.StmtExecContext); is {
		return siCtx.ExecContext(ctx, dargs)
	}
	if ctx.Done() == context.Background().Done() {
		return si.Exec(dargs)
	}

	type R struct {
		err   error
		panic interface{}
		resi  driver.Result
	}

	rc := make(chan R, 1)
	go func() {
		r := R{}
		defer func() {
			if v := recover(); v != nil {
				r.panic = v
			}
			rc <- r
		}()
		r.resi, r.err = si.Exec(dargs)
	}()
	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.resi, r.err
	}
}
開發者ID:kuangchanglang,項目名稱:go,代碼行數:39,代碼來源:ctxutil.go

示例9: rowsiFromStatement

func rowsiFromStatement(si driver.Stmt, args ...interface{}) (driver.Rows, error) {
	// -1 means the driver doesn't know how to count the number of
	// placeholders, so we won't sanity check input here and instead let the
	// driver deal with errors.
	if want := si.NumInput(); want != -1 && len(args) != want {
		return nil, fmt.Errorf("sql: statement expects %d inputs; got %d", si.NumInput(), len(args))
	}

	dargs, err := driverArgs(si, args)
	if err != nil {
		return nil, err
	}

	rowsi, err := si.Query(dargs)
	if err != nil {
		return nil, err
	}
	return rowsi, nil
}
開發者ID:serge-hulne,項目名稱:golang,代碼行數:19,代碼來源:sql.go

示例10: NewVar

// NewVar calls NewVar on the underlying *oracle.Cursor.
// This allows out binds, and if value is a pointer, then GetValue is not needed.
func NewVar(stmt driver.Stmt, value interface{}) (*oracle.Variable, error) {
	if stmt, ok := stmt.(varCreator); ok {
		return stmt.NewVar(value)
	}
	return nil, errgo.New("stmt must be a varCreator")
}
開發者ID:salahwadif,項目名稱:goracle,代碼行數:8,代碼來源:var.go


注:本文中的database/sql/driver.Stmt類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。