@@ -11,6 +11,7 @@ static BYTEAOID: Oid = 17;
1111static INT8OID : Oid = 20 ;
1212static INT2OID : Oid = 21 ;
1313static INT4OID : Oid = 23 ;
14+ static TEXTOID : Oid = 25 ;
1415static FLOAT4OID : Oid = 700 ;
1516static FLOAT8OID : Oid = 701 ;
1617static VARCHAROID : Oid = 1043 ;
@@ -34,9 +35,10 @@ pub fn result_format(ty: Oid) -> Format {
3435}
3536
3637macro_rules! check_oid(
37- ( $expected: ident, $actual: ident) => (
38- if $expected != $actual {
39- fail!( "Expected Oid %? but got Oid %?" , $expected, $actual) ;
38+ ( $( $expected: ident) |+, $actual: ident) => (
39+ match $actual {
40+ $( $expected) |+ => ( ) ,
41+ actual => fail!( "Invalid Oid %?" , actual)
4042 }
4143 )
4244)
@@ -95,7 +97,7 @@ from_option_impl!(f64)
9597
9698impl FromSql for Option < ~str > {
9799 fn from_sql ( ty : Oid , raw : & Option < ~[ u8 ] > ) -> Option < ~str > {
98- check_oid ! ( VARCHAROID , ty)
100+ check_oid ! ( VARCHAROID | TEXTOID , ty)
99101 do raw. chain_ref |buf| {
100102 Some ( str:: from_bytes ( buf. as_slice ( ) ) )
101103 }
@@ -116,10 +118,10 @@ pub trait ToSql {
116118}
117119
118120macro_rules! to_option_impl(
119- ( $oid: ident, $t: ty) => (
121+ ( $( $ oid: ident) |+ , $t: ty) => (
120122 impl ToSql for Option <$t> {
121123 fn to_sql( & self , ty: Oid ) -> ( Format , Option <~[ u8 ] >) {
122- check_oid!( $oid, ty)
124+ check_oid!( $( $ oid) |+ , ty)
123125
124126 match * self {
125127 None => ( Text , None ) ,
@@ -131,10 +133,10 @@ macro_rules! to_option_impl(
131133)
132134
133135macro_rules! to_conversions_impl(
134- ( $oid: ident, $t: ty, $f: ident) => (
136+ ( $( $ oid: ident) |+ , $t: ty, $f: ident) => (
135137 impl ToSql for $t {
136138 fn to_sql( & self , ty: Oid ) -> ( Format , Option <~[ u8 ] >) {
137- check_oid!( $oid, ty)
139+ check_oid!( $( $ oid) |+ , ty)
138140
139141 let mut writer = MemWriter :: new( ) ;
140142 writer. $f( * self ) ;
@@ -165,16 +167,16 @@ to_option_impl!(FLOAT8OID, f64)
165167
166168impl < ' self > ToSql for & ' self str {
167169 fn to_sql ( & self , ty : Oid ) -> ( Format , Option < ~[ u8 ] > ) {
168- check_oid ! ( VARCHAROID , ty)
170+ check_oid ! ( VARCHAROID | TEXTOID , ty)
169171 ( Text , Some ( self . as_bytes ( ) . to_owned ( ) ) )
170172 }
171173}
172174
173- to_option_impl ! ( VARCHAROID , ~str )
175+ to_option_impl ! ( VARCHAROID | TEXTOID , ~str )
174176
175177impl < ' self > ToSql for Option < & ' self str > {
176178 fn to_sql ( & self , ty : Oid ) -> ( Format , Option < ~[ u8 ] > ) {
177- check_oid ! ( VARCHAROID , ty)
179+ check_oid ! ( VARCHAROID | TEXTOID , ty)
178180 match * self {
179181 None => ( Text , None ) ,
180182 Some ( val) => val. to_sql ( ty)
0 commit comments