Skip to content

Commit 5632f1b

Browse files
committed
feat!: update SQL API
BREAKING CHANGE!: New versions of prepare and unprepare functions require the session identifier as an additional parameter.
1 parent 413ea70 commit 5632f1b

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
### Fixed (picodata)
2929

3030
### Breaking changes (picodata)
31+
- Add session ID to the argument list of the `sql_prepare_ext`.
32+
- Replace `sql_unprepare` with `sql_unprepare_ext` (contains an additional session ID argument).
3133

3234

3335

tarantool/src/ffi/sql.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ crate::define_dlsym_reloc! {
1919
/// Free memory allocated by this buffer
2020
pub fn ibuf_reinit(ibuf: *mut Ibuf);
2121

22-
pub(crate) fn sql_prepare_ext(sql: *const u8, len: u32, stmt_id: *mut u32) -> c_int;
22+
pub(crate) fn sql_prepare_ext(
23+
sql: *const u8,
24+
len: u32,
25+
stmt_id: *mut u32,
26+
session_id: *mut u64,
27+
) -> c_int;
2328
pub(crate) fn sql_execute_prepared_ext(
2429
stmt_id: u32,
2530
mp_params: *const u8,
2631
vdbe_max_steps: u64,
2732
obuf: *mut Obuf,
2833
) -> c_int;
29-
pub(crate) fn sql_unprepare(stmt_id: u32) -> c_int;
34+
pub(crate) fn sql_unprepare_ext(stmt_id: u32, session_id: u64) -> c_int;
3035
pub(crate) fn sql_stmt_calculate_id(sql_str: *const c_char, len: size_t) -> u32;
3136
pub(crate) fn sql_prepare_and_execute_ext(
3237
sql: *const u8,

tarantool/src/sql.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,45 @@ where
5858
5959
pub fn prepare(query: String) -> crate::Result<Statement> {
6060
let mut stmt_id: u32 = 0;
61+
let mut session_id: u64 = 0;
6162

6263
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+
)
6470
} < 0
6571
{
6672
return Err(TarantoolError::last().into());
6773
}
6874

69-
Ok(Statement { query, id: stmt_id })
75+
Ok(Statement {
76+
query,
77+
stmt_id,
78+
session_id,
79+
})
7080
}
7181

7282
/// Removes SQL prepared statement from the session.
7383
///
7484
/// The statement is removed from the session, and its reference counter in
7585
/// the instance cache is decremented. If the counter reaches zero, the
7686
/// 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());
8090
}
91+
Ok(())
8192
}
8293

8394
/// SQL prepared statement.
8495
#[derive(Default, Debug)]
8596
pub struct Statement {
8697
query: String,
87-
id: u32,
98+
stmt_id: u32,
99+
session_id: u64,
88100
}
89101

90102
impl Statement {
@@ -95,7 +107,12 @@ impl Statement {
95107

96108
/// Returns the statement ID generated from the SQL query text.
97109
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
99116
}
100117

101118
/// Executes prepared statement and returns a wrapper over the raw msgpack bytes.
@@ -114,7 +131,7 @@ impl Statement {
114131
}
115132
let param_ptr = param_data.as_ptr() as *const u8;
116133
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())
118135
};
119136

120137
if execute_result < 0 {

0 commit comments

Comments
 (0)