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>

def execute(self, sql, params=None):
        """
        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>
        """
        logging.debug(sql)
        try:
            self._cursor.execute(sql, params)
            if self.autocommit:
                self._conn.commit()
            if self._cursor.rowcount > 0:
                return self._cursor.rowcount
        except psycopg2.Error, error:
            logging.debug('PG error ({}): {}'.format(
                error.pgcode, error.pgerror))
            self._conn.rollback()
            raise