Skip to content

Commit

Permalink
feat(#3361): add database query function
Browse files Browse the repository at this point in the history
  • Loading branch information
Deblintrake09 committed Apr 24, 2023
1 parent f92dfff commit c42c6dc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions deps/wazuh_testing/wazuh_testing/db_interface/cve_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit c42c6dc

Please sign in to comment.