@@ -160,7 +160,7 @@ where
160
160
let has_hostname = hostname. is_some ( ) ;
161
161
let ( mut client, mut connection) =connect_raw ( socket, tls, has_hostname, config) . await ?;
162
162
163
- if let TargetSessionAttrs :: ReadWrite = config . target_session_attrs {
163
+ if config . target_session_attrs != TargetSessionAttrs :: Any {
164
164
let rows = client. simple_query_raw ( "SHOW transaction_read_only" ) ;
165
165
pin_mut ! ( rows) ;
166
166
@@ -185,11 +185,21 @@ where
185
185
186
186
match next. await . transpose ( ) ?{
187
187
Some ( SimpleQueryMessage :: Row ( row) ) =>{
188
- if row. try_get ( 0 ) ? ==Some ( "on" ) {
188
+ let read_only_result = row. try_get ( 0 ) ?;
189
+ if read_only_result ==Some ( "on" )
190
+ && config. target_session_attrs ==TargetSessionAttrs :: ReadWrite
191
+ {
189
192
return Err ( Error :: connect ( io:: Error :: new (
190
193
io:: ErrorKind :: PermissionDenied ,
191
194
"database does not allow writes" ,
192
195
) ) ) ;
196
+ } else if read_only_result ==Some ( "off" )
197
+ && config. target_session_attrs ==TargetSessionAttrs :: ReadOnly
198
+ {
199
+ return Err ( Error :: connect ( io:: Error :: new (
200
+ io:: ErrorKind :: PermissionDenied ,
201
+ "database is not read only" ,
202
+ ) ) ) ;
193
203
} else {
194
204
break ;
195
205
}