def execute(self, sql, params=None):
logging.debug(sql)<EOL>try:<EOL><INDENT>self._cursor.execute(sql, params)<EOL>if self.autocommit:<EOL><INDENT>self._conn.commit()<EOL><DEDENT>if self._cursor.rowcount > <NUM_LIT:0>:<EOL><INDENT>return self._cursor.rowcount<EOL><DEDENT><DEDENT>except psycopg2.Error as error:<EOL><INDENT>logging.debug('<STR_LIT>'.format(<EOL>error.pgcode, error.pgerror))<EOL>self._conn.rollback()<EOL>raise<EOL><DEDENT>
Execute given SQL.
Calls `rollback` if there's a DB error and re-raises the exception.
Calls `commit` if autocommit is True and there was no error.
Returns number of rows affected (for commands that affect rows).

>>> import getpass
>>> s = DB(dbname='test', user=getpass.getuser(), host='localhost',
... password='')
>>> s.execute('drop table if exists t2')
>>> s.execute('drop table t2')
Traceback (most recent call last):
    ...
ProgrammingError: table "t2" does not exist
<BLANKLINE>