def execute(self, qry, args = []):
        #print repr(qry),  repr(args), self.connection.charset
        
        if self.closed:
            raise ProgrammingError('this cursor is already closed')

        if type(qry) == unicode:
            #we will only communicate in 8-bits with mysql
            qry = qry.encode(self.connection.charset)
            
        try:
            self._close_result() #close any previous result if needed
            #substitute arguments
            for arg in args:
                if type(arg) == str:
                    qry = qry.replace('%s', "'%s'" % self._escape_string(arg), 1)
                elif type(arg) == unicode:
                    qry = qry.replace('%s', "'%s'" % self._escape_string(arg).encode(self.connection.charset), 1)
                elif type(arg) == int:
                    qry = qry.replace('%s', str(arg), 1)
                elif type(arg) == long:
                    qry = qry.replace('%s', str(arg), 1)
                elif arg is None:
                    qry = qry.replace('%s', 'null', 1)
                elif isinstance(arg, datetime):
                    qry = qry.replace('%s', "'%s'" % arg.strftime('%Y-%m-%d %H:%M:%S'), 1)
                else:
                    assert False, "unknown argument type: %s %s" % (type(arg), repr(arg))
            
            result = self.connection.client.query(qry)
            
            #process result if nescecary
            if isinstance(result, client.ResultSet):
                self.description = tuple(((name, type_code, None, None, None, None, None) for name, type_code in result.fields))
                self.result = result
                self.result_iter = iter(result)
                self.lastrowid = None
                self.rowcount = -1
            else:
                self.rowcount, self.lastrowid = result
                self.description = None
                self.result = None

        except TaskletExit:
            raise
        except Exception, e:
            raise self._wrap_exception(e, "an error occurred while executing qry %s" % (qry, ))
dataset/ETHPy150Open concurrence/concurrence/lib/concurrence/database/mysql/dbapi.py/Cursor.execute/original