Beispiel #1
0
func (m mysqlProvider) grabInsertID(s schema, v value, b sq.InsertBuilder) (int64, error) {
	result, err := b.Exec()
	if err != nil {
		return 0, err
	}
	for _, pk := range s.xinfo.pk {
		f := s.fields[pk]
		if f.autoincr {
			id, _ := result.LastInsertId()
			v.field(f.Name).SetInt(id)
			break
		}
	}
	return result.RowsAffected()
}
Beispiel #2
0
func (p postgresProvider) grabInsertID(s schema, v value, b sq.InsertBuilder) (int64, error) {
	for _, pk := range s.xinfo.pk {
		f := s.fields[pk]
		if f.autoincr {
			var id int64
			row := b.Suffix(fmt.Sprintf("RETURNING \"%s\"", pk)).QueryRow()
			if err := row.Scan(&id); err != nil {
				return 0, err
			}
			v.field(f.Name).SetInt(id)
			return 1, nil
		}
	}

	result, err := b.Exec()
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}