[geeklog-cvs] geeklog: Translate MySQL CONCAT into Postgres equivalent for search
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Feb 7 04:15:54 EST 2010
changeset 7706:bf5d451bc7aa
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/bf5d451bc7aa
user: Dirk Haun <dirk at haun-online.de>
date: Sun Feb 07 09:19:40 2010 +0100
description:
Translate MySQL CONCAT into Postgres equivalent for search
diffstat:
system/classes/search.class.php | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diffs (46 lines):
diff -r 6b3dc3088dfe -r bf5d451bc7aa system/classes/search.class.php
--- a/system/classes/search.class.php Sun Feb 07 09:12:01 2010 +0100
+++ b/system/classes/search.class.php Sun Feb 07 09:19:40 2010 +0100
@@ -882,27 +882,31 @@
}
/**
- * Converts the MySQL CONCAT function to the MSSQL equivalent
+ * Converts the MySQL CONCAT function to the MS SQL / Postgres equivalents
*
* @access private
- * @param string $sql The SQL to convert
- * @return string MSSQL friendly SQL
+ * @param string $sql The SQL to convert
+ * @return string MS SQL or PostgreSQL friendly SQL
*
*/
- function _convertsql( $sql )
+ function _convertsql($sql)
{
global $_DB_dbms;
- if ($_DB_dbms == 'mssql')
- {
- if (is_string( $sql ))
- {
+
+ if ($_DB_dbms == 'mssql') {
+ if (is_string($sql)) {
$sql = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 + ', '\\1')", $sql);
- }
- else if (is_array( $sql ))
- {
+ } elseif (is_array($sql)) {
$sql['mssql'] = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 + ', '\\1')", $sql['mssql']);
}
+ } elseif ($_DB_dbms == 'pgsql') {
+ if (is_string($sql)) {
+ $sql = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 || ', '\\1')", $sql);
+ } elseif (is_array($sql)) {
+ $sql['pgsql'] = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 || ', '\\1')", $sql['pgsql']);
+ }
}
+
return $sql;
}
More information about the geeklog-cvs
mailing list