本文整理汇总了Golang中github.com/pingcap/tidb/stmt.Statement.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang Statement.Exec方法的具体用法?Golang Statement.Exec怎么用?Golang Statement.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/stmt.Statement
的用法示例。
在下文中一共展示了Statement.Exec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runStmt
func runStmt(ctx context.Context, s stmt.Statement, args ...interface{}) (rset.Recordset, error) {
var err error
var rs rset.Recordset
// before every execution, we must clear affectedrows.
variable.GetSessionVars(ctx).SetAffectedRows(0)
switch s.(type) {
case *stmts.PreparedStmt:
ps := s.(*stmts.PreparedStmt)
return runPreparedStmt(ctx, ps)
case *stmts.ExecuteStmt:
es := s.(*stmts.ExecuteStmt)
rs, err = runExecute(ctx, es, args...)
if err != nil {
return nil, errors.Trace(err)
}
default:
if s.IsDDL() {
err = ctx.FinishTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
}
stmt.BindExecArgs(ctx, args)
rs, err = s.Exec(ctx)
stmt.ClearExecArgs(ctx)
}
// MySQL DDL should be auto-commit
if err == nil && (s.IsDDL() || variable.ShouldAutocommit(ctx)) {
err = ctx.FinishTxn(false)
}
return rs, errors.Trace(err)
}
示例2: runStmt
func runStmt(ctx context.Context, s stmt.Statement, args ...interface{}) (rset.Recordset, error) {
var err error
var rs rset.Recordset
// before every execution, we must clear affectedrows.
variable.GetSessionVars(ctx).SetAffectedRows(0)
if s.IsDDL() {
err = ctx.FinishTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
}
rs, err = s.Exec(ctx)
// All the history should be added here.
se := ctx.(*session)
se.history.add(0, s)
// MySQL DDL should be auto-commit
if s.IsDDL() || autocommit.ShouldAutocommit(ctx) {
if err != nil {
ctx.FinishTxn(true)
} else {
err = ctx.FinishTxn(false)
}
}
return rs, errors.Trace(err)
}
示例3: runStmt
func runStmt(ctx context.Context, s stmt.Statement, args ...interface{}) (rset.Recordset, error) {
var err error
var rs rset.Recordset
// before every execution, we must clear affectedrows.
variable.GetSessionVars(ctx).SetAffectedRows(0)
switch ts := s.(type) {
case *stmts.PreparedStmt:
rs, err = runPreparedStmt(ctx, ts)
case *stmts.ExecuteStmt:
rs, err = runExecute(ctx, ts, args...)
default:
if s.IsDDL() {
err = ctx.FinishTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
}
stmt.BindExecArgs(ctx, args)
rs, err = s.Exec(ctx)
stmt.ClearExecArgs(ctx)
}
// All the history should be added here.
se := ctx.(*session)
switch ts := s.(type) {
case *stmts.PreparedStmt:
se.history.add(ts.ID, s)
case *stmts.ExecuteStmt:
se.history.add(ts.ID, s, args...)
default:
se.history.add(0, s)
}
// MySQL DDL should be auto-commit
if s.IsDDL() || autocommit.ShouldAutocommit(ctx) {
if err != nil {
ctx.FinishTxn(true)
} else {
err = ctx.FinishTxn(false)
}
}
return rs, errors.Trace(err)
}