@@ -35,7 +35,90 @@ pub enum OdbcVariant {
3535 SqlServer ,
3636}
3737
38- impl super :: SqlDialect for OdbcDialect { }
38+ impl super :: SqlDialect for OdbcDialect {
39+ fn sql_list_catalogs ( & self ) -> String {
40+ match self . variant {
41+ OdbcVariant :: Snowflake => {
42+ "SELECT database_name AS catalog_name \
43+ FROM snowflake.information_schema.databases \
44+ ORDER BY database_name"
45+ . into ( )
46+ }
47+ _ => {
48+ "SELECT DISTINCT catalog_name FROM information_schema.schemata \
49+ ORDER BY catalog_name"
50+ . into ( )
51+ }
52+ }
53+ }
54+
55+ fn sql_list_schemas ( & self , catalog : & str ) -> String {
56+ let catalog = catalog. replace ( '\'' , "''" ) ;
57+ match self . variant {
58+ OdbcVariant :: Snowflake => {
59+ let catalog_ident = catalog. replace ( '"' , "\" \" " ) ;
60+ format ! (
61+ "SELECT schema_name \
62+ FROM \" {catalog_ident}\" .information_schema.schemata \
63+ ORDER BY schema_name"
64+ )
65+ }
66+ _ => {
67+ format ! (
68+ "SELECT DISTINCT schema_name FROM information_schema.schemata \
69+ WHERE catalog_name = '{catalog}' ORDER BY schema_name"
70+ )
71+ }
72+ }
73+ }
74+
75+ fn sql_list_tables ( & self , catalog : & str , schema : & str ) -> String {
76+ let schema = schema. replace ( '\'' , "''" ) ;
77+ match self . variant {
78+ OdbcVariant :: Snowflake => {
79+ let catalog_ident = catalog. replace ( '"' , "\" \" " ) ;
80+ format ! (
81+ "SELECT table_name, table_type \
82+ FROM \" {catalog_ident}\" .information_schema.tables \
83+ WHERE table_schema = '{schema}' \
84+ ORDER BY table_name"
85+ )
86+ }
87+ _ => {
88+ let catalog = catalog. replace ( '\'' , "''" ) ;
89+ format ! (
90+ "SELECT DISTINCT table_name, table_type FROM information_schema.tables \
91+ WHERE table_catalog = '{catalog}' AND table_schema = '{schema}' \
92+ ORDER BY table_name"
93+ )
94+ }
95+ }
96+ }
97+
98+ fn sql_list_columns ( & self , catalog : & str , schema : & str , table : & str ) -> String {
99+ let schema = schema. replace ( '\'' , "''" ) ;
100+ let table = table. replace ( '\'' , "''" ) ;
101+ match self . variant {
102+ OdbcVariant :: Snowflake => {
103+ let catalog_ident = catalog. replace ( '"' , "\" \" " ) ;
104+ format ! (
105+ "SELECT column_name, data_type \
106+ FROM \" {catalog_ident}\" .information_schema.columns \
107+ WHERE table_schema = '{schema}' AND table_name = '{table}' \
108+ ORDER BY ordinal_position"
109+ )
110+ }
111+ _ => {
112+ let catalog = catalog. replace ( '\'' , "''" ) ;
113+ format ! (
114+ "SELECT column_name, data_type FROM information_schema.columns \
115+ WHERE table_catalog = '{catalog}' AND table_schema = '{schema}' \
116+ AND table_name = '{table}' ORDER BY ordinal_position"
117+ )
118+ }
119+ }
120+ }
121+ }
39122
40123/// Generic ODBC reader implementing the `Reader` trait.
41124pub struct OdbcReader {
0 commit comments