def case_db_to_dict(dbname, varnames, case_sql='', var_sql='', include_errors=False):
    """
    Retrieve the values of specified variables from a sqlite DB containing
    Case data.

    Returns a dict containing a list of values for each entry, keyed on
    variable name.

    Only data from cases containing ALL of the specified variables will
    be returned so that all data values with the same index will correspond
    to the same case.

    dbname: str
        The name of the sqlite DB file.

    varnames: list[str]
        Iterator of names of variables to be retrieved.

    case_sql: str (optional)
        SQL syntax that will be placed in the WHERE clause for Case retrieval.

    var_sql: str (optional)
        SQL syntax that will be placed in the WHERE clause for variable retrieval.

    include_errors: bool (optional) [False]
        If True, include data from cases that reported an error.

    """
    connection = sqlite3.connect(dbname)
    vardict = dict([(name, []) for name in varnames])

    sql = ["SELECT id FROM cases"]
    qlist = []
    if case_sql:
        qlist.append(case_sql)
    if not include_errors:
        qlist.append("msg = ''")

    if qlist:
        sql.append("WHERE %s" % ' AND '.join(qlist))

    casecur = connection.cursor()
    casecur.execute(' '.join(sql))

    sql = ["SELECT name, value from casevars WHERE case_id=%s"]
    vars_added = False
    for i, name in enumerate(vardict.keys()):
        if i == 0:
            sql.append("AND (")
        else:
            sql.append("OR")
        sql.append(name % "name='%s'")
        vars_added = True
    if vars_added:
        sql.append(")")

    if var_sql:
        sql.append(" AND %s" % var_sql)
    combined = ' '.join(sql)

    varcur = connection.cursor()

    for case_id in casecur:
        casedict = {}
        varcur.execute(combined % case_id)
        for vname, value in varcur:
            if not isinstance(value, (float, int, str)):
                try:
                    value = loads(str(value))
                except UnpicklingError as err:
                    raise UnpicklingError("can't unpickle value '%s' from"
                                          " database: %s" % (vname, str(err)))
            casedict[vname] = value

        if len(casedict) != len(vardict):
            continue   # case doesn't contain a complete set of specified vars,
                       # so skip it to avoid data mismatches

        for name, value in casedict.items():
            vardict[name].append(value)

    return vardict
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.lib/src/openmdao/lib/casehandlers/dbcase.py/case_db_to_dict/swapped operands of `%`