• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang driver.RowsAffected函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Exec

func (stmt *cypherStmt) Exec(args []driver.Value) (driver.Result, error) {
	if stmt.c.transaction != nil {
		err := stmt.c.transaction.query(stmt.query, args)
		// TODO add counts and error support
		return driver.RowsAffected(0), err
	}
	rows, err := stmt.Query(args)
	if rows != nil {
		defer rows.Close()
	}
	// TODO add counts and error support
	return driver.RowsAffected(0), err
}
开发者ID:slowteetoe,项目名称:presagio,代码行数:13,代码来源:statement.go


示例2: exec

func (c *conn) exec(stmt parser.Statement, args []driver.Value) (driver.Result, error) {
	rows, err := c.query(stmt, args)
	if err != nil {
		return nil, err
	}
	return driver.RowsAffected(len(rows.rows)), nil
}
开发者ID:Jaekyun,项目名称:cockroach,代码行数:7,代码来源:conn.go


示例3: execInsert

func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
	db := s.c.db
	if len(args) != s.placeholders {
		panic("error in pkg db; should only get here if size is correct")
	}
	db.mu.Lock()
	t, ok := db.table(s.table)
	db.mu.Unlock()
	if !ok {
		return nil, fmt.Errorf("fakedb: table %q doesn't exist", s.table)
	}

	t.mu.Lock()
	defer t.mu.Unlock()

	cols := make([]interface{}, len(t.colname))
	argPos := 0
	for n, colname := range s.colName {
		colidx := t.columnIndex(colname)
		if colidx == -1 {
			return nil, fmt.Errorf("fakedb: column %q doesn't exist or dropped since prepared statement was created", colname)
		}
		var val interface{}
		if strvalue, ok := s.colValue[n].(string); ok && strvalue == "?" {
			val = args[argPos]
			argPos++
		} else {
			val = s.colValue[n]
		}
		cols[colidx] = val
	}

	t.rows = append(t.rows, &row{cols: cols})
	return driver.RowsAffected(1), nil
}
开发者ID:anuvazhayil,项目名称:HelloWorld_32bitOS,代码行数:35,代码来源:fakedb_test.go


示例4: Exec

func (c *conn) Exec(stmt string, args []driver.Value) (driver.Result, error) {
	rows, err := c.Query(stmt, args)
	if err != nil {
		return nil, err
	}
	return driver.RowsAffected(len(rows.rows)), nil
}
开发者ID:XisiHuang,项目名称:cockroach,代码行数:7,代码来源:conn.go


示例5: Exec

func (cn *Conn) Exec(query string, args []interface{}) (driver.Result, error) {
	if len(args) == 0 {
		err := cn.p.SimpleQuery(query)
		if err != nil {
			return nil, err
		}

		var serr error
		for {
			m, err := cn.p.Next()
			if err != nil {
				return nil, err
			}

			switch m.Type {
			case 'E':
				serr = m.Err
			case 'Z':
				return driver.RowsAffected(0), serr
			}
		}
	} else {
		stmt, err := cn.Prepare(query)
		if err != nil {
			return nil, err
		}

		return stmt.Exec(args)
	}

	panic("not reached")
}
开发者ID:bhuvan,项目名称:go-sql-test,代码行数:32,代码来源:conn.go


示例6: Exec

// Exec inserts values into the COPY stream. The insert is asynchronous
// and Exec can return errors from previous Exec calls to the same
// COPY stmt.
//
// You need to call Exec(nil) to sync the COPY stream and to get any
// errors from pending data, since Stmt.Close() doesn't return errors
// to the user.
func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) {
	defer errRecover(&err)

	if ci.closed {
		return nil, errCopyInClosed
	}

	if ci.isErrorSet() {
		return nil, ci.err
	}

	if len(v) == 0 {
		err = ci.Close()
		ci.closed = true
		return nil, err
	}

	numValues := len(v)
	for i, value := range v {
		ci.buffer = appendEncodedText(&ci.cn.parameterStatus, ci.buffer, value)
		if i < numValues-1 {
			ci.buffer = append(ci.buffer, '\t')
		}
	}

	ci.buffer = append(ci.buffer, '\n')

	if len(ci.buffer) > ciBufferFlushSize {
		ci.flush(ci.buffer)
		// reset buffer, keep bytes for message identifier and length
		ci.buffer = ci.buffer[:5]
	}

	return driver.RowsAffected(0), nil
}
开发者ID:jpoz,项目名称:pq,代码行数:42,代码来源:copy.go


