本文整理汇总了Golang中github.com/pingcap/tidb/context.Context.RollbackTxn方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RollbackTxn方法的具体用法?Golang Context.RollbackTxn怎么用?Golang Context.RollbackTxn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/context.Context
的用法示例。
在下文中一共展示了Context.RollbackTxn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runStmt
func runStmt(ctx context.Context, s ast.Statement, args ...interface{}) (ast.RecordSet, error) {
var err error
var rs ast.RecordSet
// before every execution, we must clear affectedrows.
variable.GetSessionVars(ctx).SetAffectedRows(0)
if s.IsDDL() {
err = ctx.CommitTxn()
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.
ac, err1 := autocommit.ShouldAutocommit(ctx)
if err1 != nil {
return nil, errors.Trace(err1)
}
if s.IsDDL() || ac {
if err != nil {
log.Info("RollbackTxn for ddl/autocommit error.")
ctx.RollbackTxn()
} else {
err = ctx.CommitTxn()
}
}
return rs, errors.Trace(err)
}
示例2: runStmt
// runStmt executes the ast.Statement and commit or rollback the current transaction.
func runStmt(ctx context.Context, s ast.Statement) (ast.RecordSet, error) {
var err error
var rs ast.RecordSet
if s.IsDDL() {
err = ctx.CommitTxn()
if err != nil {
return nil, errors.Trace(err)
}
}
rs, err = s.Exec(ctx)
// All the history should be added here.
se := ctx.(*session)
getHistory(ctx).add(0, s)
// MySQL DDL should be auto-commit.
if s.IsDDL() || se.sessionVars.ShouldAutocommit() {
if err != nil {
log.Info("RollbackTxn for ddl/autocommit error.")
ctx.RollbackTxn()
} else {
err = ctx.CommitTxn()
}
}
return rs, errors.Trace(err)
}
示例3: TestColumn
func (s *testColumnSuite) TestColumn(c *C) {
defer testleak.AfterTest(c)()
tblInfo := testTableInfo(c, s.d, "t1", 3)
var ctx context.Context
ctx = testNewContext(c, s.d)
defer ctx.RollbackTxn()
testCreateTable(c, ctx, s.d, s.dbInfo, tblInfo)
t := testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
num := 10
for i := 0; i < num; i++ {
_, err := t.AddRecord(ctx, types.MakeDatums(i, 10*i, 100*i))
c.Assert(err, IsNil)
}
err := ctx.CommitTxn()
c.Assert(err, IsNil)
i := int64(0)
t.IterRecords(ctx, t.FirstKey(), t.Cols(), func(h int64, data []types.Datum, cols []*table.Column) (bool, error) {
c.Assert(data, HasLen, 3)
c.Assert(data[0].GetInt64(), Equals, i)
c.Assert(data[1].GetInt64(), Equals, 10*i)
c.Assert(data[2].GetInt64(), Equals, 100*i)
i++
return true, nil
})
c.Assert(i, Equals, int64(num))
c.Assert(table.FindCol(t.Cols(), "c4"), IsNil)
job := testCreateColumn(c, ctx, s.d, s.dbInfo, tblInfo, "c4", &ast.ColumnPosition{Tp: ast.ColumnPositionAfter, RelativeColumn: &ast.ColumnName{Name: model.NewCIStr("c3")}}, 100)
testCheckJobDone(c, s.d, job, true)
t = testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
c.Assert(table.FindCol(t.Cols(), "c4"), NotNil)
i = int64(0)
t.IterRecords(ctx, t.FirstKey(), t.Cols(), func(h int64, data []types.Datum, cols []*table.Column) (bool, error) {
c.Assert(data, HasLen, 4)
c.Assert(data[0].GetInt64(), Equals, i)
c.Assert(data[1].GetInt64(), Equals, 10*i)
c.Assert(data[2].GetInt64(), Equals, 100*i)
c.Assert(data[3].GetInt64(), Equals, int64(100))
i++
return true, nil
})
c.Assert(i, Equals, int64(num))
h, err := t.AddRecord(ctx, types.MakeDatums(11, 12, 13, 14))
c.Assert(err, IsNil)
err = ctx.CommitTxn()
c.Assert(err, IsNil)
values, err := t.RowWithCols(ctx, h, t.Cols())
c.Assert(err, IsNil)
c.Assert(values, HasLen, 4)
c.Assert(values[3].GetInt64(), Equals, int64(14))
job = testDropColumn(c, ctx, s.d, s.dbInfo, tblInfo, "c4", false)
testCheckJobDone(c, s.d, job, false)
t = testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
values, err = t.RowWithCols(ctx, h, t.Cols())
c.Assert(err, IsNil)
c.Assert(values, HasLen, 3)
c.Assert(values[2].GetInt64(), Equals, int64(13))
job = testCreateColumn(c, ctx, s.d, s.dbInfo, tblInfo, "c4", &ast.ColumnPosition{Tp: ast.ColumnPositionNone}, 111)
testCheckJobDone(c, s.d, job, true)
t = testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
values, err = t.RowWithCols(ctx, h, t.Cols())
c.Assert(err, IsNil)
c.Assert(values, HasLen, 4)
c.Assert(values[3].GetInt64(), Equals, int64(111))
job = testCreateColumn(c, ctx, s.d, s.dbInfo, tblInfo, "c5", &ast.ColumnPosition{Tp: ast.ColumnPositionNone}, 101)
testCheckJobDone(c, s.d, job, true)
t = testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
values, err = t.RowWithCols(ctx, h, t.Cols())
c.Assert(err, IsNil)
c.Assert(values, HasLen, 5)
c.Assert(values[4].GetInt64(), Equals, int64(101))
job = testCreateColumn(c, ctx, s.d, s.dbInfo, tblInfo, "c6", &ast.ColumnPosition{Tp: ast.ColumnPositionFirst}, 202)
testCheckJobDone(c, s.d, job, true)
t = testGetTable(c, s.d, s.dbInfo.ID, tblInfo.ID)
cols := t.Cols()
c.Assert(cols, HasLen, 6)
c.Assert(cols[0].Offset, Equals, 0)
c.Assert(cols[0].Name.L, Equals, "c6")
c.Assert(cols[1].Offset, Equals, 1)
//.........这里部分代码省略.........