提交代码
This commit is contained in:
parent
b3a50d39b1
commit
400933b3da
|
@ -63,7 +63,7 @@ def mysql_config():
|
|||
mysql_info_dict['insert_list'] = insert_list
|
||||
|
||||
# delete sql
|
||||
del_sql = "delete FROM "+ table_name + " where 1=1 limit 2"
|
||||
del_sql = "delete FROM "+ table_name + " where 1=1 limit 100"
|
||||
mysql_info_dict['del_sql'] = del_sql
|
||||
|
||||
|
||||
|
@ -75,15 +75,57 @@ def mysql_config():
|
|||
|
||||
|
||||
def oracle_config():
|
||||
mysql_info_dict={}
|
||||
mysql_info_dict['driver_name'] = "com.mysql.jdbc.Driver"
|
||||
mysql_info_dict['driver_jar'] = "mysql-connector-java-8.0.29.jar"
|
||||
driver_jar_path = etc_dir / "driver" / mysql_info_dict['driver_jar']
|
||||
mysql_info_dict['driver_jar_path'] = str(driver_jar_path)
|
||||
|
||||
mysql_info_dict['jdbc_url'] = "jdbc:mysql://10.10.29.9:3306/test2"
|
||||
mysql_info_dict['db_user'] = "root"
|
||||
mysql_info_dict['db_password'] = "Unary@2023"
|
||||
oracle_info_dict={}
|
||||
oracle_info_dict['driver_name'] = "oracle.jdbc.OracleDriver"
|
||||
oracle_info_dict['driver_jar'] = "ojdbc8-12.2.0.1.jar"
|
||||
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:@10.10.13.21:1521:a"
|
||||
oracle_info_dict['db_user'] = "unary"
|
||||
oracle_info_dict['db_password'] = "unary2023"
|
||||
|
||||
return(mysql_info_dict)
|
||||
#create table sql
|
||||
# now_hours = get_now()
|
||||
#TODO(MH):根据时间生成不同的表
|
||||
table_name = "ORACLE_TEST"
|
||||
create_sql_string = 'CREATE TABLE "'
|
||||
create_sql_string += table_name + '" '
|
||||
create_sql_string += '("UUID" VARCHAR2(50),'
|
||||
create_sql_string += '"ID" NUMBER(38,0), '
|
||||
create_sql_string += '"NAME" VARCHAR2(50),'
|
||||
create_sql_string += '"MOBILE" VARCHAR2(50),'
|
||||
create_sql_string += '"SSN" VARCHAR2(50),'
|
||||
create_sql_string += '"SEX" NUMBER(*,0), '
|
||||
create_sql_string += '"EMAIL" VARCHAR2(50), '
|
||||
create_sql_string += '"JOB" VARCHAR2(50),'
|
||||
create_sql_string += '"ADDRESS" VARCHAR2(100),'
|
||||
create_sql_string += '"ACTIME_TIME" VARCHAR2(50))'
|
||||
oracle_info_dict['create_sql_string'] = create_sql_string
|
||||
|
||||
|
||||
# insert into sql
|
||||
insert_list = []
|
||||
data = faker_data.faker_data(lines=2)[1:]
|
||||
for a in data:
|
||||
#拼接sql
|
||||
insert_sql_string = "INSERT INTO " + 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 + ")"
|
||||
|
||||
insert_list.append(insert_sql_string)
|
||||
# 返回所有的插入语句
|
||||
oracle_info_dict['insert_list'] = insert_list
|
||||
|
||||
# delete sql
|
||||
del_sql = "delete FROM "+ table_name + " WHERE rownum<=100"
|
||||
oracle_info_dict['del_sql'] = del_sql
|
||||
|
||||
|
||||
# uptata sql
|
||||
updata_sql = "UPDATE "+ table_name + " t SET t.job='测试' WHERE t.name like '李%' AND sex = 1 AND id = 1 "
|
||||
oracle_info_dict['updata_sql'] = updata_sql
|
||||
|
||||
return(oracle_info_dict)
|
||||
|
||||
|
|
|
@ -8,13 +8,26 @@ import jaydebeapi
|
|||
from schedule import every, repeat, run_pending
|
||||
|
||||
|
||||
"""
|
||||
说明:
|
||||
1. 用于数据库的持续增、删、改,目前支持MySQL和Oracle
|
||||
2. DBConfig.py 为数据库连接配置,使用时需要修改连接信息
|
||||
3. 脚本运行会创建一个测试表
|
||||
4. 每秒往测试表中插入1条数据
|
||||
5. 每5分钟删除100条数据
|
||||
6. 每1小时,修改一下数据
|
||||
"""
|
||||
|
||||
# 目前支持 MySQL和Oracle两种数据库,其他的数据库需要做适配
|
||||
DBType = "mysql"
|
||||
|
||||
|
||||
#获取连接信息
|
||||
def get_db_info(DBType = "mysql"):
|
||||
def get_db_info(dbtype=DBType):
|
||||
db_config = {}
|
||||
if DBType == "mysql":
|
||||
if dbtype == "mysql":
|
||||
db_config = DBConfig.mysql_config()
|
||||
elif DBType == "mysql":
|
||||
elif dbtype == "oracle":
|
||||
db_config = DBConfig.oracle_config()
|
||||
else:
|
||||
assert False ,"DBType is not support."
|
||||
|
@ -42,6 +55,7 @@ def execute_sql(sql):
|
|||
def create_table():
|
||||
print("start create table...")
|
||||
sql_string = db_config["create_sql_string"]
|
||||
|
||||
execute_sql(sql_string)
|
||||
|
||||
|
||||
|
@ -58,7 +72,7 @@ def insert_data():
|
|||
|
||||
|
||||
#每5分钟删除100条数据
|
||||
@repeat(every(10).seconds)
|
||||
@repeat(every(5).minutes)
|
||||
def dalete_data():
|
||||
print("dalete data....")
|
||||
sql_string = db_config["del_sql"]
|
||||
|
@ -66,7 +80,7 @@ def dalete_data():
|
|||
|
||||
|
||||
#每1小时,修改一下数据
|
||||
@repeat(every(20).seconds)
|
||||
@repeat(every(1).hours)
|
||||
def updata_data():
|
||||
print("updata data ....")
|
||||
sql_string = db_config["updata_sql"]
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue