Skip to content

Commit

Permalink
db: store ints as ints, not floats
Browse files Browse the repository at this point in the history
DatabaseULog.write_ulog complained about wrong value types during struct
packing.
  • Loading branch information
hermankolden committed Jun 29, 2024
1 parent b2a398b commit c6cbd33
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyulog/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
37 changes: 37 additions & 0 deletions pyulog/sql/pyulog.4.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c6cbd33

Please sign in to comment.