eccentricOrange/npbc

Log row shown only if both fields present

Closed this issue · 0 comments

The get_logged_data() function does not return some entries. It appears that it's showing only the entries for which an undelivered date and a cost both exist.

npbc/npbc_core.py

Lines 694 to 759 in 49dcf6e

def get_logged_data(
paper_id: int | None = None,
log_id: int | None = None,
month: int | None = None,
year: int | None = None,
timestamp: date_type | None = None
):
"""get logged data
- the user may specify as parameters many as they want
- available parameters: paper_id, log_id, month, year, timestamp
- returns: a list of tuples containing the following fields:
log_id, paper_id, month, year, timestamp, date, cost."""
global DATABASE_PATH
# initialize parameters for the WHERE clause of the SQL query
data = []
parameters = []
values = ()
# check each parameter and add it to the WHERE clause if it is given
if paper_id:
parameters.append("paper_id")
values += (paper_id,)
if log_id:
parameters.append("log_id")
values += (log_id,)
if month:
parameters.append("month")
values += (month,)
if year:
parameters.append("year")
values += (year,)
if timestamp:
parameters.append("timestamp")
values += (timestamp.strftime(r'%d/%m/%Y %I:%M:%S %p'),)
# generate the SQL query
columns_only_query = """
SELECT logs.log_id, logs.paper_id, logs.month, logs.year, logs.timestamp, undelivered_dates_logs.date_not_delivered, cost_logs.cost
FROM logs
INNER JOIN undelivered_dates_logs ON logs.log_id = undelivered_dates_logs.log_id
INNER JOIN cost_logs ON logs.log_id = cost_logs.log_id"""
if parameters:
conditions = ' AND '.join(
f"logs.{parameter} = ?"
for parameter in parameters
)
final_query = f"{columns_only_query} WHERE {conditions};"
else:
final_query = f"{columns_only_query};"
# execute the query
with connect(DATABASE_PATH) as connection:
data = connection.execute(final_query, values).fetchall()
connection.close()
return data