From: Jay Freeman (saurik) Date: Fri, 30 Jul 2010 07:21:07 +0000 (+0000) Subject: Add exists(), refactoring yank() to take an argument for offset (required as a utility). X-Git-Url: https://git.saurik.com/cyql.git/commitdiff_plain/f1df255a1450b9f5040a075f11310e12713cd46d?hp=229bbf8c4928ba0ce6d47fbb0b102c1f20eac8c0 Add exists(), refactoring yank() to take an argument for offset (required as a utility). --- 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