def test_simpleselect(): sql = u""" delete a, b from student a, teacher b where a.id=b.name and b.age = 32; """ tokens = mtp.mysql_token_parser(sql) print(tokens) assert isinstance(tokens, dict)
def test_simpleselect(): sql = u""" UPDATE table_name SET field1='new-value1', field2='new-value2' WHERE id=23 and name="css"; """ tokens = mtp.mysql_token_parser(sql) print(tokens) assert isinstance(tokens, dict)
def test_simpleselect(): sql = u""" insert into teacher (age, sex) values (25, 'women'), (30, 'women'); """ tokens = mtp.mysql_token_parser(sql) print(tokens) assert isinstance(tokens, dict)
def test_modifycolumns(): sql = u""" ALTER TABLE tab_name MODIFY COLUMN amount bigint DEFAULT 0 COMMENT '数量', MODIFY COLUMN sumAmt bigint DEFAULT 0 COMMENT '总数量', MODIFY COLUMN amount bigint DEFAULT 0 COMMENT 'name数量'; """ tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict)
def test_simpleselect(): sql = u""" select id as qq, name as ww, age as ee, class as rr from student as s, teacher as t where name='cs' and age=26; """ sql2 = """ select * from teacher where age<=26 and (sex="man" or age >26) and sex="women"; """ tokens = mtp.mysql_token_parser(sql2) assert isinstance(tokens, dict)
def test_createtable(response): """Sample pytest test function with the pytest fixture as an argument.""" # from bs4 import BeautifulSoup # assert 'GitHub' in BeautifulSoup(response.content).title.string sql = u""" CREATE TABLE tab_name ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键', uid int(2) NOT NULL COMMENT '唯一流水id', okmysite DECIMAL(6,2) NOT NULL COMMENT 'cccc', name varchar(20) NOT NULL DEFAULT '' COMMENT '名称', amount DOUBLE(6,2) NOT NULL DEFAULT 0 COMMENT '数量', create_date date NOT NULL DEFAULT '1000-01-01' COMMENT '创建日期', create_time datetime DEFAULT '1000-01-01 00:00:00' COMMENT '创建时间', update_time timestamp default current_timestamp on update current_timestamp COMMENT '更新时间(会自动更新,不需要刻意程序更新)', PRIMARY KEY (id), UNIQUE KEY uniq_uid (uid, ccccc), KEY idx_name (name, wwwww), KEY idx_cscscsc (data, nunm, ssw) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='cs'; """ tokens = mtp.mysql_token_parser(sql) print(tokens) assert isinstance(tokens, dict) hope_tablename = 'tab_name' assert hope_tablename == tokens['data']['data'][_c.TABLE_NAME] hope_engine = 'InnoDB' assert hope_engine == tokens['data']['data'][_c.TABLE_OPTION_ENGINE] hope_charset = 'utf8' assert hope_charset == tokens['data']['data'][_c.TABLE_OPTION_CHARSET] hope_column_len = 8 assert hope_column_len == len( tokens['data']['data'][_c.CREATE_DEFINITIONS]['columns']) hope_common_index_len = 2 assert hope_common_index_len == len( tokens['data']['data'][_c.CREATE_DEFINITIONS]['indexs'][_c.COMMON_KEY]) hope_columnname = [ "id", "uid", "name", "amount", "create_date", "create_time", "update_time", "okmysite" ] for i in tokens['data']['data'][_c.CREATE_DEFINITIONS]['columns']: assert i[_c.COLUMN_NAME] in hope_columnname
def test_adduniqueindexs(): sql = u"ALTER TABLE tab_name ADD UNIQUE uniq_name (name(20), age);" tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict) hope_tablename = 'tab_name' assert hope_tablename == tokens['data']['data'][_c.TABLE_NAME] hope_indexname = 'uniq_name' assert hope_indexname == tokens['data']['data']['alter_data'][0]['data'][ _c.INDEX_NAME] hope_columnname = ['name', 'age'] assert hope_columnname == tokens['data']['data']['alter_data'][0]['data'][ _c.INDEX_DEFINITION]['columns']
def test_dropcolumns(): sql = u"ALTER TABLE tab_name DROP COLUMN address1, DROP COLUMN address2, DROP INDEX uniq_name, DROP PRIMARY KEY;" tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict) hope_tablename = 'tab_name' assert hope_tablename == tokens['data']['data'][_c.TABLE_NAME] hope_drop_len = 4 assert hope_drop_len == len(tokens['data']['data']['alter_data']) hope_columnname = ['address1', 'address2'] assert tokens['data']['data']['alter_data'][0]['data'][ _c.COLUMN_NAME] in hope_columnname assert tokens['data']['data']['alter_data'][1]['data'][ _c.COLUMN_NAME] in hope_columnname
def test_addindexs(): sql = u"ALTER TABLE t_a_gun2_6_dw_pfm_emp_cm ADD INDEX \ idx_eob_date(empid_org_bus (200),pfm_date);" tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict) hope_tablename = 't_a_gun2_6_dw_pfm_emp_cm' assert hope_tablename == tokens['data']['data'][_c.TABLE_NAME] hope_indexname = 'idx_eob_date' assert hope_indexname == tokens['data']['data']['alter_data'][0]['data'][ _c.INDEX_NAME] hope_columnname = ['empid_org_bus', 'pfm_date'] assert hope_columnname == tokens['data']['data']['alter_data'][0]['data'][ _c.INDEX_DEFINITION]['columns']
def test_addcolumns(): sql = u"ALTER TABLE tab_name ADD address01 varchar(100) NOT NULL \ DEFAULT '' COMMENT '地址1' , ADD address02 varchar(100) NOT \ NULL DEFAULT '' COMMENT '地址2', ADD INDEX \ idx_eob_date(empid_org_bus (200),pfm_date), ADD PRIMARY KEY (id);" tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict) hope_tablename = 'tab_name' assert hope_tablename == tokens['data']['data'][_c.TABLE_NAME] hope_add_len = 4 assert hope_add_len == len(tokens['data']['data']['alter_data']) hope_columnname = ['address01', 'address02'] assert tokens['data']['data']['alter_data'][0]['data'][ _c.COLUMN_NAME] in hope_columnname assert tokens['data']['data']['alter_data'][1]['data'][ _c.COLUMN_NAME] in hope_columnname
def test_changecolumns(): sql = u"ALTER TABLE tab_name CHANGE amount new_amount bigint DEFAULT 0 COMMENT 'name数量';" tokens = mtp.mysql_token_parser(sql) assert isinstance(tokens, dict)