-
Hi, Is it possible to call stored procedure that has output parameters? If yes, how to do it? I have following stored procedure: CREATE PROCEDURE my_proc(
IN name VARCHAR(255),
OUT id INT,
OUT data INT)
BEGIN
...
END; and created query like this: let query = sqlx::query!("CALL my_proc(?, ?, ?);", name, ?, ?); How should I map last 2 output parameters? Didn't find anything like this in the documentation. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Found solution. Stored procedure: CREATE PROCEDURE my_proc(
IN name VARCHAR(255),
OUT id INT,
OUT data INT)
BEGIN
...
SELECT my_tbl.is as id, my_tbl.data as data FROM my_tbl;
END; sqlx: let query = sqlx::query!("CALL my_proc(?, @id, @data);", name);
let res = query.fetch_one(&pool).unrwap();
let id: i32 = res.try_get(0).unwrap();
let data: i32 = res.try_get(1).unwrap(); |
Beta Was this translation helpful? Give feedback.
-
It appears code can be even simpler - there is no need in output parameters at all in this case: CREATE PROCEDURE my_proc(IN name VARCHAR(255))
BEGIN
...
SELECT my_tbl.is as id, my_tbl.data as data FROM my_tbl;
END; sqlx: let query = sqlx::query!("CALL my_proc(?);", name);
let res = query.fetch_one(&pool).unrwap();
let id: i32 = res.try_get(0).unwrap();
let data: i32 = res.try_get(1).unwrap(); |
Beta Was this translation helpful? Give feedback.
Found solution.
Stored procedure:
sqlx: