[SQL-CVS] r334 - trunk/SQLObject/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2004-11-05 21:40:23
|
Author: ianb Date: 2004-11-05 12:24:01 -0500 (Fri, 05 Nov 2004) New Revision: 334 Modified: trunk/SQLObject/sqlobject/sqlbuilder.py Log: The % in LIKE expressions is quoted in different ways on different databases. This uses \% for Postgres and MySQL, %% for other databases Modified: trunk/SQLObject/sqlobject/sqlbuilder.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/sqlobject/sqlbuilder.py 2004-11-05 15:08:12 UTC (rev = 333) +++ trunk/SQLObject/sqlobject/sqlbuilder.py 2004-11-05 17:24:01 UTC (rev = 334) @@ -546,13 +546,13 @@ return SQLOp("LIKE", expr, string) =20 def STARTSWITH(expr, string): - return SQLOp("LIKE", expr, _likeQuote(string) + '%') + return SQLOp("LIKE", expr, _LikeQuoted(string) + '%') =20 def ENDSWITH(expr, string): - return SQLOp("LIKE", expr, '%' + _likeQuote(string)) + return SQLOp("LIKE", expr, '%' + _LikeQuoted(string)) =20 def CONTAINSSTRING(expr, string): - return SQLOp("LIKE", expr, '%' + _likeQuote(string) + '%') + return SQLOp("LIKE", expr, '%' + _LikeQuoted(string) + '%') =20 def ISNULL(expr): return SQLOp("IS", expr, None) @@ -560,9 +560,20 @@ def ISNOTNULL(expr): return SQLOp("IS NOT", expr, None) =20 -def _likeQuote(s): - return s.replace('%', '%%') +class _LikeQuoted: + # @@: I'm not sure what the quoting rules really are for all the + # databases =20 + def __init__(self, expr): + self.expr =3D expr + + def __sqlrepr__(self, db): + s =3D sqlrepr(self.expr, db) + if db in ('postgres', 'mysql'): + return s.replace('%', '\\%') + else: + return s.replace('%', '%%') + ######################################## ## Global initializations ######################################## |