def guard(fn): """Decorator function that converts MySQL exceptions into weedb exceptions.""" def guarded_fn(*args, **kwargs): try: return fn(*args, **kwargs) except _mysql_exceptions.IntegrityError, e: raise weedb.IntegrityError(e) except _mysql_exceptions.ProgrammingError, e: raise weedb.ProgrammingError(e)
def columnsOf(self, table): """Return a list of columns in the specified table. If the table does not exist, None is returned.""" column_list = [row[1] for row in self.genSchemaOf(table)] # If there are no columns (which means the table did not exist) raise an exceptional if not column_list: raise weedb.ProgrammingError("No such table %s" % table) return column_list
def guard(fn): """Decorator function that converts sqlite exceptions into weedb exceptions.""" def guarded_fn(*args, **kwargs): try: return fn(*args, **kwargs) except sqlite3.IntegrityError, e: raise weedb.IntegrityError(e) except sqlite3.OperationalError, e: # Change no such table errors into a ProgrammingError # (this is what MySQL does). if e.message.lower().startswith("no such table"): raise weedb.ProgrammingError(e) raise weedb.OperationalError(e)
def guarded_fn(*args, **kwargs): try: return fn(*args, **kwargs) except sqlite3.IntegrityError as e: raise weedb.IntegrityError(e) except sqlite3.OperationalError as e: msg = str(e).lower() if msg.startswith("unable to open"): raise weedb.PermissionError(e) elif msg.startswith("no such table"): raise weedb.NoTableError(e) elif msg.endswith("already exists"): raise weedb.TableExistsError(e) elif msg.startswith("no such column"): raise weedb.NoColumnError(e) else: raise weedb.OperationalError(e) except sqlite3.ProgrammingError as e: raise weedb.ProgrammingError(e)
except sqlite3.IntegrityError, e: raise weedb.IntegrityError(e) except sqlite3.OperationalError, e: msg = str(e).lower() if msg.startswith("unable to open"): raise weedb.PermissionError(e) elif msg.startswith("no such table"): raise weedb.NoTableError(e) elif msg.endswith("already exists"): raise weedb.TableExistsError(e) elif msg.startswith("no such column"): raise weedb.NoColumnError(e) else: raise weedb.OperationalError(e) except sqlite3.ProgrammingError, e: raise weedb.ProgrammingError(e) return guarded_fn def connect(database_name='', SQLITE_ROOT='', driver='', **argv): # @UnusedVariable """Factory function, to keep things compatible with DBAPI. """ return Connection(database_name=database_name, SQLITE_ROOT=SQLITE_ROOT, **argv) @guard