Skip to content

Conversation

@fisharebest
Copy link

Q A
Type bug
Fixed issues #7271

Summary

In SQLite, integer primary keys are implicitly autoincrement columns, and dbal contains logic for this.

However, this logic fails when a composite primary key contains an integer and also other non-integer columns. The integer column part of the composite PK becomes wrongly flagged as autoincrement.

(A consequence of this is that when calling getAlterSchemaSQL(), the non-integer columns are removed from the primary key. For example, a PK consisting of INTEGER, VARCHAR gets changed to just INTEGER. This causes loss of data as the rows saved to the temporary table cannot be re-inserted.)

This happens because the code filters the existing PK columns by "is integer" instead of filtering the column under consideration by "is integer".

Moving this "is integer" check fixes the issue.

A new test case was added containing three assertions. Two of these assert that the existing functionality isn't broken. The third would fail under the old code, but passes under the new code.


NOTE: I have submitted this PR against the 4.5.x branch (as requested by @morozov).
However, the code is the same in the 4.4.x branch, and could be backported if desired.

@fisharebest fisharebest changed the title Fix 7271 - SQLite - composite keys wrongly introspected as autoincrement Fix #7271 - SQLite - composite keys wrongly introspected as autoincrement Jan 12, 2026
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks fine to me. I don't think there's a BC break other than "it used to work the other way previously". Maintainers, please speak up if you disagree.

);
}

public function testIntrospectPrimaryKeyAutoincrement(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests seems to combine three independent tests. Would it make sense to separate them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three assertions are all testing the same logic, so it seemed clearer (to me) to have them in a single test.

I can split them up if desired, but I prefer them together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current approach, if the first assertion fails, the other two will be skipped, however they shouldn't.

@morozov morozov requested review from derrabus and greg0ire January 13, 2026 22:27
@greg0ire
Copy link
Member

From #7271 (comment) (emphasis mine)

You could try making this change and providing a BC impact analysis

@morozov
Copy link
Member

morozov commented Jan 15, 2026

From #7271 (comment) (emphasis mine)

You could try making this change and providing a BC impact analysis

When I requested this analysis, I assumed that the complete fix would somehow resemble #6862, which is a BC break. My own assessment of the actual changes in this PR is:

  1. Not ignoring non-integer columns in the PK definition is correct: any column can be part of the PK, and there's no promise that the DBAL will ignore them.
  2. Setting auto-increment to true only if the column is integer is also correct (this behavior doesn't change, it's just the condition above being moved lower).

I don't see an obvious BC break here, it's just a different more correct behavior, which is more appropriate for a minor release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants