Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msgid is stored as text type #2247

Open
kashikoibumi opened this issue May 29, 2024 · 5 comments
Open

msgid is stored as text type #2247

kashikoibumi opened this issue May 29, 2024 · 5 comments

Comments

@kashikoibumi
Copy link

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
@PeterSurda
Copy link
Member

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

@kashikoibumi
Copy link
Author

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

@PeterSurda
Copy link
Member

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.

@kashikoibumi
Copy link
Author

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
Copy link
Author

I have implemented a quick workaround: #2248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants