@@ -45,6 +45,13 @@ pub trait Dialect {
4545 fn interval_style ( & self ) -> IntervalStyle {
4646 IntervalStyle :: PostgresVerbose
4747 }
48+
49+ // Does the dialect use CHAR to cast Utf8 rather than TEXT?
50+ // E.g. MySQL requires CHAR instead of TEXT and automatically produces a string with
51+ // the VARCHAR, TEXT or LONGTEXT data type based on the length of the string
52+ fn use_char_for_utf8_cast ( & self ) -> bool {
53+ false
54+ }
4855}
4956
5057/// `IntervalStyle` to use for unparsing
@@ -103,6 +110,10 @@ impl Dialect for MySqlDialect {
103110 fn interval_style ( & self ) -> IntervalStyle {
104111 IntervalStyle :: MySQL
105112 }
113+
114+ fn use_char_for_utf8_cast ( & self ) -> bool {
115+ true
116+ }
106117}
107118
108119pub struct SqliteDialect { }
@@ -118,6 +129,7 @@ pub struct CustomDialect {
118129 supports_nulls_first_in_sort : bool ,
119130 use_timestamp_for_date64 : bool ,
120131 interval_style : IntervalStyle ,
132+ use_char_for_utf8_cast : bool ,
121133}
122134
123135impl Default for CustomDialect {
@@ -127,6 +139,7 @@ impl Default for CustomDialect {
127139 supports_nulls_first_in_sort : true ,
128140 use_timestamp_for_date64 : false ,
129141 interval_style : IntervalStyle :: SQLStandard ,
142+ use_char_for_utf8_cast : false ,
130143 }
131144 }
132145}
@@ -158,6 +171,10 @@ impl Dialect for CustomDialect {
158171 fn interval_style ( & self ) -> IntervalStyle {
159172 self . interval_style
160173 }
174+
175+ fn use_char_for_utf8_cast ( & self ) -> bool {
176+ self . use_char_for_utf8_cast
177+ }
161178}
162179
163180/// `CustomDialectBuilder` to build `CustomDialect` using builder pattern
@@ -179,6 +196,7 @@ pub struct CustomDialectBuilder {
179196 supports_nulls_first_in_sort : bool ,
180197 use_timestamp_for_date64 : bool ,
181198 interval_style : IntervalStyle ,
199+ use_char_for_utf8_cast : bool ,
182200}
183201
184202impl Default for CustomDialectBuilder {
@@ -194,6 +212,7 @@ impl CustomDialectBuilder {
194212 supports_nulls_first_in_sort : true ,
195213 use_timestamp_for_date64 : false ,
196214 interval_style : IntervalStyle :: PostgresVerbose ,
215+ use_char_for_utf8_cast : false ,
197216 }
198217 }
199218
@@ -203,6 +222,7 @@ impl CustomDialectBuilder {
203222 supports_nulls_first_in_sort : self . supports_nulls_first_in_sort ,
204223 use_timestamp_for_date64 : self . use_timestamp_for_date64 ,
205224 interval_style : self . interval_style ,
225+ use_char_for_utf8_cast : self . use_char_for_utf8_cast ,
206226 }
207227 }
208228
@@ -235,4 +255,9 @@ impl CustomDialectBuilder {
235255 self . interval_style = interval_style;
236256 self
237257 }
258+
259+ pub fn with_use_char_for_utf8_cast ( mut self , use_char_for_utf8_cast : bool ) -> Self {
260+ self . use_char_for_utf8_cast = use_char_for_utf8_cast;
261+ self
262+ }
238263}
0 commit comments