def iterVersionByName(self, name, withFlavors):
        cu = self.db.cursor()

        if withFlavors:
            flavorCol = "flavor"
            flavorClause = """INNER JOIN Flavors ON
                            Flavors.flavorId = Instances.flavorId"""
        else:
            flavorCol = "NULL"
            flavorClause = ""

        cu.execute("""SELECT DISTINCT version, timeStamps, %s
                        FROM Instances NATURAL JOIN Versions
                        %s
                        WHERE troveName='%s' AND isPresent=1"""
                            % (flavorCol, flavorClause, name))

        flavors = {}

        for (match, timeStamps, flavorStr) in cu:
            ts = [float(x) for x in timeStamps.split(':')]
            version = versions.VersionFromString(match, timeStamps=ts)

            if withFlavors:
                f = flavors.get(flavorStr, None)
                if f is None:
                    f = deps.deps.ThawFlavor(flavorStr)
                    flavors[flavorStr] = f

                yield (version, f)
            else:
                yield (version)