@@ -75,8 +75,6 @@ pub use transaction::Transaction;
75
75
76
76
use error:: { Error , ConnectError , SqlState , DbError } ;
77
77
use io:: { StreamWrapper , NegotiateSsl } ;
78
- use message:: Backend :: * ;
79
- use message:: Frontend :: * ;
80
78
use message:: { Frontend , Backend , RowDescriptionEntry } ;
81
79
use message:: { WriteMessage , ReadMessage } ;
82
80
use notification:: { Notifications , Notification } ;
@@ -285,7 +283,7 @@ pub fn cancel_query<T>(params: T,
285
283
let params = try!( params. into_connect_params ( ) . map_err ( ConnectError :: ConnectParams ) ) ;
286
284
let mut socket = try!( priv_io:: initialize_stream ( & params, ssl) ) ;
287
285
288
- try!( socket. write_message ( & CancelRequest {
286
+ try!( socket. write_message ( & Frontend :: CancelRequest {
289
287
code : message:: CANCEL_CODE ,
290
288
process_id : data. process_id ,
291
289
secret_key : data. secret_key ,
@@ -436,7 +434,7 @@ impl InnerConnection {
436
434
options. push ( ( "database" . to_owned ( ) , database) ) ;
437
435
}
438
436
439
- try!( conn. write_messages ( & [ StartupMessage {
437
+ try!( conn. write_messages ( & [ Frontend :: StartupMessage {
440
438
version : message:: PROTOCOL_VERSION ,
441
439
parameters : & options,
442
440
} ] ) ) ;
@@ -445,12 +443,12 @@ impl InnerConnection {
445
443
446
444
loop {
447
445
match try!( conn. read_message ( ) ) {
448
- BackendKeyData { process_id, secret_key } => {
446
+ Backend :: BackendKeyData { process_id, secret_key } => {
449
447
conn. cancel_data . process_id = process_id;
450
448
conn. cancel_data . secret_key = secret_key;
451
449
}
452
- ReadyForQuery { .. } => break ,
453
- ErrorResponse { fields } => return DbError :: new_connect ( fields) ,
450
+ Backend :: ReadyForQuery { .. } => break ,
451
+ Backend :: ErrorResponse { fields } => return DbError :: new_connect ( fields) ,
454
452
_ => return Err ( ConnectError :: Io ( bad_response ( ) ) ) ,
455
453
}
456
454
}
@@ -533,12 +531,12 @@ impl InnerConnection {
533
531
debug_assert ! ( !self . desynchronized) ;
534
532
loop {
535
533
match try_desync ! ( self , self . stream. read_message( ) ) {
536
- NoticeResponse { fields } => {
534
+ Backend :: NoticeResponse { fields } => {
537
535
if let Ok ( err) = DbError :: new_raw ( fields) {
538
536
self . notice_handler . handle_notice ( err) ;
539
537
}
540
538
}
541
- ParameterStatus { parameter, value } => {
539
+ Backend :: ParameterStatus { parameter, value } => {
542
540
self . parameters . insert ( parameter, value) ;
543
541
}
544
542
val => return Ok ( val) ,
@@ -552,12 +550,12 @@ impl InnerConnection {
552
550
debug_assert ! ( !self . desynchronized) ;
553
551
loop {
554
552
match try_desync ! ( self , self . stream. read_message_timeout( timeout) ) {
555
- Some ( NoticeResponse { fields } ) => {
553
+ Some ( Backend :: NoticeResponse { fields } ) => {
556
554
if let Ok ( err) = DbError :: new_raw ( fields) {
557
555
self . notice_handler . handle_notice ( err) ;
558
556
}
559
557
}
560
- Some ( ParameterStatus { parameter, value } ) => {
558
+ Some ( Backend :: ParameterStatus { parameter, value } ) => {
561
559
self . parameters . insert ( parameter, value) ;
562
560
}
563
561
val => return Ok ( val) ,
@@ -570,12 +568,12 @@ impl InnerConnection {
570
568
debug_assert ! ( !self . desynchronized) ;
571
569
loop {
572
570
match try_desync ! ( self , self . stream. read_message_nonblocking( ) ) {
573
- Some ( NoticeResponse { fields } ) => {
571
+ Some ( Backend :: NoticeResponse { fields } ) => {
574
572
if let Ok ( err) = DbError :: new_raw ( fields) {
575
573
self . notice_handler . handle_notice ( err) ;
576
574
}
577
575
}
578
- Some ( ParameterStatus { parameter, value } ) => {
576
+ Some ( Backend :: ParameterStatus { parameter, value } ) => {
579
577
self . parameters . insert ( parameter, value) ;
580
578
}
581
579
val => return Ok ( val) ,
@@ -586,7 +584,7 @@ impl InnerConnection {
586
584
fn read_message ( & mut self ) -> std_io:: Result < Backend > {
587
585
loop {
588
586
match try!( self . read_message_with_notification ( ) ) {
589
- NotificationResponse { pid, channel, payload } => {
587
+ Backend :: NotificationResponse { pid, channel, payload } => {
590
588
self . notifications . push_back ( Notification {
591
589
pid : pid,
592
590
channel : channel,
@@ -600,14 +598,14 @@ impl InnerConnection {
600
598
601
599
fn handle_auth ( & mut self , user : UserInfo ) -> result:: Result < ( ) , ConnectError > {
602
600
match try!( self . read_message ( ) ) {
603
- AuthenticationOk => return Ok ( ( ) ) ,
604
- AuthenticationCleartextPassword => {
601
+ Backend :: AuthenticationOk => return Ok ( ( ) ) ,
602
+ Backend :: AuthenticationCleartextPassword => {
605
603
let pass = try!( user. password . ok_or_else ( || {
606
604
ConnectError :: ConnectParams ( "a password was requested but not provided" . into ( ) )
607
605
} ) ) ;
608
- try!( self . write_messages ( & [ PasswordMessage { password : & pass } ] ) ) ;
606
+ try!( self . write_messages ( & [ Frontend :: PasswordMessage { password : & pass } ] ) ) ;
609
607
}
610
- AuthenticationMD5Password { salt } => {
608
+ Backend :: AuthenticationMD5Password { salt } => {
611
609
let pass = try!( user. password . ok_or_else ( || {
612
610
ConnectError :: ConnectParams ( "a password was requested but not provided" . into ( ) )
613
611
} ) ) ;
@@ -619,22 +617,22 @@ impl InnerConnection {
619
617
hasher. input ( output. as_bytes ( ) ) ;
620
618
hasher. input ( & salt) ;
621
619
let output = format ! ( "md5{}" , hasher. result_str( ) ) ;
622
- try!( self . write_messages ( & [ PasswordMessage { password : & output } ] ) ) ;
620
+ try!( self . write_messages ( & [ Frontend :: PasswordMessage { password : & output } ] ) ) ;
623
621
}
624
- AuthenticationKerberosV5 |
625
- AuthenticationSCMCredential |
626
- AuthenticationGSS |
627
- AuthenticationSSPI => {
622
+ Backend :: AuthenticationKerberosV5 |
623
+ Backend :: AuthenticationSCMCredential |
624
+ Backend :: AuthenticationGSS |
625
+ Backend :: AuthenticationSSPI => {
628
626
return Err ( ConnectError :: Io ( std_io:: Error :: new ( std_io:: ErrorKind :: Other ,
629
627
"unsupported authentication" ) ) )
630
628
}
631
- ErrorResponse { fields } => return DbError :: new_connect ( fields) ,
629
+ Backend :: ErrorResponse { fields } => return DbError :: new_connect ( fields) ,
632
630
_ => return Err ( ConnectError :: Io ( bad_response ( ) ) ) ,
633
631
}
634
632
635
633
match try!( self . read_message ( ) ) {
636
- AuthenticationOk => Ok ( ( ) ) ,
637
- ErrorResponse { fields } => DbError :: new_connect ( fields) ,
634
+ Backend :: AuthenticationOk => Ok ( ( ) ) ,
635
+ Backend :: ErrorResponse { fields } => DbError :: new_connect ( fields) ,
638
636
_ => Err ( ConnectError :: Io ( bad_response ( ) ) ) ,
639
637
}
640
638
}
@@ -646,34 +644,34 @@ impl InnerConnection {
646
644
fn raw_prepare ( & mut self , stmt_name : & str , query : & str ) -> Result < ( Vec < Type > , Vec < Column > ) > {
647
645
debug ! ( "preparing query with name `{}`: {}" , stmt_name, query) ;
648
646
649
- try!( self . write_messages ( & [ Parse {
647
+ try!( self . write_messages ( & [ Frontend :: Parse {
650
648
name : stmt_name,
651
649
query : query,
652
650
param_types : & [ ] ,
653
651
} ,
654
- Describe {
652
+ Frontend :: Describe {
655
653
variant : b'S' ,
656
654
name : stmt_name,
657
655
} ,
658
- Sync ] ) ) ;
656
+ Frontend :: Sync ] ) ) ;
659
657
660
658
match try!( self . read_message ( ) ) {
661
- ParseComplete => { }
662
- ErrorResponse { fields } => {
659
+ Backend :: ParseComplete => { }
660
+ Backend :: ErrorResponse { fields } => {
663
661
try!( self . wait_for_ready ( ) ) ;
664
662
return DbError :: new ( fields) ;
665
663
}
666
664
_ => bad_response ! ( self ) ,
667
665
}
668
666
669
667
let raw_param_types = match try!( self . read_message ( ) ) {
670
- ParameterDescription { types } => types,
668
+ Backend :: ParameterDescription { types } => types,
671
669
_ => bad_response ! ( self ) ,
672
670
} ;
673
671
674
672
let raw_columns = match try!( self . read_message ( ) ) {
675
- RowDescription { descriptions } => descriptions,
676
- NoData => vec ! [ ] ,
673
+ Backend :: RowDescription { descriptions } => descriptions,
674
+ Backend :: NoData => vec ! [ ] ,
677
675
_ => bad_response ! ( self ) ,
678
676
} ;
679
677
@@ -696,29 +694,29 @@ impl InnerConnection {
696
694
let more_rows;
697
695
loop {
698
696
match try!( self . read_message ( ) ) {
699
- EmptyQueryResponse | CommandComplete { .. } => {
697
+ Backend :: EmptyQueryResponse | Backend :: CommandComplete { .. } => {
700
698
more_rows = false ;
701
699
break ;
702
700
}
703
- PortalSuspended => {
701
+ Backend :: PortalSuspended => {
704
702
more_rows = true ;
705
703
break ;
706
704
}
707
- DataRow { row } => buf. push_back ( row) ,
708
- ErrorResponse { fields } => {
705
+ Backend :: DataRow { row } => buf. push_back ( row) ,
706
+ Backend :: ErrorResponse { fields } => {
709
707
try!( self . wait_for_ready ( ) ) ;
710
708
return DbError :: new ( fields) ;
711
709
}
712
- CopyInResponse { .. } => {
713
- try!( self . write_messages ( & [ CopyFail {
710
+ Backend :: CopyInResponse { .. } => {
711
+ try!( self . write_messages ( & [ Frontend :: CopyFail {
714
712
message : "COPY queries cannot be directly \
715
713
executed",
716
714
} ,
717
- Sync ] ) ) ;
715
+ Frontend :: Sync ] ) ) ;
718
716
}
719
- CopyOutResponse { .. } => {
717
+ Backend :: CopyOutResponse { .. } => {
720
718
loop {
721
- if let ReadyForQuery { .. } = try!( self . read_message ( ) ) {
719
+ if let Backend :: ReadyForQuery { .. } = try!( self . read_message ( ) ) {
722
720
break ;
723
721
}
724
722
}
@@ -759,22 +757,22 @@ impl InnerConnection {
759
757
}
760
758
}
761
759
762
- try!( self . write_messages ( & [ Bind {
760
+ try!( self . write_messages ( & [ Frontend :: Bind {
763
761
portal : portal_name,
764
762
statement : & stmt_name,
765
763
formats : & [ 1 ] ,
766
764
values : & values,
767
765
result_formats : & [ 1 ] ,
768
766
} ,
769
- Execute {
767
+ Frontend :: Execute {
770
768
portal : portal_name,
771
769
max_rows : row_limit,
772
770
} ,
773
- Sync ] ) ) ;
771
+ Frontend :: Sync ] ) ) ;
774
772
775
773
match try!( self . read_message ( ) ) {
776
- BindComplete => Ok ( ( ) ) ,
777
- ErrorResponse { fields } => {
774
+ Backend :: BindComplete => Ok ( ( ) ) ,
775
+ Backend :: ErrorResponse { fields } => {
778
776
try!( self . wait_for_ready ( ) ) ;
779
777
DbError :: new ( fields)
780
778
}
@@ -824,14 +822,14 @@ impl InnerConnection {
824
822
}
825
823
826
824
fn close_statement ( & mut self , name : & str , type_ : u8 ) -> Result < ( ) > {
827
- try!( self . write_messages ( & [ Close {
825
+ try!( self . write_messages ( & [ Frontend :: Close {
828
826
variant : type_,
829
827
name : name,
830
828
} ,
831
- Sync ] ) ) ;
829
+ Frontend :: Sync ] ) ) ;
832
830
let resp = match try!( self . read_message ( ) ) {
833
- CloseComplete => Ok ( ( ) ) ,
834
- ErrorResponse { fields } => DbError :: new ( fields) ,
831
+ Backend :: CloseComplete => Ok ( ( ) ) ,
832
+ Backend :: ErrorResponse { fields } => DbError :: new ( fields) ,
835
833
_ => bad_response ! ( self ) ,
836
834
} ;
837
835
try!( self . wait_for_ready ( ) ) ;
@@ -940,35 +938,35 @@ impl InnerConnection {
940
938
#[ allow( needless_return) ]
941
939
fn wait_for_ready ( & mut self ) -> Result < ( ) > {
942
940
match try!( self . read_message ( ) ) {
943
- ReadyForQuery { .. } => Ok ( ( ) ) ,
941
+ Backend :: ReadyForQuery { .. } => Ok ( ( ) ) ,
944
942
_ => bad_response ! ( self ) ,
945
943
}
946
944
}
947
945
948
946
fn quick_query ( & mut self , query : & str ) -> Result < Vec < Vec < Option < String > > > > {
949
947
check_desync ! ( self ) ;
950
948
debug ! ( "executing query: {}" , query) ;
951
- try!( self . write_messages ( & [ Query { query : query } ] ) ) ;
949
+ try!( self . write_messages ( & [ Frontend :: Query { query : query } ] ) ) ;
952
950
953
951
let mut result = vec ! [ ] ;
954
952
loop {
955
953
match try!( self . read_message ( ) ) {
956
- ReadyForQuery { .. } => break ,
957
- DataRow { row } => {
954
+ Backend :: ReadyForQuery { .. } => break ,
955
+ Backend :: DataRow { row } => {
958
956
result. push ( row. into_iter ( )
959
957
. map ( |opt| {
960
958
opt. map ( |b| String :: from_utf8_lossy ( & b) . into_owned ( ) )
961
959
} )
962
960
. collect ( ) ) ;
963
961
}
964
- CopyInResponse { .. } => {
965
- try!( self . write_messages ( & [ CopyFail {
962
+ Backend :: CopyInResponse { .. } => {
963
+ try!( self . write_messages ( & [ Frontend :: CopyFail {
966
964
message : "COPY queries cannot be directly \
967
965
executed",
968
966
} ,
969
- Sync ] ) ) ;
967
+ Frontend :: Sync ] ) ) ;
970
968
}
971
- ErrorResponse { fields } => {
969
+ Backend :: ErrorResponse { fields } => {
972
970
try!( self . wait_for_ready ( ) ) ;
973
971
return DbError :: new ( fields) ;
974
972
}
@@ -980,7 +978,7 @@ impl InnerConnection {
980
978
981
979
fn finish_inner ( & mut self ) -> Result < ( ) > {
982
980
check_desync ! ( self ) ;
983
- try!( self . write_messages ( & [ Terminate ] ) ) ;
981
+ try!( self . write_messages ( & [ Frontend :: Terminate ] ) ) ;
984
982
Ok ( ( ) )
985
983
}
986
984
}
0 commit comments