diff --git a/bin/DBConfig.py b/bin/DBConfig.py index 0ae47c6..4df9a7d 100644 --- a/bin/DBConfig.py +++ b/bin/DBConfig.py @@ -87,7 +87,7 @@ def oracle_config(): driver_jar_path = etc_dir / "driver" / oracle_info_dict['driver_jar'] oracle_info_dict['driver_jar_path'] = str(driver_jar_path) #这里要连接到具体的实例 - oracle_info_dict['jdbc_url'] = "jdbc:oracle:thin:@" + config['IP'] + ":" + config['PROT'] + "/" + config['DATABASES'] + oracle_info_dict['jdbc_url'] = "jdbc:oracle:thin:@" + config['IP'] + ":" + config['PROT'] + "/" + config['SERVER'] oracle_info_dict['db_user'] = config['DBUSER'] oracle_info_dict['db_password'] = config['DBPASSWD'] @@ -114,7 +114,7 @@ def oracle_config(): data = faker_data.faker_data(lines=config['InsertRows'])[1:] for a in data: #拼接sql - insert_sql_string = "INSERT INTO " + table_name + insert_sql_string = 'INSERT INTO ' + config['DATABASES'] + '."' + table_name + '" ' insert_sql_string += " t (uuid, id, name, mobile, ssn, sex, email, job, address, actime_time) VALUES(" str_data = ','.join("'{0}'".format(x) for x in a) insert_sql_string += str_data + ")" @@ -124,12 +124,12 @@ def oracle_config(): oracle_info_dict['insert_list'] = insert_list # delete sql - del_sql = "delete FROM "+ table_name + " WHERE rownum<=100" + del_sql = 'delete FROM "'+ config['DATABASES'] + '."' + table_name + '"WHERE rownum<=100' oracle_info_dict['del_sql'] = del_sql # uptata sql - updata_sql = "UPDATE "+ table_name + " t SET t.job='unary_测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " + updata_sql = "UPDATE "+ config['DATABASES'] + '."' + table_name + '" '+ " t SET t.job='unary_测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 " oracle_info_dict['updata_sql'] = updata_sql return(oracle_info_dict) diff --git a/bin/SQLDataCreating.py b/bin/SQLDataCreating.py index b9c59fe..ddf43b2 100644 --- a/bin/SQLDataCreating.py +++ b/bin/SQLDataCreating.py @@ -50,7 +50,8 @@ def execute_sql(sql): with conn.cursor() as curs: curs.execute(sql) -@repeat(every().monday) +# 按周创建,这里不采用这种方式,通过插入来触发 +#@repeat(every().monday) def create_table(): print("start create table...") sql_string = db_config["create_sql_string"] @@ -63,16 +64,18 @@ def create_table(): #每秒插入200条数据 @repeat(every(2).seconds) def insert_data(): - create_table() print("insert data ....") #重新获取一下,确保每次的插入的数据都不一样 db_config2 = get_db_info() print("insert data ...."+db_config2["jdbc_url"]) insert_list = db_config2["insert_list"] #执行插入 - for sql_string in insert_list: - execute_sql(sql_string) - + try: + for sql_string in insert_list: + execute_sql(sql_string) + # 出错可能是表不存在,这里触发一下建表 + except: + create_table() #每5分钟删除100条数据 @repeat(every(5).minutes) diff --git a/etc/test_config.yml b/etc/test_config.yml index 65e51fd..db71fb6 100644 --- a/etc/test_config.yml +++ b/etc/test_config.yml @@ -1,17 +1,17 @@ #数据库配置文件 # 数据库类型,目前仅支持MySQL和Oracle -DBType: MySQL +DBType: Oracle # 数据库地址 -IP: "10.10.13.167" -PROT: "3306" +IP: "10.10.29.41" +PROT: "1521" # 数据库用户名 -DBUSER: "root" +DBUSER: "test" # 数据库密码 -DBPASSWD: "111111" +DBPASSWD: "test123" # 库名 -DATABASES: "test" +DATABASES: "TEST" +# 服务名-Oracle +SERVER: "orcl" # 每秒中插入多少条数据 InsertRows: 200 - - diff --git a/requirements.txt b/requirements.txt index 18cfead..78c7513 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ PyYAML==6.0.1 faker==19.12.0 schedule==1.2.1 +JPype1==1.4.1 JayDeBeApi==1.2.3