Skip to content

Fix bugs found by the final pre-release sweep - #47

Merged
doron050 merged 1 commit into
mainfrom
devin/1793725681-fix-final-sweep
Nov 3, 2026
Merged

doron050 merged 1 commit into
mainfrom
devin/1793725681-fix-final-sweep

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the bugs found by the final pre-release sweep of 7e813b7, with an end-to-end test for each.

  • MySQL :copyfrom into JSON columns (regression from Fix bugs found by the pre-release sweep, update docs #46): LOAD DATA ... CHARACTER SET binary can't create JSON values. JSON columns now load into @sqlc_vN with SET col = CONVERT(@sqlc_vN USING utf8mb4).
  • PostgreSQL :copyfrom with booleans: the default binary boolean encoder sent invalid COPY text. Booleans now use PG::TextEncoder::Boolean.
  • PostgreSQL nested transaction rescuing a failed statement: this used to poison the outer transaction. Now only the savepoint is rolled back, PG::InFailedSqlTransaction is raised, and the outer block can rescue it and continue.
  • PostgreSQL array parameters: covers bytea[] (binary/NUL), jsonb[] (Hash elements), [] and leading nil, and preparedStatements: false. These are now sent as array literals (encode_array). Floats are sent as exact text (Float#to_s).
  • :copyfrom conflict clauses: SQLite keeps INSERT OR REPLACE / OR IGNORE / ON CONFLICT ... DO .... MySQL maps INSERT IGNORE and REPLACE to LOAD DATA ... IGNORE|REPLACE INTO TABLE. Clauses COPY / LOAD DATA can't express are generation errors: ON CONFLICT / RETURNING on PostgreSQL, ON DUPLICATE KEY UPDATE on MySQL.
  • Names: snake_case keeps acronyms together (MIN_ID → min_id, not m_i_n_i_d). RuboCop exemptions are emitted only where a name offends, including Naming/VariableNumber for repeated parameters (id_2).
  • mysql2 batches prepare a statement per row, because reusing one statement broke binary/unsigned values.
  • Dead connections: pg resets a CONNECTION_BAD connection on checkout. mysql2 discards a closed connection from the pool.
  • Nested transaction(isolation:) / transaction(mode:) now raise ArgumentError instead of being silently ignored.

Drivers get the parsed verb/tail through copy_from_lines(..., query_name:, sources:, verb:, tail:) and a prepares_batch_rows? hook.

New example tables back the e2e tests: batch_types (pg), copy_types (mysql), tags (sqlite). README documents the new behaviour and limitations.

Behaviour changes (release notes)

  • A nested transaction with isolation: / mode: raises ArgumentError.
  • A :copyfrom query with ON CONFLICT / RETURNING (PostgreSQL) or ON DUPLICATE KEY UPDATE (MySQL) is rejected at generation time.

Verified locally

  • rake test: Ruby 3.1–3.4.
  • RuboCop and Steep: clean. Steep expectations were refreshed; only line shifts and new PG/Mysql2 constant references changed.
  • sqlc diff: clean through both the newly built dist/plugin.wasm and exe/plugin.rb.
  • E2E on Ruby 3.2–3.4, against PostgreSQL 16, MySQL 8.3 and SQLite.
  • Randomized round-trip tests (insert/select, batch, copyfrom) on Ruby 3.1–3.4. They include binary bytea[], jsonb[], Float::MAX and 5e-324.

Checklist

  • examples/ is regenerated (rake sqlc_generate_process) and committed
  • Tests added or updated (rake test, and rake end2end_* when the generated code changes)
  • The generated code stays RuboCop-clean (rake rubocop) and Steep-clean (rake steep)
  • Labelled (bug, enhancement, documentation, or breaking) so the release notes are grouped correctly

- MySQL :copyfrom into JSON columns (LOAD DATA CHARACTER SET binary): convert JSON columns via user variables
- PostgreSQL :copyfrom with booleans: text boolean encoder
- PostgreSQL nested transaction rescuing a failed statement: roll back only the savepoint
- PostgreSQL array parameters (bytea[], jsonb[], [] / leading nil, preparedStatements: false) as array literals; floats as exact text
- :copyfrom keeps INSERT OR REPLACE / OR IGNORE / ON CONFLICT (SQLite), INSERT IGNORE / REPLACE (MySQL); rejects clauses COPY / LOAD DATA cannot express
- acronym-aware snake_case (MIN_ID -> min_id); RuboCop exemptions only where needed (Naming/VariableNumber)
- mysql2 batches prepare per row; nested isolation:/mode: raise; dead connections reset (pg) / discarded from the pool (mysql2)
- E2E tests for every case

Co-Authored-By: Doron Eli Rachman <doron050@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the bug Something isn't working label Nov 3, 2026
@doron050
doron050 merged commit af5e998 into main Nov 3, 2026
14 checks passed
@doron050
doron050 deleted the devin/1793725681-fix-final-sweep branch November 12, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant