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
Changes from 1 commit
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
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