[dev] PATCH: PostgreSQL lib/SQL.php

Jason M. Felice jfelice at cronosys.com
Wed Jul 16 09:51:19 PDT 2003


The last fix (which removed SIMILAR TO) has a logic error in the regexp- it
will match anything with a digit, including 'foo9', for example, which would
cause the cast to fail.

The attached patch fixes the regexp.

-- 
 Jason M. Felice
 Cronosys, LLC <http://www.cronosys.com/>
 216.221.4600 x302
-------------- next part --------------
Index: lib/SQL.php
===================================================================
RCS file: /repository/horde/lib/SQL.php,v
retrieving revision 1.16
diff -u -u -r1.16 SQL.php
--- lib/SQL.php	16 Jul 2003 04:17:40 -0000	1.16
+++ lib/SQL.php	16 Jul 2003 16:48:49 -0000
@@ -38,7 +38,7 @@
             case 'pgsql':
                 // Only PgSQL 7.3+ understand SQL99 'SIMILAR TO'; use ~ for
                 // greater backwards compatibility
-                return sprintf('CASE WHEN CAST(%s AS VARCHAR) ~ \'-?[0-9]+\' THEN (CAST(%s AS INTEGER) %s %d) <> 0 ELSE FALSE END', $lhs, $lhs, $op, (int)$rhs);
+                return sprintf('CASE WHEN CAST(%s AS VARCHAR) ~ \'^-?[0-9]+$\' THEN (CAST(%s AS INTEGER) %s %d) <> 0 ELSE FALSE END', $lhs, $lhs, $op, (int)$rhs);
 
             default:
                 return sprintf('%s %s %d', $lhs, $op, (int)$rhs);


More information about the dev mailing list