示例7: Exec

func (c *sqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
	n, err := c.conn.Execute(query, paramsFromValues(nil, args)...)
	if err != nil {
		return nil, err
	}

	return driver.RowsAffected(n), nil
}
开发者ID:sedzinreri,项目名称:go-pgsql,代码行数:8,代码来源:driver.go


示例8: Exec

func (c *conn) Exec(stmt string, args []driver.Value) (driver.Result, error) {
	result, err := c.internalQuery(stmt, args)
	if err != nil {
		return nil, err
	}
	switch t := result.GetUnion().(type) {
	case nil:
		return nil, nil
	case *Response_Result_DDL_:
		return driver.ResultNoRows, nil
	case *Response_Result_RowsAffected:
		return driver.RowsAffected(int(t.RowsAffected)), nil
	case *Response_Result_Rows_:
		return driver.RowsAffected(len(t.Rows.Rows)), nil
	default:
		return nil, util.Errorf("unexpected result %s of type %T", t, t)
	}
}
开发者ID:nporsche,项目名称:cockroach,代码行数:18,代码来源:conn.go


示例9: Exec

func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
	if err := s.st.Execute(args); err != nil {
		return nil, err
	}

	rowsAffected, err := s.st.RowsAffected()
	r := driver.RowsAffected(rowsAffected)
	return r, err
}
开发者ID:andybalholm,项目名称:go-odbc,代码行数:9,代码来源:sql.go


示例10: Exec

func (c *Conn) Exec(query string, argsV []driver.Value) (driver.Result, error) {
	if !c.conn.IsAlive() {
		return nil, driver.ErrBadConn
	}

	args := valueToInterface(argsV)
	commandTag, err := c.conn.Exec(query, args...)
	return driver.RowsAffected(commandTag.RowsAffected()), err
}
开发者ID:josephwinston,项目名称:flynn,代码行数:9,代码来源:sql.go


示例11: parseComplete

// parseComplete parses the "command tag" from a CommandComplete message, and
// returns the number of rows affected (if applicable) and a string
// identifying only the command that was executed, e.g. "ALTER TABLE".  If the
// command tag could not be parsed, parseComplete panics.
func (cn *conn) parseComplete(commandTag string) (driver.Result, string) {
	commandsWithAffectedRows := []string{
		"SELECT ",
		// INSERT is handled below
		"UPDATE ",
		"DELETE ",
		"FETCH ",
		"MOVE ",
		"COPY ",
	}

	var affectedRows *string
	for _, tag := range commandsWithAffectedRows {
		if strings.HasPrefix(commandTag, tag) {
			t := commandTag[len(tag):]
			affectedRows = &t
			commandTag = tag[:len(tag)-1]
			break
		}
	}
	// INSERT also includes the oid of the inserted row in its command tag.
	// Oids in user tables are deprecated, and the oid is only returned when
	// exactly one row is inserted, so it's unlikely to be of value to any
	// real-world application and we can ignore it.
	if affectedRows == nil && strings.HasPrefix(commandTag, "INSERT ") {
		parts := strings.Split(commandTag, " ")
		if len(parts) != 3 {
			cn.bad = true
			errorf("unexpected INSERT command tag %s", commandTag)
		}
		affectedRows = &parts[len(parts)-1]
		commandTag = "INSERT"
	}
	// There should be no affected rows attached to the tag, just return it
	if affectedRows == nil {
		return driver.RowsAffected(0), commandTag
	}
	n, err := strconv.ParseInt(*affectedRows, 10, 64)
	if err != nil {
		cn.bad = true
		errorf("could not parse commandTag: %s", err)
	}
	return driver.RowsAffected(n), commandTag
}
开发者ID:agonist,项目名称:gameflix,代码行数:48,代码来源:conn.go


示例12: execInsert

