Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache db: using single quotes for strings #16123

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions conan/internal/cache/db/packages_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _where_clause(self, pref: PkgReference):
self.columns.prev: pref.revision,
}
where_expr = ' AND '.join(
[f'{k}="{v}" ' if v is not None else f'{k} IS NULL' for k, v in where_dict.items()])
[f"{k}='{v}' " if v is not None else f'{k} IS NULL' for k, v in where_dict.items()])
return where_expr

def _set_clause(self, pref: PkgReference, path=None, build_id=None):
Expand All @@ -52,7 +52,7 @@ def _set_clause(self, pref: PkgReference, path=None, build_id=None):
self.columns.timestamp: pref.timestamp,
self.columns.build_id: build_id,
}
set_expr = ', '.join([f'{k} = "{v}"' for k, v in set_dict.items() if v is not None])
set_expr = ', '.join([f"{k} = '{v}'" for k, v in set_dict.items() if v is not None])
return set_expr

def get(self, pref: PkgReference):
Expand Down Expand Up @@ -107,15 +107,15 @@ def update_lru(self, pref):
where_clause = self._where_clause(pref)
lru = timestamp_now()
query = f"UPDATE {self.table_name} " \
f'SET {self.columns.lru} = "{lru}" ' \
f"SET {self.columns.lru} = '{lru}' " \
f"WHERE {where_clause};"
with self.db_connection() as conn:
conn.execute(query)

def remove_build_id(self, pref):
where_clause = self._where_clause(pref)
query = f"UPDATE {self.table_name} " \
f'SET {self.columns.build_id} = "null" ' \
f"SET {self.columns.build_id} = 'null' " \
f"WHERE {where_clause};"
with self.db_connection() as conn:
try:
Expand All @@ -126,8 +126,8 @@ def remove_build_id(self, pref):
def remove_recipe(self, ref: RecipeReference):
# can't use the _where_clause, because that is an exact match on the package_id, etc
query = f"DELETE FROM {self.table_name} " \
f'WHERE {self.columns.reference} = "{str(ref)}" ' \
f'AND {self.columns.rrev} = "{ref.revision}" '
f"WHERE {self.columns.reference} = '{str(ref)}' " \
f"AND {self.columns.rrev} = '{ref.revision}' "
with self.db_connection() as conn:
conn.execute(query)

Expand All @@ -141,7 +141,7 @@ def remove(self, pref: PkgReference):
def get_package_revisions_references(self, pref: PkgReference, only_latest_prev=False):
assert pref.ref.revision, "To search package revisions you must provide a recipe revision."
assert pref.package_id, "To search package revisions you must provide a package id."
check_prev = f'AND {self.columns.prev} = "{pref.revision}" ' if pref.revision else ''
check_prev = f"AND {self.columns.prev} = '{pref.revision}' " if pref.revision else ""
if only_latest_prev:
query = f'SELECT {self.columns.reference}, ' \
f'{self.columns.rrev}, ' \
Expand All @@ -152,17 +152,17 @@ def get_package_revisions_references(self, pref: PkgReference, only_latest_prev=
f'{self.columns.build_id}, ' \
f'{self.columns.lru} ' \
f'FROM {self.table_name} ' \
f'WHERE {self.columns.rrev} = "{pref.ref.revision}" ' \
f'AND {self.columns.reference} = "{str(pref.ref)}" ' \
f'AND {self.columns.pkgid} = "{pref.package_id}" ' \
f"WHERE {self.columns.rrev} = '{pref.ref.revision}' " \
f"AND {self.columns.reference} = '{str(pref.ref)}' " \
f"AND {self.columns.pkgid} = '{pref.package_id}' " \
f'{check_prev} ' \
f'AND {self.columns.prev} IS NOT NULL ' \
f'GROUP BY {self.columns.pkgid} '
else:
query = f'SELECT * FROM {self.table_name} ' \
f'WHERE {self.columns.rrev} = "{pref.ref.revision}" ' \
f'AND {self.columns.reference} = "{str(pref.ref)}" ' \
f'AND {self.columns.pkgid} = "{pref.package_id}" ' \
f"WHERE {self.columns.rrev} = '{pref.ref.revision}' " \
f"AND {self.columns.reference} = '{str(pref.ref)}' " \
f"AND {self.columns.pkgid} = '{pref.package_id}' " \
f'{check_prev} ' \
f'AND {self.columns.prev} IS NOT NULL ' \
f'ORDER BY {self.columns.timestamp} DESC'
Expand All @@ -185,13 +185,13 @@ def get_package_references(self, ref: RecipeReference, only_latest_prev=True):
f'{self.columns.build_id}, ' \
f'{self.columns.lru} ' \
f'FROM {self.table_name} ' \
f'WHERE {self.columns.rrev} = "{ref.revision}" ' \
f'AND {self.columns.reference} = "{str(ref)}" ' \
f"WHERE {self.columns.rrev} = '{ref.revision}' " \
f"AND {self.columns.reference} = '{str(ref)}' " \
f'GROUP BY {self.columns.pkgid} '
else:
query = f'SELECT * FROM {self.table_name} ' \
f'WHERE {self.columns.rrev} = "{ref.revision}" ' \
f'AND {self.columns.reference} = "{str(ref)}" ' \
f"WHERE {self.columns.rrev} = '{ref.revision}' " \
f"AND {self.columns.reference} = '{str(ref)}' " \
f'AND {self.columns.prev} IS NOT NULL ' \
f'ORDER BY {self.columns.timestamp} DESC'
with self.db_connection() as conn:
Expand Down
18 changes: 9 additions & 9 deletions conan/internal/cache/db/recipes_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _where_clause(self, ref):
self.columns.rrev: ref.revision,
}
where_expr = ' AND '.join(
[f'{k}="{v}" ' if v is not None else f'{k} IS NULL' for k, v in where_dict.items()])
[f"{k}='{v}' " if v is not None else f'{k} IS NULL' for k, v in where_dict.items()])
return where_expr

