Skip to content

Commit b4aa6ec

Browse files
committed
fix incorrect bytea escaping for Postgres 9.1+
1 parent 439f3aa commit b4aa6ec

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

core/DB/PostgresDialect.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ public static function prepareFullText(array $words, $logic)
7272

7373
public function quoteBinary($data)
7474
{
75-
return "E'".pg_escape_bytea($data)."'";
75+
$esc = pg_escape_bytea($data);
76+
if (mb_strpos($esc, '\\x') === 0) {
77+
// http://www.postgresql.org/docs/9.1/static/datatype-binary.html
78+
// if pg_escape_bytea use postgres 9.1+ it's return value like '\x00aabb' (new bytea hex format),
79+
// but must return '\\x00aabb'. So we use this fix:'
80+
return "E'\\".$esc."'";
81+
} else {
82+
//if function escape value like '\\000\\123' - all ok
83+
return "E'".$esc."'";
84+
}
7685
}
7786

7887
public function unquoteBinary($data)

doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-08-10 Alexey S. Denisov
2+
3+
* core/DB/PostgresDialect.class.php:
4+
fix incorrect bytea escaping for Postgres 9.1+
5+
16
2012-08-10 Alexey S. Denisov
27

38
* core/Form/Primitives/PrimitiveHstore.class.php:

0 commit comments

Comments
 (0)