@@ -58,33 +58,45 @@ where
58
58
59
59
pub fn prepare ( query : String ) -> crate :: Result < Statement > {
60
60
let mut stmt_id: u32 = 0 ;
61
+ let mut session_id: u64 = 0 ;
61
62
62
63
if unsafe {
63
- ffi:: sql:: sql_prepare_ext ( query. as_ptr ( ) , query. len ( ) as u32 , & mut stmt_id as * mut u32 )
64
+ ffi:: sql:: sql_prepare_ext (
65
+ query. as_ptr ( ) ,
66
+ query. len ( ) as u32 ,
67
+ & mut stmt_id as * mut u32 ,
68
+ & mut session_id as * mut u64 ,
69
+ )
64
70
} < 0
65
71
{
66
72
return Err ( TarantoolError :: last ( ) . into ( ) ) ;
67
73
}
68
74
69
- Ok ( Statement { query, id : stmt_id } )
75
+ Ok ( Statement {
76
+ query,
77
+ stmt_id,
78
+ session_id,
79
+ } )
70
80
}
71
81
72
82
/// Removes SQL prepared statement from the session.
73
83
///
74
84
/// The statement is removed from the session, and its reference counter in
75
85
/// the instance cache is decremented. If the counter reaches zero, the
76
86
/// statement is removed from the instance cache.
77
- pub fn unprepare ( stmt : Statement ) {
78
- unsafe {
79
- ffi :: sql :: sql_unprepare ( stmt . id ) ;
87
+ pub fn unprepare ( stmt : Statement ) -> crate :: Result < ( ) > {
88
+ if unsafe { ffi :: sql :: sql_unprepare_ext ( stmt . id ( ) , stmt . session_id ( ) ) } < 0 {
89
+ return Err ( TarantoolError :: last ( ) . into ( ) ) ;
80
90
}
91
+ Ok ( ( ) )
81
92
}
82
93
83
94
/// SQL prepared statement.
84
95
#[ derive( Default , Debug ) ]
85
96
pub struct Statement {
86
97
query : String ,
87
- id : u32 ,
98
+ stmt_id : u32 ,
99
+ session_id : u64 ,
88
100
}
89
101
90
102
impl Statement {
@@ -95,7 +107,12 @@ impl Statement {
95
107
96
108
/// Returns the statement ID generated from the SQL query text.
97
109
pub fn id ( & self ) -> u32 {
98
- self . id
110
+ self . stmt_id
111
+ }
112
+
113
+ /// Returns the session ID.
114
+ pub fn session_id ( & self ) -> u64 {
115
+ self . session_id
99
116
}
100
117
101
118
/// Executes prepared statement and returns a wrapper over the raw msgpack bytes.
@@ -114,7 +131,7 @@ impl Statement {
114
131
}
115
132
let param_ptr = param_data. as_ptr ( ) as * const u8 ;
116
133
let execute_result = unsafe {
117
- ffi:: sql:: sql_execute_prepared_ext ( self . id , param_ptr, vdbe_max_steps, buf. obuf ( ) )
134
+ ffi:: sql:: sql_execute_prepared_ext ( self . id ( ) , param_ptr, vdbe_max_steps, buf. obuf ( ) )
118
135
} ;
119
136
120
137
if execute_result < 0 {
0 commit comments