Guard against insert() concatenating statements again (#294) - #573
Merged
Merged
Conversation
The bug reported in #294 is gone. The adapter used to emit INSERT INTO `iobroker`.ts_counter ...;INSERT INTO `iobroker`.ts_number ...; as a single query, which MariaDB rejects: no driver here is configured for multi-statement batches. Reproducing the reported batch against the current builders gives two separate statements on all four dialects, and _insertValuesIntoDB() sends them one at a time over one borrowed connection. What was missing is anything that keeps it that way. Joining the statements back together is the obvious "optimization" for someone looking at a list of queries where one would do, and the only thing standing in the way was a comment. test/testInsertStatements.js now asserts, per dialect, that a batch holding both counter and value rows produces one statement per table, that no statement carries a second one behind a semicolon, and that a 1200 row batch chunks into 500/500/200 without the chunks being glued back together. Verified by restoring the old behaviour in the compiled mysql builder: the three mysql cases fail, and pass again once it is reverted. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug in #294 is already gone. This adds the regression test that was missing, rather than a fix.
What I checked
The issue was filed against 1.16.1 / 2.2.0 and reports a single query carrying two statements:
Reproducing that exact batch — a counter datapoint, which writes to
ts_counterandts_numberin the same flush — against the current builders:And
_insertValuesIntoDB()sends them one at a time through a recursivenext(i), each with its ownclient.execute, over one borrowed connection. The whole path is sound.What was missing
Nothing stops it from coming back. A list of queries where one would do is exactly the kind of thing someone "optimizes" by joining — and the only thing in the way was a comment on
_insertValuesIntoDB().test/testInsertStatements.jsasserts per dialect that:;of a statement is not a match),Verification
12 cases, in the CI unit list. Control run with the old behaviour restored in the compiled mysql builder (
return [query.join('')]):177 unit tests pass overall,
prettier --checkclean.One thing I did not change
The reported batch also shows a duplicate row —
(5, 1676138387812, 53)twice ints_counter. That is inherent to the counter-reset path:main.tspushes both the old and the new state on a reset, so a value that is the "new" state of one reset is the "old" state of the next. It is harmless —ts_counterhas no primary key,getCounterDiffselectsDISTINCT, and equal consecutive values contribute nothing to the summed progression — so I left it alone rather than change counter semantics on the side.#294 can be closed, and #304 with it if it is the same report, as the commenter suggests.
🤖 Generated with Claude Code