-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add RawSql to BaseConnection->escape() #6332
Conversation
Looks like a cool feature! The changes look good to me but I'd rather someone with a better idea of the larger database implications handle reviews. @iRedds or @paulbalandan ? |
Please update the all notes in query_builder.rst:
|
Looking good! Thanks for all the reviews. |
@kenjis What do you propose we do here? How about: .. note:: All values except ``RawSql`` are escaped automatically producing safer queries. |
I think the following section is weird. Because it explains I think we should remove the sample and description for This section explains how to use See the first sample code. The assumption here is that SQL statements are generated by concatenating strings. |
So you want to remove everything? Then none will know about its availability for use. I think the example is good because it explains what the method does. The method does different things to different types of data. It could be possible to add other data types such as Datetime. Its important to know how these datatypes are treated. |
Developers might should understand that the escape method is what they are relying on when they employ functions like insert. They might not write the actual code for db->escape() but they are none the less calling it via ignoring the escape parameter on functions like insert(). |
I thought again, and yes. Because the page explains how to use Your explanation about
Yes, and the explanation should be in the |
Maybe RawSql needs its own page |
I wonder if this will conflict with binds.. |
Sounds like a test case is in order 😊 |
No conflict with binds but did have to fix objectToArray() in BaseBuilder |
Why doesn't the existing test fail? |
The existing test just tests escape(). Ill write some tests to test things like insert(). |
Added RawSql test.. to test custom SQL function:
Returns: This way the RawSql has quotes in it to test and make sure quotes aren't being escaped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenjis last call?
Sorry, can you rebase to resolve the conflict? |
The usage example is rather ambiguous. $data = [
'title' => 'My title',
'name' => 'My Name',
'date' => '2022-01-01',
];
$builder->set([
'id' => 'DEFAULT',
'last_update' => 'CURRENT_TIMESTAMP()',
], null, false)->insert($data); |
Your trick won't work on |
@iRedds To be honest, I would like to throw an Exception to such code. It is difficult to read. By the way, what do you mean ambiguous ? |
I think @iRedds was pointing out that we can already accomplish the same thing with other tools. |
I agree that we can already accomplish the same thing with other tools. |
Thanks all! |
This PR adds
RawSql
type toBaseConnection->escape()
. It does not escape theRawSql
.This allows passing SQL functions in columns used for DML operations.
For instance you could pass
CURRENT_TIMESTAMP()
to a date time field instead of a literal value.You could call your own SQL function as well.
Another is to pass SQL constants like
DEFAULT
in order to fill a column with default values.Checklist: