Fix column's statistics errors
This commit is contained in:
@@ -87,6 +87,10 @@ class BaseDriver(ABC):
|
|||||||
"""Returns list of database name strings."""
|
"""Returns list of database name strings."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def quote_identifier(self, name: str) -> str:
|
||||||
|
"""Wrap an identifier in the DB-appropriate quote characters."""
|
||||||
|
return f'"{name}"'
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_tables(self, database: str) -> list:
|
def get_tables(self, database: str) -> list:
|
||||||
"""Returns list of TableInfo for the given database."""
|
"""Returns list of TableInfo for the given database."""
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ class MSSQLDriver(BaseDriver):
|
|||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
self.db_type = "mssql"
|
self.db_type = "mssql"
|
||||||
|
|
||||||
|
def quote_identifier(self, name: str) -> str:
|
||||||
|
return f"[{name}]"
|
||||||
|
|
||||||
def _conn_str(self) -> str:
|
def _conn_str(self) -> str:
|
||||||
host = self.config.get("host", "localhost")
|
host = self.config.get("host", "localhost")
|
||||||
port = int(self.config.get("port", 1433))
|
port = int(self.config.get("port", 1433))
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ class MySQLDriver(BaseDriver):
|
|||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
self.db_type = "mysql"
|
self.db_type = "mysql"
|
||||||
|
|
||||||
|
def quote_identifier(self, name: str) -> str:
|
||||||
|
return f"`{name}`"
|
||||||
|
|
||||||
def _connect_kwargs(self) -> dict:
|
def _connect_kwargs(self) -> dict:
|
||||||
kw = {
|
kw = {
|
||||||
"host": self.config.get("host", "localhost"),
|
"host": self.config.get("host", "localhost"),
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ class _StatsWorker(QThread):
|
|||||||
self._column = column
|
self._column = column
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
col = self._column
|
q = self._driver.quote_identifier
|
||||||
tbl = self._table
|
col = q(self._column)
|
||||||
|
tbl = q(self._table)
|
||||||
try:
|
try:
|
||||||
_, rows, _ = self._driver.execute_query(
|
_, rows, _ = self._driver.execute_query(
|
||||||
f'SELECT COUNT(*), COUNT("{col}"), COUNT(DISTINCT "{col}"), '
|
f'SELECT COUNT(*), COUNT({col}), COUNT(DISTINCT {col}), '
|
||||||
f'MIN("{col}"), MAX("{col}") FROM "{tbl}"'
|
f'MIN({col}), MAX({col}) FROM {tbl}'
|
||||||
)
|
)
|
||||||
total, non_null, distinct, min_val, max_val = rows[0]
|
total, non_null, distinct, min_val, max_val = rows[0]
|
||||||
null_count = (total or 0) - (non_null or 0)
|
null_count = (total or 0) - (non_null or 0)
|
||||||
@@ -35,7 +36,7 @@ class _StatsWorker(QThread):
|
|||||||
avg_val = None
|
avg_val = None
|
||||||
try:
|
try:
|
||||||
_, avg_rows, _ = self._driver.execute_query(
|
_, avg_rows, _ = self._driver.execute_query(
|
||||||
f'SELECT AVG("{col}") FROM "{tbl}"'
|
f'SELECT AVG({col}) FROM {tbl}'
|
||||||
)
|
)
|
||||||
avg_val = avg_rows[0][0]
|
avg_val = avg_rows[0][0]
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user