Skip to content

Match PDO MySQL lastInsertId() behavior in edge cases #474

Description

@JanJakes

Problem

WP_MySQL_On_SQLite::lastInsertId() snapshots SQLite's last row ID, but SQLite and PDO MySQL differ in several cases:

  • A multi-row insert returns SQLite's last generated ID; PDO MySQL returns the first.
  • An insert into a table without AUTO_INCREMENT can expose a SQLite row ID; PDO MySQL returns "0".
  • A fully ignored insert can expose a stale or advanced SQLite ID; PDO MySQL returns "0".

The PDO coverage work in #471 handles initialization, operation resets, and isolation from internal SQLite writes, but not these differences.

Expected behavior

Derive the ID from the user-issued MySQL INSERT or REPLACE operation rather than directly exposing SQLite's connection-level last row ID.

Add coverage for single-row, multi-row, explicit-ID, non-auto-increment, ignored, replace, and duplicate-key-update cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions