def test_1_PRIMARY_AUTO_INCREMENT(self): tbl = Table.match("CREATE TABLE `my_table` (") tbl.feed("`field1` int AUTO_INCREMENT PRIMARY KEY") tbl.feed(") ENGINE=InnoDB AUTO_INCREMENT=237442 DEFAULT CHARSET=utf8;") self.assertTrue(tbl.done) self.assertEqual( tbl.sql(flavor="sqlite", skip_constraints=True), '''CREATE TABLE "my_table" ( "field1" INTEGER AUTOINCREMENT );''') self.assertEqual( tbl.sql(flavor="sqlite", skip_constraints=False), '''CREATE TABLE "my_table" ( "field1" INTEGER PRIMARY KEY AUTOINCREMENT );''') self.assertEqual( tbl.sql(flavor="pg", skip_constraints=True), '''CREATE TABLE "my_table" ( "field1" SERIAL );''') self.assertEqual( tbl.sql(flavor="pg", skip_constraints=False), '''CREATE TABLE "my_table" ( "field1" SERIAL PRIMARY KEY );''')
def test_1_UNIQUE(self): tbl = Table.match("CREATE TABLE `my_table` (") tbl.feed("`field1` int UNIQUE") tbl.feed(") ENGINE=InnoDB AUTO_INCREMENT=237442 DEFAULT CHARSET=utf8;") self.assertTrue(tbl.done) self.assertEqual( tbl.sql(flavor="sqlite", skip_constraints=True), '''CREATE TABLE "my_table" ( "field1" INTEGER );''') self.assertEqual( tbl.sql(flavor="sqlite", skip_constraints=False), '''CREATE TABLE "my_table" ( "field1" INTEGER UNIQUE );''')
def test_create(self): tbl = Table.match("CREATE TABLE `my_table` (") self.assertEqual(tbl.name, 'my_table') tbl = Table.match("CREATE TABLE `tbl_name`") self.assertEqual(tbl.name, 'tbl_name') tbl = Table.match("CREATE TEMPORARY TABLE `tbl_name`") self.assertEqual(tbl.name, 'tbl_name') tbl = Table.match("CREATE TABLE IF NOT EXISTS `tbl_name`") self.assertEqual(tbl.name, 'tbl_name') tbl = Table.match("CREATE TEMPORARY TABLE IF NOT EXISTS `tbl_name`") self.assertEqual(tbl.name, 'tbl_name') tbl = Table.match("CREATE TEMPORARY TABLE IF NOT EXISTS `tbl_name` (") self.assertEqual(tbl.name, 'tbl_name') self.assertRaises(Exception, tbl.sql)
def test_empty(self): tbl = Table.match("CREATE TABLE `my_table` (") tbl.feed(") ENGINE=InnoDB AUTO_INCREMENT=237442 DEFAULT CHARSET=utf8;") self.assertTrue(tbl.done)
def test_match_end(self): tbl = Table.match("CREATE TABLE `my_table` (") #tbl.feed(") ENGINE=InnoDB AUTO_INCREMENT=237442 DEFAULT CHARSET=utf8;") stmt = ") ENGINE=InnoDB AUTO_INCREMENT=237442 DEFAULT CHARSET=utf8;" res = tbl.match_end(stmt) self.assertIsNotNone(res)