@@ -17,7 +17,14 @@ use fehler::{throw, throws};
1717use log:: { debug, warn} ;
1818use r2d2:: { Pool , PooledConnection } ;
1919use r2d2_mysql:: {
20- mysql:: { prelude:: Queryable , Binary , Opts , OptsBuilder , QueryResult , Row , Text } ,
20+ mysql:: {
21+ consts:: {
22+ ColumnFlags as MySQLColumnFlags , ColumnType as MySQLColumnType , UTF8MB4_GENERAL_CI ,
23+ UTF8_GENERAL_CI ,
24+ } ,
25+ prelude:: Queryable ,
26+ Binary , Opts , OptsBuilder , QueryResult , Row , Text ,
27+ } ,
2128 MySqlConnectionManager ,
2229} ;
2330use rust_decimal:: Decimal ;
96103 assert ! ( !self . queries. is_empty( ) ) ;
97104
98105 let mut conn = self . pool . get ( ) ?;
106+ let server_version_post_5_5_3 = conn. server_version ( ) >= ( 5 , 5 , 3 ) ;
107+
99108 let first_query = & self . queries [ 0 ] ;
100109
101110 match conn. prep ( first_query) {
@@ -104,10 +113,28 @@ where
104113 . columns ( )
105114 . iter ( )
106115 . map ( |col| {
107- (
108- col. name_str ( ) . to_string ( ) ,
109- MySQLTypeSystem :: from ( ( & col. column_type ( ) , & col. flags ( ) ) ) ,
110- )
116+ let col_name = col. name_str ( ) . to_string ( ) ;
117+ let col_type = col. column_type ( ) ;
118+ let col_flags = col. flags ( ) ;
119+ let charset = col. character_set ( ) ;
120+ let charset_is_utf8 = ( server_version_post_5_5_3
121+ && charset == UTF8MB4_GENERAL_CI )
122+ || ( !server_version_post_5_5_3 && charset == UTF8_GENERAL_CI ) ;
123+ if charset_is_utf8
124+ && ( col_type == MySQLColumnType :: MYSQL_TYPE_LONG_BLOB
125+ || col_type == MySQLColumnType :: MYSQL_TYPE_BLOB
126+ || col_type == MySQLColumnType :: MYSQL_TYPE_MEDIUM_BLOB
127+ || col_type == MySQLColumnType :: MYSQL_TYPE_TINY_BLOB )
128+ {
129+ return (
130+ col_name,
131+ MySQLTypeSystem :: Char (
132+ !col_flags. contains ( MySQLColumnFlags :: NOT_NULL_FLAG ) ,
133+ ) ,
134+ ) ;
135+ }
136+ let d = MySQLTypeSystem :: from ( ( & col_type, & col_flags) ) ;
137+ ( col_name, d)
111138 } )
112139 . unzip ( ) ;
113140 self . names = names;
0 commit comments