Skip to content

Enhance executemany() to use multistatement - #798

Open
methane wants to merge 9 commits into
PyMySQL:mainfrom
methane:codex/executemany-multi-fallback
Open

Enhance executemany() to use multistatement#798
methane wants to merge 9 commits into
PyMySQL:mainfrom
methane:codex/executemany-multi-fallback

Conversation

@methane

@methane methane commented Sep 5, 2026

Copy link
Copy Markdown
Member

This pull request introduces a new executemany_fallback option to improve how executemany() handles non-bulk DML statements, allowing for client-side multi-statement batching. It also adds a new more_results() method to the connection API, enhances documentation, and expands test coverage for these features.

Enhancements to executemany() batching and options:

  • Added a new executemany_fallback option to the Connection and Cursor classes, allowing users to control whether non-bulk DML statements in executemany() are executed in a loop (default) or batched into multi-statement queries ("multi"). This includes validation, documentation, and support for configuration via connection parameters. [1] [2] [3] [4] [5] [6] [7] [8]
  • Implemented batching logic in Cursor.executemany() for the "multi" fallback, including statement batching, error handling, and result validation.

API improvements:

  • Added a new more_results() method to the connection object, allowing users to check for additional results after a multi-statement query, and documented its usage. [1] [2] [3]

Documentation updates:

  • Expanded user guide documentation to describe the new executemany_fallback option, its configuration, and the behavior of executemany() with batching. [1] [2]
  • Documented the new more_results() method in the user guide and API reference.

Testing improvements:

  • Added new tests for the executemany_fallback option, including validation of connection and subclass defaults, and extended multi-statement tests to cover the new API. [1] [2] [3] [4] [5] [6]

Regular expression and utility enhancements:

  • Refactored and extended regular expressions and helper functions to support new batching and DML detection logic in cursors.py. [1] [2]

These changes provide more flexible and performant handling of bulk and non-bulk DML operations, better error handling, and improved developer experience through new APIs and documentation.

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.64286% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.72%. Comparing base (e2a908b) to head (4bd318b).
⚠️ Report is 52 commits behind head on main.

Files with missing lines Patch % Lines
src/MySQLdb/cursors.py 94.39% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #798      +/-   ##
==========================================
+ Coverage   88.86%   91.72%   +2.86%     
==========================================
  Files           7        7              
  Lines         548      665     +117     
==========================================
+ Hits          487      610     +123     
+ Misses         61       55       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

1 participant