def create(self, path, ref: RecipeReference):
Expand All @@ -54,9 +54,9 @@ def update_timestamp(self, ref: RecipeReference):
assert ref.revision is not None
assert ref.timestamp is not None
query = f"UPDATE {self.table_name} " \
f'SET {self.columns.timestamp} = "{ref.timestamp}" ' \
f'WHERE {self.columns.reference}="{str(ref)}" ' \
f'AND {self.columns.rrev} = "{ref.revision}" '
f"SET {self.columns.timestamp} = '{ref.timestamp}' " \
f"WHERE {self.columns.reference}='{str(ref)}' " \
f"AND {self.columns.rrev} = '{ref.revision}' "
with self.db_connection() as conn:
conn.execute(query)

Expand All @@ -66,7 +66,7 @@ def update_lru(self, ref):
where_clause = self._where_clause(ref)
lru = timestamp_now()
query = f"UPDATE {self.table_name} " \
f'SET {self.columns.lru} = "{lru}" ' \
f"SET {self.columns.lru} = '{lru}' " \
f"WHERE {where_clause};"
with self.db_connection() as conn:
conn.execute(query)
Expand Down Expand Up @@ -95,8 +95,8 @@ def all_references(self):

def get_recipe(self, ref: RecipeReference):
query = f'SELECT * FROM {self.table_name} ' \
f'WHERE {self.columns.reference}="{str(ref)}" ' \
f'AND {self.columns.rrev} = "{ref.revision}" '
f"WHERE {self.columns.reference}='{str(ref)}' " \
f"AND {self.columns.rrev} = '{ref.revision}' "
with self.db_connection() as conn:
r = conn.execute(query)
row = r.fetchone()
Expand All @@ -112,7 +112,7 @@ def get_latest_recipe(self, ref: RecipeReference):
f'MAX({self.columns.timestamp}), ' \
f'{self.columns.lru} ' \
f'FROM {self.table_name} ' \
f'WHERE {self.columns.reference} = "{str(ref)}" ' \
f"WHERE {self.columns.reference} = '{str(ref)}' " \
f'GROUP BY {self.columns.reference} ' # OTHERWISE IT FAILS THE MAX()

with self.db_connection() as conn:
Expand All @@ -126,7 +126,7 @@ def get_latest_recipe(self, ref: RecipeReference):
def get_recipe_revisions_references(self, ref: RecipeReference):
assert ref.revision is None
query = f'SELECT * FROM {self.table_name} ' \
f'WHERE {self.columns.reference} = "{str(ref)}" ' \
f"WHERE {self.columns.reference} = '{str(ref)}' " \
f'ORDER BY {self.columns.timestamp} DESC'

with self.db_connection() as conn:
Expand Down
4 changes: 2 additions & 2 deletions conans/client/store/localdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def clean(self, remote_url=None):
cursor = connection.cursor()
query = "DELETE FROM %s" % REMOTES_USER_TABLE
if remote_url:
query += ' WHERE remote_url="{}"'.format(remote_url)
query += " WHERE remote_url='{}'".format(remote_url)
cursor.execute(query)
try:
# https://github.com/ghaering/pysqlite/issues/109
Expand All @@ -74,7 +74,7 @@ def get_login(self, remote_url):
with self._connect() as connection:
try:
statement = connection.cursor()
statement.execute('select user, token, refresh_token from %s where remote_url="%s"'
statement.execute("select user, token, refresh_token from %s where remote_url='%s'"
% (REMOTES_USER_TABLE, remote_url))
rs = statement.fetchone()
if not rs:
Expand Down