11# Utility Guide: Oracle
22
3- The Oracle Utility can be used to run SQL queries or stored procedures on the Oracle database.
3+ The Oracle Utility provides an easy way to interact with an Oracle database directly from your Playwright test suite.It can be used to run SQL queries or stored procedures on the Oracle database.
4+
5+ ## When and Why to Use the Oracle Utility
6+
7+ You might need to use this utility in scenarios such as:
8+
9+ - To run SQL queries or stored procedures on the Oracle database.
10+ - Verifying that data is correctly written to or updated in the database after a workflow is completed in your application.
411
512## Table of Contents
613
714- [ Utility Guide: Oracle] ( #utility-guide-oracle )
15+ - [ When and Why to Use the Oracle Utility] ( #when-and-why-to-use-the-oracle-utility )
816 - [ Table of Contents] ( #table-of-contents )
917 - [ Using the Oracle Utility] ( #using-the-oracle-utility )
1018 - [ Required arguments] ( #required-arguments )
19+ - [ Oracle Utility Methods] ( #oracle-utility-methods )
1120 - [ Example usage] ( #example-usage )
1221 - [ Oracle Specific Functions] ( #oracle-specific-functions )
22+ - [ How to Add New Oracle-Specific Functions] ( #how-to-add-new-oracle-specific-functions )
1323 - [ Example Usage] ( #example-usage-1 )
24+ - [ Note] ( #note )
1425
1526## Using the Oracle Utility
1627
@@ -22,29 +33,43 @@ The functions in this class require different arguments.<br>
2233Look at the docstrings for each function to see what arguments are required.<br >
2334The docstrings also specify when arguments are optional, and what the default values are when no argument is provided.
2435
25- ## Example usage
36+ ## Oracle Utility Methods
37+
38+ ** The main methods provided by OracleDB are:**
2639
27- from utils.oracle.oracle import OracleDB
40+ -connect_to_db(self)-Connects to the Oracle database using credentials from environment variables.
41+ -disconnect_from_db(self, conn)-Closes the provided Oracle database connection.
42+ -execute_query(self, query, params=None)-Executes a SQL query with optional parameters and returns the results as a pandas DataFrame.
43+ -execute_stored_procedure(self, procedure_name, params=None)-Executes a named stored procedure with optional parameters.
44+ -exec_bcss_timed_events(self, nhs_number_df)-Runs the bcss_timed_events stored procedure for each NHS number provided in a DataFrame.
45+ -get_subject_id_from_nhs_number(self, nhs_number)-Retrieves the subject_screening_id for a given NHS number.
2846
29- def test_oracle_query() -> None:
47+ For full implementation details, see utils/oracle/oracle.py.
3048
31- query = """select column_a,
32- column_b,
33- column_c
34- from example_table
35- where condition_1 = :condition1
36- and condition_2 = :condition2"""
49+ ## Example usage
3750
38- params = {
51+ ``` python
52+ from utils.oracle.oracle import OracleDB
53+
54+ def test_oracle_query () -> None :
55+ query = """
56+ SELECT column_a,
57+ column_b,
58+ column_c
59+ FROM example_table
60+ WHERE condition_1 = :condition1
61+ AND condition_2 = :condition2
62+ """
63+ params = {
3964 " condition1" : 101 ,
4065 " condition2" : 202 ,
41- }
66+ }
67+ result_df = OracleDB().execute_query(query, params)
68+ print (result_df)
4269
43- result_df = OracleDB().execute_query(query, params)
44-
45- def run_stored_procedure() -> None:
46-
47- OracleDB().execute_stored_procedure("bcss_timed_events")
70+ def run_stored_procedure () -> None :
71+ OracleDB().execute_stored_procedure(" bcss_timed_events" )
72+ ```
4873
4974## Oracle Specific Functions
5075
@@ -53,15 +78,30 @@ These are all stored in one location to make it easier to edit the query at a la
5378
5479Common values are placed in the ` SqlQueryValues ` class to avoid repeating the same values in the queries.
5580
81+ ## How to Add New Oracle-Specific Functions
82+
83+ -Define a new function in utils/oracle/oracle_specific_functions.py.
84+ -Create your SQL query, parameterizing as needed.
85+ -Call OracleDB().execute_query(query, params) to run the query.
86+ -Return the result as a pandas DataFrame.
87+ -Document the function with a clear docstring.
88+
5689## Example Usage
5790
58- from oracle.oracle import OracleDB
91+ ``` python
92+ from utils.oracle.oracle import OracleDB
93+
94+ def example_query () -> pd.DataFrame:
95+
96+ example_df = OracleDB().execute_query(
97+ f """ subject_nhs_number
98+ from ep_subject_episode_t
99+ where se.latest_event_status_id in ( { SqlQueryValues.S10_EVENT_STATUS } , { SqlQueryValues.S19_EVENT_STATUS } ) """ )
59100
60- def example_query() -> pd.DataFrame:
101+ return example_df
102+ ```
61103
62- example_df = OracleDB().execute_query(
63- f"""subject_nhs_number
64- from ep_subject_episode_t
65- where se.latest_event_status_id in ({SqlQueryValues.S10_EVENT_STATUS}, {SqlQueryValues.S19_EVENT_STATUS})""")
104+ ## Note
66105
67- return example_df
106+ The Oracle utility and its helper functions are available under utils/oracle/.
107+ See the source code for more details.
0 commit comments