aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-26 11:44:53 +0300
committerFrederick Muriuki Muriithi2021-11-29 12:05:16 +0300
commitf88d8e4446c8c9d6693197a452669e0e9c8ea812 (patch)
tree5a5c9c3c68f8a33efb5c8b2445672fffab4bac32 /gn3/db
parent40f264876f2309fcccfcd3d04a2999bdf3fa5d98 (diff)
downloadgenenetwork3-f88d8e4446c8c9d6693197a452669e0e9c8ea812.tar.gz
Fix query parametrisation
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * Pass parameters to the query the way the MySQL driver expects.
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/correlations.py16
-rw-r--r--gn3/db/species.py2
2 files changed, 11 insertions, 7 deletions
diff --git a/gn3/db/correlations.py b/gn3/db/correlations.py
index a1daa3c..c838597 100644
--- a/gn3/db/correlations.py
+++ b/gn3/db/correlations.py
@@ -23,8 +23,8 @@ def get_filename(target_db_name: str, conn: Any) -> str:
"""
with conn.cursor() as cursor:
cursor.execute(
- "SELECT Id, FullName from ProbeSetFreeze WHERE Name-%s",
- target_db_name)
+ "SELECT Id, FullName from ProbeSetFreeze WHERE Name=%s",
+ (target_db_name,))
result = cursor.fetchone()
if result:
return "ProbeSetFreezeId_{tid}_FullName_{fname}.txt".format(
@@ -398,9 +398,12 @@ def fetch_sample_ids(
"AND Species.name=%(species_name)s")
with conn.cursor() as cursor:
cursor.execute(
- query, samples_names=tuple(sample_names),
- species_name=species_name)
return cursor.fetchall()
+ query,
+ {
+ "samples_names": tuple(sample_names),
+ "species_name": species_name
+ })
def build_query_sgo_lit_corr(
db_type: str, temp_table: str, sample_id_columns: str,
@@ -511,8 +514,9 @@ def fetch_all_database_data(# pylint: disable=[R0913, R0914]
query, data_start_pos = __build_query__(sample_ids, temp_table)
with conn.cursor() as cursor:
cursor.execute(
- query, db_name=db_name,
- **{f"T{item}_sample_id": item for item in sample_ids})
+ query,
+ {"db_name": db_name,
+ **{f"T{item}_sample_id": item for item in sample_ids}})
return (cursor.fetchall(), data_start_pos)
sample_ids = tuple(
diff --git a/gn3/db/species.py b/gn3/db/species.py
index 20170ba..5b8e096 100644
--- a/gn3/db/species.py
+++ b/gn3/db/species.py
@@ -71,6 +71,6 @@ def species_name(conn: Any, group: str) -> str:
("SELECT Species.Name FROM Species, InbredSet "
"WHERE InbredSet.Name = %(group_name)s "
"AND InbredSet.SpeciesId = Species.Id"),
- group_name=group_name)
+ {"group_name": group})
return cursor.fetchone()[0]
return None