yy0931 / sqlite3-editor

https://marketplace.visualstudio.com/items?itemName=yy0931.vscode-sqlite3-editor
GNU General Public License v3.0
838 stars 6 forks source link

Question: sql query editor while executing INSERT creates every time one extra empty row with NULL values? #63

Closed mrlee14 closed 1 month ago

mrlee14 commented 2 months ago

version: v1.0.189

EXAMPLE: INSERT INTO live_data ("ffmpeg_pid", "live_id", "service", "origin", "option", "date", "real_stat") VALUES (?, ?, ?, ?, ?, ?, ?), (12345, "asdadas", "youtube", "scheduler", NULL, 1723072696, 1723072699);

RESULT: [{"ffmpeg_pid":12345,"live_id":"asdadas","service":"youtube","origin":"scheduler","option":null,"date":1723072696,"real_stat":1723072699}]

plus one extra row each time: [{"live_id":null},{"ffmpeg_pid":null},{"service":null},{"origin":null},{"option":null},{"date":null},{"real_stat":null}]

Quetsion: Is this bug or I have some unknown option set????

yy0931 commented 1 month ago

I could not reproduce the issue.

  1. Could you provide the schema of the live_data table?
  2. Additionally, is there a trigger attached to the live_data table? You can check this via the Schema button in the UI.
mrlee14 commented 1 month ago

I could not reproduce the issue.

  1. Could you provide the schema of the live_data table?
  2. Additionally, is there a trigger attached to the live_data table? You can check this via the Schema button in the UI.

NOTE: insert statements i execute by <shift+enter>

Schema: CREATE TABLE live_data ( ffmpeg_pid INTEGER, live_id TEXT, service TEXT, origin TEXT, option TEXT, date INTEGER, real_stat INTEGER )

Triger: None found

Screenshot from 2024-08-17 02-11-07 Screenshot from 2024-08-17 02-10-41

yy0931 commented 1 month ago

Thank you, I now understand your question. The query editor does not support placeholders, so the correct query would be:

INSERT INTO live_data ("ffmpeg_pid", "live_id", "service", "origin", "option", "date", "real_stat")
VALUES (12345, 'asdadas', 'youtube', 'scheduler', NULL, 1723072696, 1723072699);

What was happening in your original query is that in SQLite, a VALUES clause can make multiple rows by separating them with commas, like this:

sqlite> VALUES (1, 2), (3, 4), (5, 6);
column1
---
1|2
3|4
5|6

It seems SQLite treats unbound placeholders as NULL, so (?, ?, ?, ?, ?, ?, ?) is inserting 7 NULLs.