From c6cbd3313d9e12f73a63c4eaf63435e53dfaa23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herman=20=C3=98ie=20Kolden?= Date: Sat, 29 Jun 2024 08:07:29 +0200 Subject: [PATCH] db: store ints as ints, not floats DatabaseULog.write_ulog complained about wrong value types during struct packing. --- pyulog/db.py | 2 +- pyulog/sql/pyulog.4.sql | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pyulog/sql/pyulog.4.sql diff --git a/pyulog/db.py b/pyulog/db.py index d28acb3..6d14905 100644 --- a/pyulog/db.py +++ b/pyulog/db.py @@ -49,7 +49,7 @@ class DatabaseULog(ULog): contsructor will throw an exception. See the documentation of "ulog_migratedb" for more information. ''' - SCHEMA_VERSION = 3 + SCHEMA_VERSION = 4 @staticmethod def get_db_handle(db_path): diff --git a/pyulog/sql/pyulog.4.sql b/pyulog/sql/pyulog.4.sql new file mode 100644 index 0000000..5866070 --- /dev/null +++ b/pyulog/sql/pyulog.4.sql @@ -0,0 +1,37 @@ +BEGIN; +PRAGMA foreign_keys=off; + +-- Change REAL timestamps to INT. SQLITE only supports INT64, but ULog -- changed from REAL +-- timestamps are UINT64. We accept losing 1 bit at the top end, since 2^63 +-- microseconds = 400,000 years. which should be enough. + +ALTER TABLE ULog RENAME COLUMN StartTimestamp TO StartTimestamp_old; +ALTER TABLE ULog ADD COLUMN StartTimestamp INT; +UPDATE ULog SET StartTimestamp = CAST(StartTimestamp_old AS INT); + +ALTER TABLE ULog RENAME COLUMN LastTimestamp TO LastTimestamp_old; +ALTER TABLE ULog ADD COLUMN LastTimestamp INT; +UPDATE ULog SET LastTimestamp = CAST(LastTimestamp_old AS INT); + +ALTER TABLE ULogMessageDropout RENAME COLUMN Timestamp TO Timestamp_old; +ALTER TABLE ULogMessageDropout ADD COLUMN Timestamp INT; +UPDATE ULogMessageDropout SET Timestamp = CAST(Timestamp_old AS INT); + +ALTER TABLE ULogMessageDropout RENAME COLUMN Duration TO Duration_old; +ALTER TABLE ULogMessageDropout ADD COLUMN Duration INT; +UPDATE ULogMessageDropout SET Duration = CAST(Duration_old AS INT); + +ALTER TABLE ULogMessageLogging RENAME COLUMN Timestamp TO Timestamp_old; +ALTER TABLE ULogMessageLogging ADD COLUMN Timestamp INT; +UPDATE ULogMessageLogging SET Timestamp = CAST(Timestamp_old AS INT); + +ALTER TABLE ULogMessageLoggingTagged RENAME COLUMN Timestamp TO Timestamp_old; +ALTER TABLE ULogMessageLoggingTagged ADD COLUMN Timestamp INT; +UPDATE ULogMessageLoggingTagged SET Timestamp = CAST(Timestamp_old AS INT); + +ALTER TABLE ULogChangedParameter RENAME COLUMN Timestamp TO Timestamp_old; +ALTER TABLE ULogChangedParameter ADD COLUMN Timestamp INT; +UPDATE ULogChangedParameter SET Timestamp = CAST(Timestamp_old AS INT); + +PRAGMA foreign_keys=on; +COMMIT;