1212//!
1313//! fn main() {
1414//! let conn = Connection::connect("postgres://postgres@localhost",
15- //! & SslMode::None).unwrap();
15+ //! SslMode::None).unwrap();
1616//!
1717//! conn.execute("CREATE TABLE foo (id INT PRIMARY KEY, bar VARCHAR)", &[])
1818//! .unwrap();
2727//! stmt.copy_in(&[], &mut reader).unwrap();
2828//! }
2929//! ```
30- #![ doc( html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.1.2 " ) ]
30+ #![ doc( html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.2.0 " ) ]
3131#![ warn( missing_docs) ]
3232extern crate byteorder;
3333extern crate postgres;
@@ -399,7 +399,7 @@ mod test {
399399
400400 #[ test]
401401 fn write_basic ( ) {
402- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
402+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
403403 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar VARCHAR)" , & [ ] ) . unwrap ( ) ;
404404
405405 let stmt = conn. prepare ( "COPY foo (id, bar) FROM STDIN BINARY" ) . unwrap ( ) ;
@@ -423,7 +423,7 @@ mod test {
423423
424424 #[ test]
425425 fn write_many_rows ( ) {
426- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
426+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
427427 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar VARCHAR)" , & [ ] ) . unwrap ( ) ;
428428
429429 let stmt = conn. prepare ( "COPY foo (id, bar) FROM STDIN BINARY" ) . unwrap ( ) ;
@@ -451,7 +451,7 @@ mod test {
451451
452452 #[ test]
453453 fn write_big_rows ( ) {
454- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
454+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
455455 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar BYTEA)" , & [ ] ) . unwrap ( ) ;
456456
457457 let stmt = conn. prepare ( "COPY foo (id, bar) FROM STDIN BINARY" ) . unwrap ( ) ;
@@ -479,15 +479,18 @@ mod test {
479479
480480 #[ test]
481481 fn read_basic ( ) {
482- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
482+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
483483 conn. execute ( "CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, bar INT)" , & [ ] ) . unwrap ( ) ;
484484 conn. execute ( "INSERT INTO foo (bar) VALUES (1), (2), (NULL), (4)" , & [ ] ) . unwrap ( ) ;
485485
486486 let mut out = vec ! [ ] ;
487487
488488 {
489489 let writer = |r : Option < & mut WriteValueReader > , info : & CopyInfo | {
490- out. push ( Option :: < i32 > :: from_sql_nullable ( & Type :: Int4 , r, & info. session_info ( ) ) . unwrap ( ) ) ;
490+ match r {
491+ Some ( r) => out. push ( Option :: < i32 > :: from_sql ( & Type :: Int4 , r, & info. session_info ( ) ) . unwrap ( ) ) ,
492+ None => out. push ( Option :: < i32 > :: from_sql_null ( & Type :: Int4 , & info. session_info ( ) ) . unwrap ( ) ) ,
493+ }
491494 Ok ( ( ) )
492495 } ;
493496
@@ -502,7 +505,7 @@ mod test {
502505
503506 #[ test]
504507 fn read_many_rows ( ) {
505- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
508+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
506509 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT)" , & [ ] ) . unwrap ( ) ;
507510
508511 let mut expected = vec ! [ ] ;
@@ -516,7 +519,7 @@ mod test {
516519
517520 {
518521 let writer = |r : Option < & mut WriteValueReader > , info : & CopyInfo | {
519- out. push ( i32:: from_sql_nullable ( & Type :: Int4 , r, & info. session_info ( ) ) . unwrap ( ) ) ;
522+ out. push ( i32:: from_sql ( & Type :: Int4 , r. unwrap ( ) , & info. session_info ( ) ) . unwrap ( ) ) ;
520523 Ok ( ( ) )
521524 } ;
522525
@@ -531,7 +534,7 @@ mod test {
531534
532535 #[ test]
533536 fn read_big_rows ( ) {
534- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
537+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
535538 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY, bar BYTEA)" , & [ ] ) . unwrap ( ) ;
536539
537540 let mut expected = vec ! [ ] ;
@@ -546,7 +549,7 @@ mod test {
546549
547550 {
548551 let writer = |r : Option < & mut WriteValueReader > , info : & CopyInfo | {
549- out. push ( Vec :: < u8 > :: from_sql_nullable ( & Type :: Bytea , r, & info. session_info ( ) ) . unwrap ( ) ) ;
552+ out. push ( Vec :: < u8 > :: from_sql ( & Type :: Bytea , r. unwrap ( ) , & info. session_info ( ) ) . unwrap ( ) ) ;
550553 Ok ( ( ) )
551554 } ;
552555
@@ -561,7 +564,7 @@ mod test {
561564
562565 #[ test]
563566 fn read_with_oids ( ) {
564- let conn = Connection :: connect ( "postgres://postgres@localhost" , & SslMode :: None ) . unwrap ( ) ;
567+ let conn = Connection :: connect ( "postgres://postgres@localhost" , SslMode :: None ) . unwrap ( ) ;
565568 conn. execute ( "CREATE TEMPORARY TABLE foo (id INT) WITH OIDS" , & [ ] ) . unwrap ( ) ;
566569 conn. execute ( "INSERT INTO foo (id) VALUES (1), (2), (3), (4)" , & [ ] ) . unwrap ( ) ;
567570
@@ -571,9 +574,9 @@ mod test {
571574 {
572575 let writer = |r : Option < & mut WriteValueReader > , info : & CopyInfo | {
573576 if oids. len ( ) > out. len ( ) {
574- out. push ( i32:: from_sql_nullable ( & Type :: Bytea , r, & info. session_info ( ) ) . unwrap ( ) ) ;
577+ out. push ( i32:: from_sql ( & Type :: Bytea , r. unwrap ( ) , & info. session_info ( ) ) . unwrap ( ) ) ;
575578 } else {
576- oids. push ( u32:: from_sql_nullable ( & Type :: Oid , r, & info. session_info ( ) ) . unwrap ( ) ) ;
579+ oids. push ( u32:: from_sql ( & Type :: Oid , r. unwrap ( ) , & info. session_info ( ) ) . unwrap ( ) ) ;
577580 }
578581 Ok ( ( ) )
579582 } ;
0 commit comments