Skip to content

Commit 756d775

Browse files
author
Matthew Emmett
committed
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.
1 parent c903738 commit 756d775

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

pymc/database/sqlite.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,10 @@ def _initialize(self, chain, length):
6464

6565
# Create the variable name strings.
6666
vstr = ', '.join(v + ' FLOAT' for v in var_str(self._shape))
67-
68-
try:
69-
query = "create table [%s] (recid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, trace int(5), %s )" % (self.name, vstr)
70-
71-
self.db.cur.execute(query)
72-
except OperationalError:
73-
"Table already exists"
74-
return
67+
query = """CREATE TABLE IF NOT EXISTS [%s]
68+
(recid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
69+
trace int(5), %s)""" % (self.name, vstr)
70+
self.db.cur.execute(query)
7571

7672

7773

0 commit comments

Comments
 (0)