From f1df255a1450b9f5040a075f11310e12713cd46d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 30 Jul 2010 07:21:07 +0000 Subject: [PATCH] Add exists(), refactoring yank() to take an argument for offset (required as a utility). --- __init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 2bddbe4..bda044b 100644 --- a/__init__.py +++ b/__init__.py @@ -56,8 +56,8 @@ class transaction(object): with self.connection.execute(statement, 1) as cursor: return cursor.fetchall() - def yank(self, statement): - with self.connection.execute(statement, 1) as cursor: + def yank(self, statement, offset=0): + with self.connection.execute(statement, 1 + offset) as cursor: rows = cursor.fetchall() return rows[0] if len(rows) != 0 else None @@ -65,6 +65,13 @@ class transaction(object): with self.connection.execute(statement, 1) as cursor: pass + def exists(self, statement): + return yank(''' + select exists ( + {statement} + ) + ''')[0] + @contextmanager def connect(dsn): attempt = 0 -- 2.47.2