def row_absent(name, db, table, where_sql, where_args=None):
    '''
    Makes sure the specified row is absent in db.  If multiple rows
    match where_sql, then the state will fail.

    name
        Only used as the unique ID

    db
        The database file name

    table
        The table name to check

    where_sql
        The sql to select the row to check

    where_args
        The list parameters to substitute in where_sql
    '''
    changes = {'name': name,
               'changes': {},
               'result': None,
               'comment': ''}
    conn = None
    try:
        conn = sqlite3.connect(db, detect_types=sqlite3.PARSE_DECLTYPES)
        conn.row_factory = _dict_factory
        rows = None
        if where_args is None:
            rows = _query(conn,
                          "SELECT * FROM `" + table + "` WHERE " + where_sql)
        else:
            rows = _query(conn,
                          "SELECT * FROM `" + table + "` WHERE " + where_sql,
                          where_args)

        if len(rows) > 1:
            changes['result'] = False
            changes['comment'] = "More than one row matched the specified query"
        elif len(rows) == 1:
            if __opts__['test']:
                changes['result'] = True
                changes['comment'] = "Row will be removed in " + table
                changes['changes']['old'] = rows[0]

            else:
                if where_args is None:
                    cursor = conn.execute("DELETE FROM `" +
                                          table + "` WHERE " + where_sql)
                else:
                    cursor = conn.execute("DELETE FROM `" +
                                          table + "` WHERE " + where_sql,
                                          where_args)
                conn.commit()
                if cursor.rowcount == 1:
                    changes['result'] = True
                    changes['comment'] = "Row removed"
                    changes['changes']['old'] = rows[0]
                else:
                    changes['result'] = False
                    changes['comment'] = "Unable to remove row"
        else:
            changes['result'] = True
            changes['comment'] = 'Row is absent'

    except Exception as e:
        changes['result'] = False
        changes['comment'] = six.text_type(e)

    finally:
        if conn:
            conn.close()

    return changes
def row_absent ( name , db , table , where_sql , where_args = None ) : changes = { 'name' : name , 'changes' : { } , 'result' : None , 'comment' : '' } conn = None try : conn = sqlite3 . connect ( db , detect_types = sqlite3 . PARSE_DECLTYPES ) conn . row_factory = _dict_factory rows = None if where_args is None : rows = _query ( conn , "SELECT * FROM `" + table + "` WHERE " + where_sql ) else : rows = _query ( conn , "SELECT * FROM `" + table + "` WHERE " + where_sql , where_args ) if len ( rows ) > 1 : changes [ 'result' ] = False changes [ 'comment' ] = "More than one row matched the specified query" elif len ( rows ) == 1 : if __opts__ [ 'test' ] : changes [ 'result' ] = True changes [ 'comment' ] = "Row will be removed in " + table changes [ 'changes' ] [ 'old' ] = rows [ 0 ] else : if where_args is None : cursor = conn . execute ( "DELETE FROM `" + table + "` WHERE " + where_sql ) else : cursor = conn . execute ( "DELETE FROM `" + table + "` WHERE " + where_sql , where_args ) conn . commit ( ) if cursor . rowcount == 1 : changes [ 'result' ] = True changes [ 'comment' ] = "Row removed" changes [ 'changes' ] [ 'old' ] = rows [ 0 ] else : changes [ 'result' ] = False changes [ 'comment' ] = "Unable to remove row" else : changes [ 'result' ] = True changes [ 'comment' ] = 'Row is absent' except Exception as e : changes [ 'result' ] = False changes [ 'comment' ] = six . text_type ( e ) finally : if conn : conn . close ( ) return changes
Makes sure the specified row is absent in db.  If multiple rows
    match where_sql, then the state will fail.

    name
        Only used as the unique ID

    db
        The database file name

    table
        The table name to check

    where_sql
        The sql to select the row to check

    where_args
        The list parameters to substitute in where_sql