diff --git a/frappe/database/database.py b/frappe/database/database.py index 6a4e781b44..0f325a746e 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -511,14 +511,10 @@ class Database(object): # Get coulmn and value of the single doctype Accounts Settings account_settings = frappe.db.get_singles_dict("Accounts Settings") """ - result = self.sql(""" - SELECT field, value - FROM `tabSingles` - WHERE doctype = %s - """, doctype) - + result = self.query.get_sql( + "Singles", filters={"doctype": doctype}, fields=["field", "value"] + ).run() dict_ = frappe._dict(result) - return dict_ @staticmethod @@ -547,8 +543,11 @@ class Database(object): if fieldname in self.value_cache[doctype]: return self.value_cache[doctype][fieldname] - val = self.sql("""select `value` from - `tabSingles` where `doctype`=%s and `field`=%s""", (doctype, fieldname)) + val = self.query.get_sql( + table="Singles", + filters={"doctype": doctype, "field": fieldname}, + fields="value", + ).run() val = val[0][0] if val else None df = frappe.get_meta(doctype).get_field(fieldname) diff --git a/frappe/database/query.py b/frappe/database/query.py index 69328cb206..6d2be5fa25 100644 --- a/frappe/database/query.py +++ b/frappe/database/query.py @@ -286,14 +286,13 @@ class Query: ): criterion = self.build_conditions(table, filters, **kwargs) if isinstance(fields, (list, tuple)): - query = criterion.select(*kwargs.get("field_objects")) + query = criterion.select(*kwargs.get("field_objects", fields)) elif isinstance(fields, Criterion): query = criterion.select(fields) else: - if fields=="*": - query = criterion.select(fields) + query = criterion.select(fields) return query diff --git a/frappe/query_builder/builder.py b/frappe/query_builder/builder.py index 630cfea222..a65d50fdeb 100644 --- a/frappe/query_builder/builder.py +++ b/frappe/query_builder/builder.py @@ -18,16 +18,6 @@ class Base: table_name = get_table_name(table_name) return Table(table_name, *args, **kwargs) - -class MariaDB(Base, MySQLQuery): - Field = terms.Field - - @classmethod - def from_(cls, table, *args, **kwargs): - if isinstance(table, str): - table = cls.DocType(table) - return super().from_(table, *args, **kwargs) - @classmethod def into(cls, table, *args, **kwargs): if isinstance(table, str): @@ -40,6 +30,17 @@ class MariaDB(Base, MySQLQuery): table = cls.DocType(table) return super().update(table, *args, **kwargs) + +class MariaDB(Base, MySQLQuery): + Field = terms.Field + + @classmethod + def from_(cls, table, *args, **kwargs): + if isinstance(table, str): + table = cls.DocType(table) + return super().from_(table, *args, **kwargs) + + class Postgres(Base, PostgreSQLQuery): field_translation = {"table_name": "relname", "table_rows": "n_tup_ins"} schema_translation = {"tables": "pg_stat_all_tables"} @@ -69,15 +70,3 @@ class Postgres(Base, PostgreSQLQuery): table = cls.DocType(table) return super().from_(table, *args, **kwargs) - - @classmethod - def into(cls, table, *args, **kwargs): - if isinstance(table, str): - table = cls.DocType(table) - return super().into(table, *args, **kwargs) - - @classmethod - def update(cls, table, *args, **kwargs): - if isinstance(table, str): - table = cls.DocType(table) - return super().update(table, *args, **kwargs) \ No newline at end of file