PyBitmessage icon indicating copy to clipboard operation
PyBitmessage copied to clipboard

msgid is stored as text type

Open kashikoibumi opened this issue 1 year ago • 5 comments

msgid is stored as text type. It should be binary blob.

$ sqlite3 messages.dat
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> SELECT TYPEOF(msgid) FROM inbox LIMIT 1;
text

hash in inventory is OK.

sqlite> SELECT TYPEOF(hash) FROM inventory LIMIT 1;
blob

kashikoibumi avatar May 29 '24 18:05 kashikoibumi

This is true, but there are potential problems with upgrades. That's why the sql thread should be refactored first and added tests. These are the PRs that tried that but they are too big and need cleaning up: #1794 #1999 #2150

PeterSurda avatar May 29 '24 23:05 PeterSurda

The type of values whose declared type is blob:

  • inbox.msgid : text
  • inbox.sighash : text
  • inventory.hash : blob
  • inventory.payload : blob
  • inventory.tag : blob
  • objectprocessorqueue.data : (empty)
  • pubkeys.transmitdata : text
  • sent.msgid : text
  • sent.toripe : text
  • sent.ackdata : text
  • settings.key : text
  • settings.value : text, integer

kashikoibumi avatar May 30 '24 00:05 kashikoibumi

It actually isn't consistent across versions, there may be older databases which are different. That's why we need tests for this, even more for the data type change.

PeterSurda avatar May 30 '24 02:05 PeterSurda

How about this:

  • Change all code at once to store all blob data as blob by using sqlite3.Binary(). Then,
  • Search any blob data:
    • First, try SELECT by blob keys using sqlite3.Binary(key).
    • When there is no match found, as a fallback, try SELECT by text key using CAST(? AS TEXT) in SQLite sintax.

I think this should be compatible to any past versions and future updates, including migrations to Python3.

kashikoibumi avatar May 30 '24 03:05 kashikoibumi

I have implemented a quick workaround: #2248

kashikoibumi avatar May 30 '24 09:05 kashikoibumi