Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Literal values in inserts #2301

Merged
merged 1 commit into from
Aug 5, 2024
Merged

Support Literal values in inserts #2301

merged 1 commit into from
Aug 5, 2024

Conversation

MasterOdin
Copy link
Member

@MasterOdin MasterOdin commented Aug 4, 2024

Closes #2297

PR adds support for using \Phinx\Util\Literal in insert operations, so that can do stuff like insert CURRENT_TIMESTAMP. Previously, we were always passing all values in the insert data as binded variables to the escaped SQL statement. Now, the literal values will be inserted directly into the escaped SQL statement, while non literals values will continue to be binded.

@MasterOdin MasterOdin force-pushed the feat-literal-insert branch 6 times, most recently from b274511 to b0afe3a Compare August 4, 2024 18:10
@MasterOdin MasterOdin marked this pull request as ready for review August 4, 2024 18:21
@dereuromark
Copy link
Member

@markstory Do we need to port this to migrations as well?

Comment on lines +374 to +376
if ($value instanceof Literal) {
return (string)$value;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

quoteValue is used only in the insert functions for dry-run output as well as two queries in the sqlite adapter where it always operates on a string, so not much risk this breaks something.

@MasterOdin MasterOdin merged commit b0f4397 into 0.x Aug 5, 2024
12 checks passed
@MasterOdin MasterOdin deleted the feat-literal-insert branch August 5, 2024 14:39
$data = [
[
'column1' => 'value1',
'column3' => Literal::from('CURRENT_TIMESTAMP'),

Choose a reason for hiding this comment

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

👍

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.

Unable to seed rows using CURRENT_TIMESTAMP
3 participants