def execute_query(self, statements: List[str], *params): job_path = JobPath(self.job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): for st in statements: cursor.execute(st, tuple(params)) ret = cursor.fetchall() return ret
def create_table(): with SqliteContext(sqlite_path) as (_, cursor): cursor.execute('''CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL);''')
def create_tables(job_id: str): job_path = JobPath(job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): for s in create_job_kv: cursor.execute(s) for s in create_job_client: cursor.execute(s) for s in create_job_params: cursor.execute(s)
def init_table(self): name, _, statements = self.table_info() job_path = JobPath(self.job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): cursor.execute("SELECT name FROM sqlite_master WHERE type='table'") table_names = [r[0] for r in cursor.fetchall()] if name not in table_names: for st in statements: cursor.execute(st)
def show_data(): with SqliteContext(sqlite_path) as (_, cursor): ret = cursor.execute("select * from COMPANY") for r in ret: print("ID : %d" % r[0]) print("NAME : %s - LEN: %d" % (r[1], len(r[1]))) print("AGE : %s" % r[2]) print("ADDRESS: %s - LEN: %d" % (r[3], len(r[3]))) print("SALARY : %.f" % r[4])
def __get(job_id: str, statement: str, *params): job_path = JobPath(job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): cursor.execute(statement, tuple(params)) ret = cursor.fetchall() return ret
def __save(job_id: str, statement: str, *params): job_path = JobPath(job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): cursor.execute(statement, tuple(params))
def execute_update(self, statements: List[str], *params): job_path = JobPath(self.job_id) with SqliteContext(job_path.sqlite_file) as (_, cursor): for st in statements: cursor.execute(st, tuple(params))
def insert_data(): with SqliteContext(sqlite_path) as (_, cursor): cursor.execute( "insert into COMPANY(ID, NAME, AGE, ADDRESS, SALARY) values (1, 'tom', 18, 'mar', 10086.0)" )