IdoQuery::initializeForPostgres(): cast only valid IP addresses to inet

fixes #7165
This commit is contained in:
Alexander A. Klimov 2015-05-12 16:35:14 +02:00
parent 4bda1cf6d6
commit 7353c0d287
1 changed files with 5 additions and 1 deletions

View File

@ -370,7 +370,11 @@ abstract class IdoQuery extends DbQuery
if ($count > 0) { if ($count > 0) {
$this->columnsWithoutCollation[] = $this->getMappedField($key); $this->columnsWithoutCollation[] = $this->getMappedField($key);
} }
$value = preg_replace('/inet_aton\(([[:word:].]+)\)/i', '$1::inet - \'0.0.0.0\'', $value); $value = preg_replace(
'/inet_aton\(([[:word:].]+)\)/i',
'(CASE WHEN $1 ~ \'(?:[0-9]{1,3}\\\\.){3}[0-9]{1,3}\' THEN $1::inet - \'0.0.0.0\' ELSE NULL END)',
$value
);
$value = preg_replace( $value = preg_replace(
'/UNIX_TIMESTAMP(\((?>[^()]|(?-1))*\))/i', '/UNIX_TIMESTAMP(\((?>[^()]|(?-1))*\))/i',
'CASE WHEN ($1 < \'1970-01-03 00:00:00+00\'::timestamp with time zone) THEN 0 ELSE UNIX_TIMESTAMP($1) END', 'CASE WHEN ($1 < \'1970-01-03 00:00:00+00\'::timestamp with time zone) THEN 0 ELSE UNIX_TIMESTAMP($1) END',