Escape special characters for LIKE in node lookup. pithos/v0.8.1
authorAntony Chazapis <chazapis@gmail.com>
Mon, 5 Dec 2011 16:38:33 +0000 (18:38 +0200)
committerAntony Chazapis <chazapis@gmail.com>
Mon, 5 Dec 2011 16:38:33 +0000 (18:38 +0200)
pithos/backends/lib/sqlalchemy/node.py

index 7cf3827..4a0fc55 100644 (file)
@@ -209,6 +209,9 @@ class Node(DBWorker):
            Return None if the path is not found.
         """
         
+        # Use LIKE for comparison to avoid MySQL problems with trailing spaces.
+        path = path.replace('%', '\%')
+        path = path.replace('_', '\_')
         s = select([self.nodes.c.node], self.nodes.c.path.like(path))
         r = self.conn.execute(s)
         row = r.fetchone()