Repository navigation
[#17689] - read back the generated id when the identity is 0 on adapters without sequences - #17690
Conversation
…n adapters without sequences Since phalcon#16920, doLowInsert() reuses any non-empty identity value instead of calling lastInsertId(), to avoid the PostgreSQL currval() error from phalcon#16436. On MySQL, 0 is not an explicit id: it is replaced by the next auto-increment value, so a model whose identity defaults to 0 kept 0 after the insert. The value on the model is still reused on adapters with sequences and for any explicit non-zero id (same value and type as before); 0 now goes through lastInsertId() on adapters without sequences. Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8b69110 to
2e60190
Compare
|
@nadorator Thank you for this PR. I passed this through the QA tool I have and the findings are below which I verified:
I think you can run
The ext folder has not been generated so that will cause an issue when sending this to v5. Don't worry about that, I will regenerate it and push. Posting this here as an FYI. Final question, are you planning on issuing a mirror PR for v6 or should I do it? Fine with either answer. |
|
For 3 I got carried away. cs-fixer works only on cphalcon since it cannot handle zep files so ignore that. |
…changelog - Model.zep: reword the comment; without sequences lastInsertId() returns the stored id, MySQL can replace 0 with a generated id. - CreateTest: add testMvcModelCreateWithZeroIdentitySqlite (0 is stored as given and read back as the string '0'), assertSame on the MySQL zero test, union type spacing. - CHANGELOG: shorten the entry. Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hello!
In raising this pull request, I confirm the following:
Small description of change:
Since #16920 (fix for #16436),
Model::doLowInsert()reuses any non-empty identity value instead of callinglastInsertId(). On MySQL,0is not an explicit id: MySQL replaces it with the next auto-increment value, so a model whose identity property defaults to0keeps0aftersave()/create().The value on the model is now reused on adapters with sequences (as before), and for any explicit non-zero value (same value and type as before). Only
0on adapters without sequences goes throughlastInsertId()again. The PostgreSQL behaviour from #16436 is unchanged, and the explicit-id path keeps returning the value as set (no int to string change).supportSequences()is now called once and stored inuseSequences.Tests (
tests/database/Mvc/Model/CreateTest.php):testMvcModelCreateWithZeroIdentityMysql(data set0and'0'): the model gets the id stored in the table.testMvcModelCreateWithExplicitIdMysqlSqlite: an explicit77is kept as int77.Checked locally (Debian 12, PHP 8.2.35, MariaDB 10.11.19, PostgreSQL 16, SQLite), with one extension built from
5.0.xand one from this branch (Zephir 1.6.1):5.0.xCreateTestmysqlCreateTestsqliteCreateTestpgsql, including the #16436 teststests/database/Mvc/Modelmysql / sqlite / pgsqlThe remaining errors in the full
tests/database/Mvc/Modelruns were the same on both builds and came from my environment (APCu not enabled in CLI).phpcsandphp-cs-fixer --dry-runpass on the test file.Thanks
🤖 Generated with Claude Code