@@ -11,6 +11,7 @@ import (
11
11
"github.com/pingcap/parser"
12
12
"github.com/siddontang/go-log/log"
13
13
"github.com/siddontang/go-mysql/mysql"
14
+ "github.com/siddontang/go-mysql/replication"
14
15
)
15
16
16
17
var testHost = flag .String ("host" , "127.0.0.1" , "MySQL host" )
@@ -62,7 +63,7 @@ func (s *canalTestSuite) SetUpSuite(c *C) {
62
63
s .execute (c , "INSERT INTO test.canal_test (content, name) VALUES (?, ?), (?, ?), (?, ?)" , "1" , "a" , `\0\ndsfasdf` , "b" , "" , "c" )
63
64
64
65
s .execute (c , "SET GLOBAL binlog_format = 'ROW'" )
65
-
66
+
66
67
s .c .SetEventHandler (& testEventHandler {c : c })
67
68
go func () {
68
69
set , _ := mysql .ParseGTIDSet ("mysql" , "" )
@@ -275,3 +276,42 @@ func TestDropTableExp(t *testing.T) {
275
276
}
276
277
}
277
278
}
279
+ func TestWithoutSchemeExp (t * testing.T ) {
280
+
281
+ cases := []replication.QueryEvent {
282
+ replication.QueryEvent {
283
+ Schema : []byte ("test" ),
284
+ Query : []byte ("drop table test0" ),
285
+ },
286
+ replication.QueryEvent {
287
+ Schema : []byte ("test" ),
288
+ Query : []byte ("rename table `test0` to `testtmp`" ),
289
+ },
290
+ replication.QueryEvent {
291
+ Schema : []byte ("test" ),
292
+ Query : []byte ("ALTER TABLE `test0` ADD `field2` DATE NULL AFTER `field1`;" ),
293
+ },
294
+ replication.QueryEvent {
295
+ Schema : []byte ("test" ),
296
+ Query : []byte ("CREATE TABLE IF NOT EXISTS test0 (`id` int(10)) ENGINE=InnoDB" ),
297
+ },
298
+ }
299
+ table := "test0"
300
+ db := "test"
301
+ pr := parser .New ()
302
+ for _ , s := range cases {
303
+ stmts , _ , err := pr .Parse (string (s .Query ), "" , "" )
304
+ if err != nil {
305
+ t .Fatalf ("TestCreateTableExp:case %s failed\n " , s .Query )
306
+ }
307
+ for _ , st := range stmts {
308
+ nodes := parseStmt (st )
309
+ if len (nodes ) == 0 {
310
+ continue
311
+ }
312
+ if nodes [0 ].db != "" || nodes [0 ].table != table || string (s .Schema ) != db {
313
+ t .Fatalf ("TestCreateTableExp:case %s failed\n " , s .Query )
314
+ }
315
+ }
316
+ }
317
+ }
0 commit comments