@ -1168,6 +1168,33 @@ func (s *testSessionSuite) TestIssue571(c *C) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (s *testSessionSuite) TestRetryPreparedStmt(c *C) {
|
||||
store := newStore(c, s.dbName)
|
||||
se := newSession(c, store, s.dbName)
|
||||
se1 := newSession(c, store, s.dbName)
|
||||
se2 := newSession(c, store, s.dbName)
|
||||
|
||||
mustExecSQL(c, se, "drop table if exists t")
|
||||
c.Assert(se.(*session).txn, IsNil)
|
||||
mustExecSQL(c, se, "create table t (c1 int, c2 int, c3 int)")
|
||||
mustExecSQL(c, se, "insert t values (11, 2, 3)")
|
||||
|
||||
mustExecSQL(c, se1, "begin")
|
||||
mustExecSQL(c, se1, "update t set c2=? where c1=11;", 21)
|
||||
|
||||
mustExecSQL(c, se2, "begin")
|
||||
mustExecSQL(c, se2, "update t set c2=? where c1=11", 22)
|
||||
mustExecSQL(c, se2, "commit")
|
||||
|
||||
mustExecSQL(c, se1, "commit")
|
||||
|
||||
se3 := newSession(c, store, s.dbName)
|
||||
r := mustExecSQL(c, se3, "select c2 from t where c1=11")
|
||||
row, err := r.FirstRow()
|
||||
c.Assert(err, IsNil)
|
||||
match(c, row, 21)
|
||||
}
|
||||
|
||||
// Testcase for session
|
||||
func (s *testSessionSuite) TestSession(c *C) {
|
||||
store := newStore(c, s.dbName)
|
||||
|
||||
12
tidb.go
12
tidb.go
@ -194,16 +194,11 @@ func runStmt(ctx context.Context, s stmt.Statement, args ...interface{}) (rset.R
|
||||
var rs rset.Recordset
|
||||
// before every execution, we must clear affectedrows.
|
||||
variable.GetSessionVars(ctx).SetAffectedRows(0)
|
||||
switch s.(type) {
|
||||
switch ts := s.(type) {
|
||||
case *stmts.PreparedStmt:
|
||||
ps := s.(*stmts.PreparedStmt)
|
||||
return runPreparedStmt(ctx, ps)
|
||||
rs, err = runPreparedStmt(ctx, ts)
|
||||
case *stmts.ExecuteStmt:
|
||||
es := s.(*stmts.ExecuteStmt)
|
||||
rs, err = runExecute(ctx, es, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Trace(err)
|
||||
}
|
||||
rs, err = runExecute(ctx, ts, args...)
|
||||
default:
|
||||
if s.IsDDL() {
|
||||
err = ctx.FinishTxn(false)
|
||||
@ -215,6 +210,7 @@ func runStmt(ctx context.Context, s stmt.Statement, args ...interface{}) (rset.R
|
||||
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:
|
||||
|
||||
@ -348,10 +348,6 @@ func exec(c *C, se Session, sql string, args ...interface{}) (rset.Recordset, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = se.DropPreparedStmt(stmtID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user