Skip to content

Conversation

@dereuromark
Copy link
Member

@dereuromark dereuromark commented Apr 8, 2025

Resolves #836

Apparently adding this to bulkinsert()

                    if ($placeholder == '?') {
                        if ($v instanceof DateTime) {
                            $vals[] = $v->toDateTimeString();
                        } elseif ($v instanceof Date) {
                            $vals[] = $v->toDateString();
                        } elseif (is_bool($v)) {
                            $vals[] = $this->castToBool($v);
                        } else {
                            $vals[] = $v;
                        }
                    }

seems to fix it for my local MySql env.

How could a test case look like for this?
And in what class, for what method?

@markstory markstory added this to the 4.x (CakePHP 5) milestone Apr 8, 2025
@markstory
Copy link
Member

How could a test case look like for this?

There are a few tests for bulkinsert already, there could be a new test for bulkinsert with datetime values. Most of the tests we have for bulkinsert are in each driver implementation though.

And in what class, for what method?

You could include a seed integration test. There are a few integration tests for bin/cake migrations seed and we could have another one that inserts into a table with datetime columns.

@dereuromark
Copy link
Member Author

Hm its all super confusing as long as we didnt major and get rid of the overhead of two systems under the hood.
Current seeds in testapp still

extends AbstractSeed

So I assume this is part why for tests they dont run into the code above.
Also, once I add a local DateTime::setToStringFormat() it also seems to cause issues.

I might need some help to get this covered.

In real prod env the above fix works fine (using BaseSeed ext) and saves DateTime properly now.

@dereuromark
Copy link
Member Author

I removed the changes again, the tests still pass.
But locally, on my system, it does not pass for actual DB columns.

@dereuromark
Copy link
Member Author

dereuromark commented Apr 8, 2025

Hah now I can reproduce also in CI :)
But it seems for test run it does not make a difference, it skips this adapter and seems to use its own one.

@dereuromark
Copy link
Member Author

@markstory Thanks a lot for the help
It indeed only gets triggered throw this part of the system

I was finally able to get it reproduced for Mysql both locally and on CI, and was able to show now that the fix indeed is helping.

@dereuromark
Copy link
Member Author

The remaining error seems to be dependant on a fix in Phinx directly maybe?
cakephp/phinx#2348

The rest seems now green instead of red :)

@dereuromark
Copy link
Member Author

All fixed, and the phinx one should be merged soon.

PS: Lets please squash merge this one.

@dereuromark dereuromark changed the title Fix up DateTime support. Fix up DateTime support for seed bulkinsert(). Apr 16, 2025
@dereuromark
Copy link
Member Author

@dereuromark
Copy link
Member Author

@markstory
Copy link
Member

  1. Migrations\Test\TestCase\MigrationsTest::testSeed with data set #0 ('builtin')
    Cake\Database\Exception\QueryException: SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
    Query: INSERT INTO [dbo].[stores] ([name], [created], [modified]) VALUES ('foo', '4/17/25', '4/17/25'),('foo_with_date', '4/17/25, 5:55 PM', '4/17/25, 5:55 PM')

It looks like there are still some issues with datetimes being cast to the wrong string format. This could be a migrations issue. There was a specialized bulkinsert implementation added in #826

@dereuromark
Copy link
Member Author

Thx, I think I finally got it.

The remaining fail is already on 4.x and due to the fact that we support still cake5.0, and we probably need a version switch on those tests.

@markstory
Copy link
Member

The remaining fail is already on 4.x and due to the fact that we support still cake5.0, and we probably need a version switch on those tests.

I have to bump the dev dependency to not use 5.x-dev.

@markstory markstory merged commit cd1f6ca into 4.x Apr 19, 2025
12 of 13 checks passed
@markstory markstory deleted the 4-x-datetime branch April 19, 2025 16:38
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.

Seed issue with DateTime

3 participants