-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RawSql to BaseConnection->escape()
- Loading branch information
1 parent
cef5e53
commit e848e00
Showing
6 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$stringArray = [' A simple string ', new RawSql('CURRENT_TIMESTAMP()'), false, null]; | ||
|
||
$escapedString = $db->escape($stringArray); | ||
|
||
$this->assertSame("'A simple string'", $escapedString[0]); // adds quotes | ||
$this->assertSame('CURRENT_TIMESTAMP()', $escapedString[1]); // does not add quotes | ||
$this->assertSame(0, $escapedString[2]); // converts bool to 1 or 0 | ||
$this->assertSame('NULL', $escapedString[3]); // null returns NULL without quotes | ||
$this->assertSame("'{braces}'", $escapedString[4]); // actual braces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
$data = [ | ||
'id' => new RawSql('DEFAULT'), | ||
'title' => 'My title', | ||
'name' => 'My Name', | ||
'date' => '2022-01-01', | ||
'last_update' => new RawSql('CURRENT_TIMESTAMP()'), | ||
]; | ||
|
||
$builder->insert($data); | ||
/* Produces: | ||
INSERT INTO mytable (id, title, name, date, last_update) | ||
VALUES (DEFAULT, 'My title', 'My name', '2022-01-01', CURRENT_TIMESTAMP()) | ||
*/ |