<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def logged_query(cr, query, args=None, skip_no_result=False):
 """ Logs query and affected rows at level DEBUG. :param query: a query string suitable to pass to cursor.execute() :param args: a list, tuple or dictionary passed as substitution values to cursor.execute(). :param skip_no_result: If True, then logging details are only shown if there are affected records. """

    if args is None:
        args = ()
    args = tuple(args) if type(args) == list else args
    try:
        cr.execute(query, args)
    except (ProgrammingError, IntegrityError):
        logger.error('Error running %s' % cr.mogrify(query, args))
        raise
    if not skip_no_result or cr.rowcount:
        logger.debug('Running %s', query % args)
        logger.debug('%s rows affected', cr.rowcount)
    return cr.rowcount