sqlitebrowser / sqlitebrowser/sqlitebrowser

[Bug]: Database cell type not updated properly when copy/pasting blob data

Open
#3,307 15 comments 0 reactions 1 assignee View on GitHub

@mgrojo is already working on this.

Since Aug 4, 2023.

bug
Dominant language
C++
Stars
24.6k
Forks
2.4k
Avg merge
3d 49m
Merged PRs (30d)
3

Description

What did you do?

When copying BLOB data into cells in the database which contain TEXT data, the BLOB will be copied into the cell and DB4S will display the type as BLOB, but when the database is read through the sqlite3 command line or python library it will be read as an empty TEXT field.

Steps to Reproduce:
  1. Create a new database and initialize as follows
CREATE TABLE "test_table" ( "field" BLOB );
INSERT INTO "test_table" ("field") VALUES (X'DEADBEEF');
INSERT INTO "test_table" ("field") VALUES ("String");
  1. Open the database in DB4S and go to the "Browse Data" tab
  2. Use ctrl+c and ctrl+v to copy the BLOB value over the TEXT value
  3. Write the changes to the database
Verifying through sqlite3 cli
  1. Open the database sqlite3 /path/to/database.db
  2. Dump raw data with .dump
-- Output abridged 
INSERT INTO test_table VALUES(X'deadbeef');
INSERT INTO test_table VALUES('ޭ��');  -- BLOB field is output as corrupt TEXT
Verifying through python's sqlite3 module

Using the following script

import sqlite3

conn = sqlite3.connect('/path/to/database.db')
cursor = sqlite3.Cursor(conn)
cursor.execute("SELECT field FROM test_table")
for row in cursor.fetchall():
    print(type(row[0]), row[0])

Depending on the exact binary data in the BLOB field the script will either crash with sqlite3.OperationalError: Could not decode to UTF-8 column 'field' with text'����' or will output the bytes field directly interpreted as UTF-8.

What did you expect to see?

I expected the BLOB value to be exactly copied over the text cell so that the two output lines of the .dump command would be identical.

What did you see instead?

The BLOB data was saved as corrupt text. Depending on how this data is retrieved, it either comes out as garbled text or crashes the program due to invalid UTF-8 encoding.

DB4S Version

3.12.2

What OS are you seeing the problem on?

Linux

OS version

Arch Linux

Relevant log output

No response

Prevention against duplicate issues
  • I have searched for similar issues

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.