// When doInsert is true, add the row to the table.
// When doInsert is false do prep-work and error checking, but don't
// actually add the row to the table.
func (s *fakeStmt) execInsert(args []driver.NamedValue, doInsert bool) (driver.Result, error) {
	db := s.c.db
	if len(args) != s.placeholders {
		panic("error in pkg db; should only get here if size is correct")
	}
	db.mu.Lock()
	t, ok := db.table(s.table)
	db.mu.Unlock()
	if !ok {
		return nil, fmt.Errorf("fakedb: table %q doesn't exist", s.table)
	}

	t.mu.Lock()
	defer t.mu.Unlock()

	var cols []interface{}
	if doInsert {
		cols = make([]interface{}, len(t.colname))
	}
	argPos := 0
	for n, colname := range s.colName {
		colidx := t.columnIndex(colname)
		if colidx == -1 {
			return nil, fmt.Errorf("fakedb: column %q doesn't exist or dropped since prepared statement was created", colname)
		}
		var val interface{}
		if strvalue, ok := s.colValue[n].(string); ok && strings.HasPrefix(strvalue, "?") {
			if strvalue == "?" {
				val = args[argPos].Value
			} else {
				// Assign value from argument placeholder name.
				for _, a := range args {
					if a.Name == strvalue[1:] {
						val = a.Value
						break
					}
				}
			}
			argPos++
		} else {
			val = s.colValue[n]
		}
		if doInsert {
			cols[colidx] = val
		}
	}

	if doInsert {
		t.rows = append(t.rows, &row{cols: cols})
	}
	return driver.RowsAffected(1), nil
}
开发者ID:oshimaya,项目名称:go,代码行数:55,代码来源:fakedb_test.go


示例13: Exec

func (s *driverStmt) Exec(args []driver.Value) (res driver.Result, err error) {
	cres := s.exec(args)
	if err = resultError(cres); err != nil {
		C.PQclear(cres)
		return
	}
	defer C.PQclear(cres)
	rowsAffected, err := strconv.ParseInt(C.GoString(C.PQcmdTuples(cres)), 10, 64)
	if err != nil {
		return
	}
	return driver.RowsAffected(rowsAffected), nil
}
开发者ID:NDrive,项目名称:gopgsqldriver,代码行数:13,代码来源:pgdriver.go


示例14: q

func (s *stmt) q(args []driver.Value) (driver.Rows, driver.Result, error) {
	cmd, err := ado.NewCommand()
	if err != nil {
		return nil, nil, err
	}
	defer cmd.Release()
	err = cmd.PutrefActiveADOConnection(s.c.db)
	if err != nil {
		return nil, nil, err
	}

	err = cmd.PutCommandText(s.query)
	if err != nil {
		return nil, nil, err
	}
	err = cmd.PutCommandType(1)
	if err != nil {
		return nil, nil, err
	}

	params, err := cmd.GetParameters()
	if err != nil {
		return nil, nil, err
	}
	defer params.Release()

	for _, a := range args {
		var param *ado.Parameter
		switch v := a.(type) {
		case int64:
			v32 := int32(v)
			if int64(v32) != v {
				return nil, nil, fmt.Errorf("integer too large to pass to FoxPro: %d", v)
			}
			param, err = cmd.CreateParameter("", ado.Integer, ado.ParamInput, 4, v32)
		case float64:
			param, err = cmd.CreateParameter("", ado.Double, ado.ParamInput, 8, v)
		case bool:
			param, err = cmd.CreateParameter("", ado.Boolean, ado.ParamInput, 1, v)
		case []byte:
			param, err = cmd.CreateParameter("", ado.BSTR, ado.ParamInput, uintptr(len(v)), string(v))
		case string:
			param, err = cmd.CreateParameter("", ado.BSTR, ado.ParamInput, uintptr(len(v)), v)
		case time.Time:
			param, err = cmd.CreateParameter("", ado.Date, ado.ParamInput, 8, v)
		default:
			err = fmt.Errorf("foxpro: parameters of type %T are not supported", a)
		}
		if err != nil {
			return nil, nil, err
		}
		defer param.Release()
		err = params.Append(param)
		if err != nil {
			return nil, nil, err
		}
	}

	var nRecords com.Variant
	recordset, err := cmd.Execute(&nRecords, nil, ado.OptionUnspecified)
	if err != nil {
		return nil, nil, err
	}
	return &rows{recordset}, driver.RowsAffected(nRecords.Val), nil
}
开发者ID:vijaygiri10,项目名称:com-and-go,代码行数:65,代码来源:ado.go


示例15: parseComplete

func parseComplete(s string) driver.Result {
	parts := strings.Split(s, " ")
	n, _ := strconv.ParseInt(parts[len(parts)-1], 10, 64)
	return driver.RowsAffected(n)
}
开发者ID:usermindinc,项目名称:pq,代码行数:5,代码来源:conn.go



注:本文中的database/sql/driver.RowsAffected函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang driver.Value函数代码示例发布时间:2022-05-24
下一篇:
Golang driver.IsValue函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap