'Execute a query.
query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.
Note: If args is a sequence, then %s must be used as the
parameter placeholder in the query. If a mapping is used,
%(key)s must be used as the placeholder.
Returns long integer rows affected, if any'

def execute(self, query, args=None):

    del self.messages[:]
    db = self._get_db()
    if isinstance(query, unicode):
        query = query.encode(db.unicode_literal.charset)
    if (args is not None):
        if isinstance(args, dict):
            query = (query % dict(((key, db.literal(item)) for (key, item) in args.iteritems())))
        else:
            query = (query % tuple([db.literal(item) for item in args]))
    try:
        r = None
        r = self._query(query)
    except TypeError as m:
        if (m.args[0] in ('not    enough    arguments    for    format    string', 'not    all    arguments    converted')):
            self.messages.append((ProgrammingError, m.args[0]))
            self.errorhandler(self, ProgrammingError, m.args[0])
        else:
            self.messages.append((TypeError, m))
            self.errorhandler(self, TypeError, m)
    except (SystemExit, KeyboardInterrupt):
        raise
    except:
        (exc, value, tb) = sys.exc_info()
        del tb
        self.messages.append((exc, value))
        self.errorhandler(self, exc, value)
    self._executed = query
    if (not self._defer_warnings):
        self._warning_check()
    return r
