def _emit_insert_statements(base_mapper, uowtransaction,
                            cached_connections, mapper, table, insert):

    statement = base_mapper._memo(('insert', table), table.insert)

    for (connection, pkeys, hasvalue, has_all_pks, has_all_defaults), \
        records in groupby(insert,
                           lambda rec: (rec[4],
                                        list(rec[2].keys()),
                                        bool(rec[5]),
                                        rec[6], rec[7])
                           ):
        if \
                (
                    has_all_defaults
                    or not base_mapper.eager_defaults
                    or not connection.dialect.implicit_returning
                ) and has_all_pks and not hasvalue:

            records = list(records)
            multiparams = [rec[2] for rec in records]

            c = cached_connections[connection].\
                execute(statement, multiparams)

            for (state, state_dict, params, mapper_rec,
                    conn, value_params, has_all_pks, has_all_defaults), \
                    last_inserted_params in \
                    zip(records, c.context.compiled_parameters):
                _postfetch(
                    mapper_rec,
                    uowtransaction,
                    table,
                    state,
                    state_dict,
                    c,
                    last_inserted_params,
                    value_params)

        else:
            if not has_all_defaults and base_mapper.eager_defaults:
                statement = statement.return_defaults()
            elif mapper.version_id_col is not None:
                statement = statement.return_defaults(mapper.version_id_col)

            for state, state_dict, params, mapper_rec, \
                    connection, value_params, \
                    has_all_pks, has_all_defaults in records:

                if value_params:
                    result = connection.execute(
                        statement.values(value_params),
                        params)
                else:
                    result = cached_connections[connection].\
                        execute(statement, params)

                primary_key = result.context.inserted_primary_key

                if primary_key is not None:
                    # set primary key attributes
                    for pk, col in zip(primary_key,
                                       mapper._pks_by_table[table]):
                        prop = mapper_rec._columntoproperty[col]
                        if state_dict.get(prop.key) is None:
                            # TODO: would rather say:
                            # state_dict[prop.key] = pk
                            mapper_rec._set_state_attr_by_column(
                                state,
                                state_dict,
                                col, pk)

                _postfetch(
                    mapper_rec,
                    uowtransaction,
                    table,
                    state,
                    state_dict,
                    result,
                    result.context.compiled_parameters[0],
                    value_params)
Emit INSERT statements corresponding to value lists collected
dataset/ETHPy150Open RoseOu/flasky/venv/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py/_emit_insert_statements