MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / test_sql

Function test_sql

script/init_db.py:523–559  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

521
522#测试sql是否能执行
523def test_sql():
524
525 dst_dir = '/www/test/db/'
526 if os.path.exists(dst_dir): shutil.rmtree(dst_dir)
527
528 os.makedirs(dst_dir, 755)
529
530 all_tabs = get_database_json(False)
531 for nkey in all_tabs.keys():
532 db_info = all_tabs[nkey]
533
534 print_x('正在同步表到 {} 数据库:{}'.format(db_info['table'], db_info['db']))
535 src_field = get_table_byjson(db_info['table'], db_info['db'])
536 dst_obj = get_db_obj('{}/{}'.format(dst_dir, db_info['db']))
537 if not check_exists_table(dst_obj, db_info['table']):
538 res = dst_obj.execute(src_field['sql'])
539 if str(res).find("error") != -1:
540 print_x("创建表 {} 错误:{}".format(db_info['table'], res))
541 break
542
543 dst_field = get_table_info(dst_obj, db_info['table'])
544
545 n_list = []
546 for field in src_field['field']:
547 if not field in n_list:
548 n_list.append(field)
549
550 for field in dst_field['field']:
551 if not field in n_list:
552 n_list.append(field)
553
554 for field in n_list:
555 if not field in src_field['field']:
556 print('databases.json文件 {} - {} fields 数组里缺少字段:{}'.format(db_info['db'],db_info['table'],field))
557
558 if not field in dst_field['field']:
559 print('databases.json文件 {} - {} sql语句里缺少字段:{}'.format(db_info['db'],db_info['table'],field))
560
561"""
562@name 检查数据库字段

Callers 1

init_db.pyFile · 0.85

Calls 12

get_table_byjsonFunction · 0.85
get_db_objFunction · 0.85
check_exists_tableFunction · 0.85
get_table_infoFunction · 0.85
get_database_jsonFunction · 0.70
print_xFunction · 0.70
existsMethod · 0.45
keysMethod · 0.45
formatMethod · 0.45
executeMethod · 0.45
findMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected