|
| 1 | +# Utility Guide: Oracle |
| 2 | + |
| 3 | +The Oracle Utility can be used to run SQL queries or stored procedures on the Oracle database. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Utility Guide: Oracle](#utility-guide-oracle) |
| 8 | + - [Table of Contents](#table-of-contents) |
| 9 | + - [Using the Oracle Utility](#using-the-oracle-utility) |
| 10 | + - [Required arguments](#required-arguments) |
| 11 | + - [Example usage](#example-usage) |
| 12 | + - [Oracle Specific Functions](#oracle-specific-functions) |
| 13 | + - [Example Usage](#example-usage-1) |
| 14 | + |
| 15 | +## Using the Oracle Utility |
| 16 | + |
| 17 | +To use the Oracle Utility, import the 'OracleDB' class into your test file and then call the OracleDB methods from within your tests, as required. |
| 18 | + |
| 19 | +## Required arguments |
| 20 | + |
| 21 | +The functions in this class require different arguments.<br> |
| 22 | +Look at the docstrings for each function to see what arguments are required.<br> |
| 23 | +The docstrings also specify when arguments are optional, and what the default values are when no argument is provided. |
| 24 | + |
| 25 | +## Example usage |
| 26 | + |
| 27 | + from utils.oracle.oracle import OracleDB |
| 28 | + |
| 29 | + def test_oracle_query() -> None: |
| 30 | + |
| 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""" |
| 37 | + |
| 38 | + params = { |
| 39 | + "condition1": 101, |
| 40 | + "condition2": 202, |
| 41 | + } |
| 42 | + |
| 43 | + result_df = OracleDB().execute_query(query, params) |
| 44 | + |
| 45 | + def run_stored_procedure() -> None: |
| 46 | + |
| 47 | + OracleDB().execute_stored_procedure("bcss_timed_events") |
| 48 | + |
| 49 | +## Oracle Specific Functions |
| 50 | + |
| 51 | +This contains SQL queries that can be used to run tests.<br> |
| 52 | +These are all stored in one location to make it easier to edit the query at a later date and to make it accessible to multiple tests. |
| 53 | + |
| 54 | +Common values are placed in the `SqlQueryValues` class to avoid repeating the same values in the queries. |
| 55 | + |
| 56 | +## Example Usage |
| 57 | + |
| 58 | + from oracle.oracle import OracleDB |
| 59 | + |
| 60 | + def example_query() -> pd.DataFrame: |
| 61 | + |
| 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})""") |
| 66 | + |
| 67 | + return example_df |
0 commit comments