From 756d775dc874d7555c0e433c8981264c5a0b25dd Mon Sep 17 00:00:00 2001 From: Matthew Emmett Date: Fri, 11 May 2012 11:10:32 -0400 Subject: [PATCH] SQLITE: Tweak CREATE TABLE statement and don't catch exceptions. An 'IF NOT EXISTS' clause was added to the CREATE TABLE query so that exceptions would not be raised if the table already exists. Then, the try/except statements were removed so that other database errors would be propagated. --- pymc/database/sqlite.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pymc/database/sqlite.py b/pymc/database/sqlite.py index 312710fa88..6025829603 100755 --- a/pymc/database/sqlite.py +++ b/pymc/database/sqlite.py @@ -64,14 +64,10 @@ def _initialize(self, chain, length): # Create the variable name strings. vstr = ', '.join(v + ' FLOAT' for v in var_str(self._shape)) - - try: - query = "create table [%s] (recid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, trace int(5), %s )" % (self.name, vstr) - - self.db.cur.execute(query) - except OperationalError: - "Table already exists" - return + query = """CREATE TABLE IF NOT EXISTS [%s] + (recid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + trace int(5), %s)""" % (self.name, vstr) + self.db.cur.execute(query)