def _next_case(self):
        """ Generator which returns Cases one at a time. """
        # figure out which selectors are for cases and which are for variables
        sql = ["SELECT * FROM cases"]
        if self.selectors is not None:
            for sel in self.selectors:
                rhs, rel, lhs = _query_split(sel)
                if rhs in _casetable_attrs:
                    if len(sql) == 1:
                        sql.append("WHERE %s%s%s" % (rhs, rel, lhs))
                    else:
                        sql.append("AND %s%s%s" % (rhs, rel, lhs))

        casecur = self._connection.cursor()
        casecur.execute(' '.join(sql))

        sql = ['SELECT var_id,name,case_id,sense,value from casevars WHERE case_id=%s']
        if self.selectors is not None:
            for sel in self.selectors:
                rhs, rel, lhs = _query_split(sel)
                if rhs in _vartable_attrs:
                    sql.append("AND %s%s%s" % (rhs, rel, lhs))
        combined = ' '.join(sql)
        varcur = self._connection.cursor()

        for cid, text_id, parent, msg, model_id, timeEnter in casecur:
            varcur.execute(combined % cid)
            inputs = []
            outputs = []
            for var_id, vname, case_id, sense, value in varcur:
                if isinstance(value, (float, int, str)):
                    pass
                elif value is None:  # Result when recorded value was NaN.
                    value = float('NaN')
                else:
                    try:
                        value = loads(str(value))
                    except UnpicklingError as err:
                        print 'value', type(value), repr(value)
                        raise UnpicklingError("can't unpickle value '%s' for"
                                              " case '%s' from database: %s"
                                              % (vname, text_id, str(err)))
                if sense == 'i':
                    inputs.append((vname, value))
                elif sense == 'o':
                    outputs.append((vname, value))
            if len(inputs) > 0 or len(outputs) > 0:
                exc = Exception(msg) if msg else None
                yield Case(inputs=inputs, outputs=outputs, exc=exc,
                           case_uuid=text_id, parent_uuid=parent)
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.lib/src/openmdao/lib/casehandlers/dbcase.py/DBCaseIterator._next_case/original