From a5b999a249cf5434e4a2a7fe21cf9b26357bc69f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 6 Sep 2022 11:56:02 +0300 Subject: Set up the self.* variables from query results Set up the appropriate self.* variables from the results of running the appropriate query. --- wqflask/base/data_set.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'wqflask') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index da3c0628..f66bf186 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -628,23 +628,30 @@ class DataSet: try: query = "" _vars = None + query_args = (self.name, self.name, self.name) if self.type == "ProbeSet": - query = """ -SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, ProbeSetFreeze.DataScale, Tissue.Name -FROM ProbeSetFreeze, ProbeFreeze, Tissue -WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id -AND ProbeFreeze.TissueId = Tissue.Id -AND (ProbeSetFreeze.Name = %s OR ProbeSetFreeze.FullName = %s OR ProbeSetFreeze.ShortName = %s""" - _vars = (self.id, self.name, self.fullname, self.shortname, self.data_scale, self.tissue,) + query = ( + "SELECT ProbeSetFreeze.Id, ProbeSetFreeze.Name, " + "ProbeSetFreeze.FullName, ProbeSetFreeze.ShortName, " + "ProbeSetFreeze.DataScale, Tissue.Name " + "FROM ProbeSetFreeze, ProbeFreeze, Tissue " + "WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id " + "AND ProbeFreeze.TissueId = Tissue.Id " + "AND (ProbeSetFreeze.Name = %s OR ProbeSetFreeze.FullName = %s OR ProbeSetFreeze.ShortName = %s)") else: - query = """ -SELECT Id, Name, FullName, ShortName FROM %s -WHERE (Name = %s OR FullName = '%s' OR ShortName = %s)""" + query = ( + "SELECT Id, Name, FullName, ShortName " + f"FROM {self.type}Freeze " + "WHERE (Name = %s OR FullName = %s OR ShortName = %s)") self.tissue = "N/A" - _vars = (self.id, self.name, self.fullname, self.shortname,) with database_connection() as conn, conn.cursor() as cursor: - cursor.execute(query, (query_args,)) + cursor.execute(query, query_args) _vars = cursor.fetchone() + if self.type == "ProbeSet": + (self.id, self.name, self.fullname, self.shortname, + self.data_scale, self.tissue) = _vars + else: + self.id, self.name, self.fullname, self.shortname = _vars except TypeError: pass -- cgit v1.2.3