@@ -209,8 +209,8 @@ class Database(AbstractDatabase):
209
209
Instanciated using :meth:`~data_diff.connect_to_uri`
210
210
"""
211
211
212
- DATETIME_TYPES = NotImplemented
213
- default_schema = NotImplemented
212
+ DATETIME_TYPES = {}
213
+ default_schema = None
214
214
215
215
def query (self , sql_ast : SqlOrStr , res_type : type ):
216
216
"Query the given SQL code/AST, and attempt to convert the result to type 'res_type'"
@@ -306,13 +306,15 @@ def query_table_schema(self, path: DbPath) -> Dict[str, ColType]:
306
306
307
307
def _normalize_table_path (self , path : DbPath ) -> DbPath :
308
308
if len (path ) == 1 :
309
- return self .default_schema , path [0 ]
310
- elif len (path ) == 2 :
311
- return path
309
+ if self .default_schema :
310
+ return self .default_schema , path [0 ]
311
+ elif len (path ) != 2 :
312
+ raise ValueError (
313
+ f"{ self .__class__ .__name__ } : Bad table path for { self } : '{ '.' .join (path )} '. Expected form: schema.table"
314
+ )
315
+
316
+ return path
312
317
313
- raise ValueError (
314
- f"{ self .__class__ .__name__ } : Bad table path for { self } : '{ '.' .join (path )} '. Expected form: schema.table"
315
- )
316
318
317
319
def parse_table_name (self , name : str ) -> DbPath :
318
320
return parse_table_name (name )
@@ -713,6 +715,14 @@ def normalize_value_by_type(self, value: str, coltype: ColType) -> str:
713
715
714
716
return self .to_string (f"{ value } " )
715
717
718
+ def select_table_schema (self , path : DbPath ) -> str :
719
+ schema , table = self ._normalize_table_path (path )
720
+
721
+ return (
722
+ "SELECT column_name, data_type, datetime_precision, numeric_precision, numeric_scale FROM information_schema.columns "
723
+ f"WHERE table_name = '{ table .lower ()} ' AND table_schema = '{ schema .lower ()} '"
724
+ )
725
+
716
726
717
727
class MsSQL (ThreadedDatabase ):
718
728
"AKA sql-server"
0 commit comments