mirror of
https://github.com/dg/dibi.git
synced 2025-08-10 16:14:57 +02:00
implemented escapeLike() and modifiers %~like, %like~, %~like~
This commit is contained in:
@@ -114,11 +114,11 @@ final class DibiTranslator extends DibiObject
|
||||
(")((?:""|[^"])*)"| ## 5,6) "string"
|
||||
(\'|")| ## 7) lone quote
|
||||
:(\S*?:)([a-zA-Z0-9._]?)| ## 8,9) :substitution:
|
||||
%([a-zA-Z]{1,4})(?![a-zA-Z])|## 10) modifier
|
||||
%([a-zA-Z~][a-zA-Z0-9~]{0,5})|## 10) modifier
|
||||
(\?) ## 11) placeholder
|
||||
)/xs',
|
||||
*/ // note: this can change $this->args & $this->cursor & ...
|
||||
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z]{1,4})(?![a-zA-Z])|(\?))/s',
|
||||
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s',
|
||||
array($this, 'cb'),
|
||||
substr($arg, $toSkip)
|
||||
);
|
||||
@@ -387,6 +387,15 @@ final class DibiTranslator extends DibiObject
|
||||
case 'SQL': // preserve as real SQL (TODO: rename to %sql)
|
||||
return (string) $value;
|
||||
|
||||
case 'like~': // LIKE string%
|
||||
return $this->driver->escapeLike($value, 1);
|
||||
|
||||
case '~like': // LIKE %string
|
||||
return $this->driver->escapeLike($value, -1);
|
||||
|
||||
case '~like~': // LIKE %string%
|
||||
return $this->driver->escapeLike($value, 0);
|
||||
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'a':
|
||||
|
@@ -166,6 +166,14 @@ interface IDibiDriver
|
||||
*/
|
||||
function escape($value, $type);
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
function escapeLike($value, $pos);
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string &$sql The SQL query that will be modified.
|
||||
|
Reference in New Issue
Block a user