@@ -322,20 +322,12 @@ pub enum IsolationLevel {
322322}
323323
324324impl IsolationLevel {
325- fn to_set_query ( & self ) -> & ' static str {
325+ fn to_sql ( & self ) -> & ' static str {
326326 match * self {
327- IsolationLevel :: ReadUncommitted => {
328- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"
329- }
330- IsolationLevel :: ReadCommitted => {
331- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED"
332- }
333- IsolationLevel :: RepeatableRead => {
334- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ"
335- }
336- IsolationLevel :: Serializable => {
337- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE"
338- }
327+ IsolationLevel :: ReadUncommitted => "READ UNCOMMITTED" ,
328+ IsolationLevel :: ReadCommitted => "READ COMMITTED" ,
329+ IsolationLevel :: RepeatableRead => "REPEATABLE READ" ,
330+ IsolationLevel :: Serializable => "SERIALIZABLE" ,
339331 }
340332 }
341333
@@ -1246,7 +1238,13 @@ impl Connection {
12461238 ///
12471239 /// This will not change the behavior of an active transaction.
12481240 pub fn set_transaction_isolation ( & self , level : IsolationLevel ) -> Result < ( ) > {
1249- self . batch_execute ( level. to_set_query ( ) )
1241+ self . set_transaction_config ( transaction:: Config :: new ( ) . isolation_level ( level) )
1242+ }
1243+
1244+ pub fn set_transaction_config ( & self , config : & transaction:: Config ) -> Result < ( ) > {
1245+ let mut command = "SET SESSION CHARACTERISTICS AS TRANSACTION" . to_owned ( ) ;
1246+ config. build_command ( & mut command) ;
1247+ self . batch_execute ( & command)
12501248 }
12511249
12521250 /// Execute a sequence of SQL statements.
@@ -1491,3 +1489,7 @@ trait TransactionInternals<'conn> {
14911489
14921490 fn depth ( & self ) -> u32 ;
14931491}
1492+
1493+ trait ConfigInternals {
1494+ fn build_command ( & self , s : & mut String ) ;
1495+ }
0 commit comments