-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the 'Call stored procedure' keyword:
- Support pymysql, oracledb/cx_Oracle, psycopg2/3, pymssql - Return both param values and result sets (even multiple sets for supported DB) - Special handling for OUT params of cursor type - For not supported DB's there is a warning message and more cautious attempt to get results + Tests
- Loading branch information
Showing
6 changed files
with
366 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
DROP PROCEDURE IF EXISTS no_params; | ||
CREATE PROCEDURE no_params | ||
AS | ||
BEGIN | ||
-- Do nothing | ||
RETURN; | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_second_name; | ||
CREATE PROCEDURE | ||
get_second_name | ||
@person_first_name VARCHAR(20) | ||
AS | ||
BEGIN | ||
SELECT LAST_NAME | ||
FROM person | ||
WHERE FIRST_NAME = @person_first_name; | ||
RETURN; | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_all_second_names; | ||
CREATE PROCEDURE get_all_second_names | ||
AS | ||
BEGIN | ||
SELECT LAST_NAME FROM person; | ||
RETURN; | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_all_first_and_second_names; | ||
CREATE PROCEDURE get_all_first_and_second_names | ||
AS | ||
BEGIN | ||
SELECT FIRST_NAME FROM person; | ||
SELECT LAST_NAME FROM person; | ||
RETURN; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
DROP PROCEDURE IF EXISTS no_params; | ||
CREATE PROCEDURE | ||
no_params() | ||
BEGIN | ||
-- Do nothing | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_second_name; | ||
CREATE PROCEDURE | ||
get_second_name (IN person_first_name VARCHAR(20), | ||
OUT person_second_name VARCHAR(20)) | ||
BEGIN | ||
SELECT LAST_NAME | ||
INTO person_second_name | ||
FROM person | ||
WHERE FIRST_NAME = person_first_name; | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_all_second_names; | ||
CREATE PROCEDURE get_all_second_names() | ||
BEGIN | ||
SELECT LAST_NAME FROM person; | ||
END; | ||
|
||
DROP PROCEDURE IF EXISTS get_all_first_and_second_names; | ||
CREATE PROCEDURE get_all_first_and_second_names() | ||
BEGIN | ||
SELECT FIRST_NAME FROM person; | ||
SELECT LAST_NAME FROM person; | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
DROP ROUTINE IF EXISTS no_params; | ||
CREATE FUNCTION no_params() | ||
RETURNS VOID | ||
BEGIN ATOMIC | ||
-- Do nothing | ||
END; | ||
|
||
DROP ROUTINE IF EXISTS get_second_name; | ||
CREATE FUNCTION | ||
get_second_name (IN person_first_name VARCHAR(20), | ||
OUT person_second_name VARCHAR(20)) | ||
LANGUAGE plpgsql | ||
AS | ||
' | ||
BEGIN | ||
SELECT LAST_NAME INTO person_second_name | ||
FROM person | ||
WHERE FIRST_NAME = person_first_name; | ||
END | ||
'; | ||
|
||
DROP ROUTINE IF EXISTS get_all_second_names; | ||
CREATE FUNCTION | ||
get_all_second_names() | ||
RETURNS TABLE (second_names VARCHAR(20)) | ||
LANGUAGE plpgsql | ||
AS | ||
' | ||
BEGIN | ||
RETURN QUERY SELECT LAST_NAME FROM person; | ||
END | ||
'; | ||
|
||
|
||
DROP ROUTINE IF EXISTS get_all_first_and_second_names; | ||
CREATE FUNCTION | ||
get_all_first_and_second_names(result1 refcursor, result2 refcursor) | ||
RETURNS SETOF refcursor | ||
LANGUAGE plpgsql | ||
AS | ||
' | ||
BEGIN | ||
OPEN result1 FOR SELECT FIRST_NAME FROM person; | ||
RETURN NEXT result1; | ||
OPEN result2 FOR SELECT LAST_NAME FROM person; | ||
RETURN NEXT result2; | ||
END | ||
'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
CREATE OR REPLACE PROCEDURE | ||
no_params AS | ||
BEGIN | ||
DBMS_OUTPUT.PUT_LINE('Hello, World!'); | ||
END; | ||
|
||
CREATE OR REPLACE PROCEDURE | ||
get_second_name (person_first_name IN VARCHAR, person_second_name OUT VARCHAR) AS | ||
BEGIN | ||
SELECT last_name | ||
INTO person_second_name | ||
FROM person | ||
WHERE first_name = person_first_name; | ||
END; | ||
|
||
CREATE OR REPLACE PROCEDURE | ||
get_all_second_names (second_names_cursor OUT SYS_REFCURSOR) AS | ||
BEGIN | ||
OPEN second_names_cursor for | ||
SELECT LAST_NAME FROM person; | ||
END; | ||
|
||
-- parsing the SQL file fails because of the semicolon before the opening of the second cursor | ||
-- , but it's needed | ||
CREATE OR REPLACE PROCEDURE | ||
get_all_first_and_second_names (first_names_cursor OUT SYS_REFCURSOR, second_names_cursor OUT SYS_REFCURSOR) AS | ||
BEGIN | ||
OPEN first_names_cursor for | ||
SELECT FIRST_NAME FROM person; | ||
OPEN second_names_cursor for | ||
SELECT LAST_NAME FROM person; | ||
END; |
Oops, something went wrong.