From c42c6dc1e545d5e5f5c8d5c03ae4862e1b2999de Mon Sep 17 00:00:00 2001 From: Deblintrake09 Date: Wed, 8 Mar 2023 18:01:03 -0300 Subject: [PATCH] feat(#3361): add database query function --- .../wazuh_testing/db_interface/cve_db.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/deps/wazuh_testing/wazuh_testing/db_interface/cve_db.py b/deps/wazuh_testing/wazuh_testing/db_interface/cve_db.py index 750f8c53b8..24786d9909 100644 --- a/deps/wazuh_testing/wazuh_testing/db_interface/cve_db.py +++ b/deps/wazuh_testing/wazuh_testing/db_interface/cve_db.py @@ -228,3 +228,27 @@ def get_nvd_metadata_timestamp(year): return None return result[0] + + +def get_rows_from_table(value, column, table, limit=None): + """ + Args: + value (str): value that user wants to find in query + column (str): Name of the column where the value will be searched for. + table (str): Name of the table where the value will be searched for. + limit (int) - Optional: Maximum amount of results to look for. Default None (No Limit used). + + Returns: + List (str): List with each instance of the value found + """ + + query_string = f"SELECT * FROM {table} WHERE {column} LIKE '{value}'" + + if limit is not None: + query_string = query_string + f"LIMIT {limit}" + + result = get_sqlite_query_result(CVE_DB_PATH, query_string) + if len(result) == 0: + return None + + return result[0]