@@ -859,6 +859,18 @@ pub enum Statement {
859859 purge : bool ,
860860 } ,
861861 /// DECLARE - Declaring Cursor Variables
862+ /// FETCH - retrieve rows from a query using a cursor
863+ ///
864+ /// Note: this is a PostgreSQL-specific statement,
865+ /// but may also compatible with other SQL.
866+ Fetch {
867+ /// Cursor name
868+ name : Ident ,
869+ direction : FetchDirection ,
870+ /// Optional, It's possible to fetch rows form cursor to the table
871+ into : Option < ObjectName > ,
872+ } ,
873+ /// DISCARD [ ALL | PLANS | SEQUENCES | TEMPORARY | TEMP ]
862874 ///
863875 /// Note: this is a PostgreSQL-specific statement,
864876 /// but may also compatible with other SQL.
@@ -1147,6 +1159,21 @@ impl fmt::Display for Statement {
11471159
11481160 write ! ( f, "FOR {}" , query)
11491161 }
1162+ Statement :: Fetch {
1163+ name,
1164+ direction,
1165+ into,
1166+ } => {
1167+ write ! ( f, "FETCH {} " , direction) ?;
1168+
1169+ write ! ( f, "IN {}" , name) ?;
1170+
1171+ if let Some ( into) = into {
1172+ write ! ( f, " INTO {}" , into) ?;
1173+ }
1174+
1175+ Ok ( ( ) )
1176+ }
11501177 Statement :: Directory {
11511178 overwrite,
11521179 local,
@@ -1940,6 +1967,69 @@ impl fmt::Display for Privileges {
19401967 }
19411968}
19421969
1970+ /// Specific direction for FETCH statement
1971+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1972+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1973+ pub enum FetchDirection {
1974+ Count { limit : Value } ,
1975+ Next ,
1976+ Prior ,
1977+ First ,
1978+ Last ,
1979+ Absolute { limit : Value } ,
1980+ Relative { limit : Value } ,
1981+ All ,
1982+ // FORWARD
1983+ // FORWARD count
1984+ Forward { limit : Option < Value > } ,
1985+ ForwardAll ,
1986+ // BACKWARD
1987+ // BACKWARD count
1988+ Backward { limit : Option < Value > } ,
1989+ BackwardAll ,
1990+ }
1991+
1992+ impl fmt:: Display for FetchDirection {
1993+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1994+ match self {
1995+ FetchDirection :: Count { limit } => f. write_str ( & limit. to_string ( ) ) ?,
1996+ FetchDirection :: Next => f. write_str ( "NEXT" ) ?,
1997+ FetchDirection :: Prior => f. write_str ( "PRIOR" ) ?,
1998+ FetchDirection :: First => f. write_str ( "FIRST" ) ?,
1999+ FetchDirection :: Last => f. write_str ( "LAST" ) ?,
2000+ FetchDirection :: Absolute { limit } => {
2001+ f. write_str ( "ABSOLUTE " ) ?;
2002+ f. write_str ( & limit. to_string ( ) ) ?;
2003+ }
2004+ FetchDirection :: Relative { limit } => {
2005+ f. write_str ( "RELATIVE " ) ?;
2006+ f. write_str ( & limit. to_string ( ) ) ?;
2007+ }
2008+ FetchDirection :: All => f. write_str ( "ALL" ) ?,
2009+ FetchDirection :: Forward { limit } => {
2010+ f. write_str ( "FORWARD" ) ?;
2011+
2012+ if let Some ( l) = limit {
2013+ f. write_str ( " " ) ?;
2014+ f. write_str ( & l. to_string ( ) ) ?;
2015+ }
2016+ }
2017+ FetchDirection :: ForwardAll => f. write_str ( "FORWARD ALL" ) ?,
2018+ FetchDirection :: Backward { limit } => {
2019+ f. write_str ( "BACKWARD" ) ?;
2020+
2021+ if let Some ( l) = limit {
2022+ f. write_str ( " " ) ?;
2023+ f. write_str ( & l. to_string ( ) ) ?;
2024+ }
2025+ }
2026+ FetchDirection :: BackwardAll => f. write_str ( "BACKWARD ALL" ) ?,
2027+ } ;
2028+
2029+ Ok ( ( ) )
2030+ }
2031+ }
2032+
19432033/// A privilege on a database object (table, sequence, etc.).
19442034#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
19452035#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
0 commit comments