From 7258b83dbb8f21697ae044ceb3d7da6f03b9027c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 21 Jul 2017 12:05:47 +0200 Subject: [PATCH] DbHelper: new trait with DB-specific utils --- library/Director/Web/Table/DbHelper.php | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 library/Director/Web/Table/DbHelper.php diff --git a/library/Director/Web/Table/DbHelper.php b/library/Director/Web/Table/DbHelper.php new file mode 100644 index 00000000..1a76db20 --- /dev/null +++ b/library/Director/Web/Table/DbHelper.php @@ -0,0 +1,43 @@ +isPgsql()) { + return sprintf("LOWER(ENCODE(%s, 'hex'))", $column); + } else { + return sprintf("LOWER(HEX(%s))", $column); + } + } + + public function quoteBinary($binary) + { + if ($this->isPgsql()) { + return new Expr("'\\x" . bin2hex($binary) . "'"); + } + + return $binary; + } + + public function isPgsql() + { + return $this->db->getConfig() instanceof \Zend_Db_Adapter_Pdo_Pgsql; + } + + public function isMysql() + { + return $this->db->getConfig() instanceof \Zend_Db_Adapter_Pdo_Mysql; + } + + public function wantBinaryValue($value) + { + if (is_resource($value)) { + return stream_get_contents($value); + } + + return $value; + } +}