You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

import pymysql
import pandas as pd
conn = pymysql.connect(user="root", password="123123", database="tree",
host="127.0.0.1", port=3306)
class DbUtil():
@staticmethod
def insert_to_fractal(name, e_name, basic_pattern, function_code, vars):
sql = """
insert into fractal(name, e_name, basic_pattern, function_code, vars) values (%s, %s, %s, %s, %s)
"""
cursor = conn.cursor()
cursor.execute(sql, (name, e_name, basic_pattern, function_code, vars))
conn.commit()
id = cursor.lastrowid
return id
@staticmethod
def update_to_fractal(fractal_id, name, e_name, basic_pattern, function_code, vars):
sql = """
update fractal set name=%s, e_name=%s, basic_pattern=%s, function_code=%s, vars=%s where id=%s
"""
cursor = conn.cursor()
cursor.execute(sql, (name, e_name, basic_pattern, function_code, vars, fractal_id))
conn.commit()
@staticmethod
def insert_to_var(name, value, comment, fractal_id):
sql = f"insert into fractal_var values ('{name}', '{value}', '{comment}', {fractal_id})"
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
@staticmethod
def delete_fractal(id):
conn.cursor().execute(f"delete from fractal_var where fractal_id={id}")
conn.commit()
conn.cursor().execute(f"delete from fractal where id={id}")
conn.commit()
@staticmethod
def execute(sql):
return pd.read_sql(sql, con=conn)
@staticmethod
def update(sql):
conn.cursor().execute(sql)
conn.commit()
@staticmethod
def query_fractal_by_id(id):
return pd.read_sql("select * from fractal where id={}".format(id), con=conn)
@staticmethod
def query_fractal_var_by_id(id):
return pd.read_sql("select * from fractal_var where fractal_id={}".format(id), con=conn)