diff --git a/session/session_inception_print_test.go b/session/session_inception_print_test.go index 60aab2f5..ce3cd467 100644 --- a/session/session_inception_print_test.go +++ b/session/session_inception_print_test.go @@ -144,3 +144,35 @@ func (s *testSessionPrintSuite) TestInsert(c *C) { c.Assert(row[4], Equals, "line 1 column 21 near \"\" (total length 21)", Commentf("%v", row)) } + +func (s *testSessionPrintSuite) TestUpdate(c *C) { + + res := s.makeSQL(`update t1 set c1=1 where a=1;`) + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] + c.Assert(row[2], Equals, "0", Commentf("%v", row)) + + res = s.makeSQL("update t1 inner join t2 on t1.id=t2.id set c2=1 where t1.c1=1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + c.Assert(row[2], Equals, "0", Commentf("%v", row)) + +} + +func (s *testSessionPrintSuite) TestDelete(c *C) { + + res := s.makeSQL(`delete from t1 where id=1;`) + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] + c.Assert(row[2], Equals, "0", Commentf("%v", row)) + + // res = s.makeSQL("update t1 inner join t2 on t1.id=t2.id set c2=1 where t1.c1=1;") + // row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + // c.Assert(row[2], Equals, "0", Commentf("%v", row)) + +} + +func (s *testSessionPrintSuite) TestAlterTable(c *C) { + + res := s.makeSQL(`alter table t1 add column c1 int;`) + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] + c.Assert(row[2], Equals, "0", Commentf("%v", row)) + +} diff --git a/session/session_print.go b/session/session_print.go index b269d7de..f5030373 100644 --- a/session/session_print.go +++ b/session/session_print.go @@ -19,13 +19,12 @@ func (s *session) printCommand(ctx context.Context, stmtNode ast.StmtNode, log.Debug("printCommand") // b, err := json.MarshalIndent(stmtNode, "", " ") - b, err := json.Marshal(stmtNode) + tree, err := json.Marshal(stmtNode) if err != nil { log.Error(err) s.printSets.Append(2, currentSql, "", err.Error()) } else { - str := string(b) - s.printSets.Append(0, currentSql, str, "") + s.printSets.Append(0, currentSql, string(tree), "") } return nil, nil