diff --git a/sqlite/read.py b/sqlite/read.py index c5a47ea..d12abc3 100755 --- a/sqlite/read.py +++ b/sqlite/read.py @@ -30,19 +30,17 @@ limit_num=parameter[1] conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db") cursor = conn.cursor() -# Retrieve the last 10 sensor readings -#cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 10") -#cursor.execute("SELECT * FROM data_BME280 ORDER BY timestamp DESC LIMIT 10") -#cursor.execute("SELECT * FROM timestamp_table") +# Retrieve the last sensor readings based on insertion order (ROWID) +# This ensures we get the most recently inserted data, regardless of timestamp value if table_name == "timestamp_table": cursor.execute("SELECT * FROM timestamp_table") else: - query = f"SELECT * FROM {table_name} ORDER BY timestamp DESC LIMIT ?" + # Order by ROWID DESC to get most recently inserted rows first + query = f"SELECT * FROM {table_name} ORDER BY ROWID DESC LIMIT ?" cursor.execute(query, (limit_num,)) - rows = cursor.fetchall() -rows.reverse() # Reverse the order in Python (to get ascending order) +# Keep DESC order - most recently inserted data first # Display the results