def execute(self, query, args=None):
while self.nextset():<EOL><INDENT>pass<EOL><DEDENT>db = self._get_db()<EOL>if isinstance(query, unicode):<EOL><INDENT>query = query.encode(db.encoding)<EOL><DEDENT>if args is not None:<EOL><INDENT>if isinstance(args, dict):<EOL><INDENT>nargs = {}<EOL>for key, item in args.items():<EOL><INDENT>if isinstance(key, unicode):<EOL><INDENT>key = key.encode(db.encoding)<EOL><DEDENT>nargs[key] = db.literal(item)<EOL><DEDENT>args = nargs<EOL><DEDENT>else:<EOL><INDENT>args = tuple(map(db.literal, args))<EOL><DEDENT>try:<EOL><INDENT>query = query % args<EOL><DEDENT>except TypeError as m:<EOL><INDENT>raise ProgrammingError(str(m))<EOL><DEDENT><DEDENT>assert isinstance(query, (bytes, bytearray))<EOL>res = self._query(query)<EOL>return res<EOL>
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 integer represents rows affected, if any