func (Lstb *All_ball) SetFollowerBalls(curr_b *Ball, base *db.Env) {
	var idB int64
	base.Db.QueryRow("SELECT id FROM container WHERE ianix=$1;", curr_b.Id_ball).Scan(&idB)
	row, er := base.Db.Query("DELETE FROM followed WHERE container_id=$1", idB)
	if er != nil {
		Lstb.Logger.Println("Error on Delete followed: ", er)
	} else {
		defer row.Close()
	}
	for f := curr_b.Followers.Front(); f != nil; f = f.Next() {
		err := base.Transact(base.Db, func(tx *sql.Tx) error {
			stm, err := tx.Prepare("INSERT INTO followed(container_id, iduser) values($1,$2)")
			if err != nil {
				Lstb.Logger.Println(err)
				return err
			}
			defer stm.Close()
			_, err = stm.Exec(idB, f.Value.(*list.Element).Value.(*users.User).Id)
			if err != nil {
				Lstb.Logger.Println(err)
				return err
			}
			return nil
		})
		if err != nil {
			Lstb.Logger.Println(err)
		}
	}
}
func (ball *Ball) addMessage(base *db.Env) error {
	var idB int64
	base.Db.QueryRow("SELECT id FROM container WHERE ianix=$1;", ball.Id_ball).Scan(&idB)
	idMessageMax, er := getIdMessageMax(idB, base)
	if er != nil {
		return er
	}
	for f := ball.Messages.Front(); f != nil; f = f.Next() {
		mes := f.Value.(Message)
		if mes.Id > idMessageMax {
			err := base.Transact(base.Db, func(tx *sql.Tx) error {
				stm, err := tx.Prepare("INSERT INTO message(content, containerid, index_m, size) VALUES ($1, (SELECT id FROM container WHERE ianix=$2), $3, $4)")
				if err != nil {
					return err
				}
				defer stm.Close()
				_, err = stm.Exec(strings.Trim(mes.Content, "\x00"), ball.Id_ball, f.Value.(Message).Id, f.Value.(Message).Size)
				return err
			})
			if err != nil {
				return er
			}
		}
	}
	return nil
}
func (b *Ball) UpdateLocation(base *db.Env) error {
	var idB int64
	base.Db.QueryRow("SELECT id FROM container WHERE ianix=$1;", b.Id_ball).Scan(&idB)
	id := int64(0)
	if b.Possessed != nil {
		id = b.Possessed.Value.(*users.User).Id
	}

	err := base.Transact(base.Db, func(tx *sql.Tx) error {
		stm, err := tx.Prepare(" SELECT setdatacontainer($1, $2, $3, $4, $5, $6, $7, $8)")
		if err != nil {
			return err
		}
		defer stm.Close()
		_, err = stm.Exec(b.Wind.Degress, b.Wind.Speed, b.Coord.Value.(Checkpoint).Coord.Lat, b.Coord.Value.(Checkpoint).Coord.Lon, idB, id, b.Coord.Value.(Checkpoint).Date, b.Coord.Value.(Checkpoint).MagnetFlag)
		if err != nil {
			return err
		}
		return nil
	})
	if err != nil {
		return err
	}
	return nil
}
func (Lst_ball *All_ball) InsertMessages(messages *list.List, idBall int64, base *db.Env) (err error) {
	i := 0
	for e := messages.Front(); e != nil; e = e.Next() {
		err = base.Transact(base.Db, func(tx *sql.Tx) error {
			stm, err := tx.Prepare("INSERT INTO message(content, containerid, index_m, size) VALUES ($1, $2, $3, $4)")
			if err != nil {
				Lst_ball.Logger.Println("Erreur tx prepare: ", err)
				return err
			}
			defer stm.Close()
			row, err := stm.Query(sanit.Accents(strings.Trim(e.Value.(Message).Content, "\x00")), idBall, i, e.Value.(Message).Size)
			if err != nil {
				Lst_ball.Logger.Println("Erreur Query: ", err)
				return err
			}
			defer row.Close()
			i++
			return err
		})
	}
	return nil
}
func (Lb *All_ball) GetListBallsByUser(userE *list.Element, base *db.Env, Ulist *list.List) (lBallon *list.List, err error) {
	lBallon = list.New()
	err = nil

	err = base.Transact(base.Db, func(tx *sql.Tx) error {
		var errT error
		stm, errT := tx.Prepare("SELECT getcontainersbyuserid($1);")
		if errT != nil {
			Lb.Logger.Println(errT)
			return errT
		}
		defer stm.Close()
		rows, errT := stm.Query(userE.Value.(*users.User).Id)
		if errT != nil {
			Lb.Logger.Println(err)
			return errT
		}
		defer rows.Close()
		for rows.Next() {
			var infoCont string
			errT = rows.Scan(&infoCont)
			if errT != nil {
				Lb.Logger.Println(err)
				return errT
			}
			result := strings.Split(infoCont, ",")

			idBall := GetIdBall(result[0])
			magnet, _ := strconv.Atoi(result[8])
			tempCord := Lb.getExtraInfo(result[6], Lb.GetDateFormat(result[9]), int16(magnet))
			lstIt := list.New()
			sStat, errT := Lb.GetStatsBallon(int64(idBall), base.Db)
			if errT != nil {
				Lb.Logger.Println("GetStatsBallon: ", errT)
				return errT
			}
			possessed, errT := GetWhomGotBall(idBall, Ulist, base.Db)
			if errT != nil {
				Lb.Logger.Println("GetWhomGotBall error: ", errT)
				return errT
			}
			tmpBall := Lb.Get_ballbyid(GetIdBall(result[7]))
			if tmpBall != nil {
				// Do Nothing
			} else {
				lstMess, errT := Lb.GetMessagesBall(idBall, base.Db)
				if errT != nil {
					Lb.Logger.Println("GetMessageBall error: ", errT)
					return errT
				}
				lstFols, errT := Lb.GetFollowers(idBall, base.Db, Ulist)
				if errT != nil {
					Lb.Logger.Println("GetFollowers error: ", errT)
					return errT
				}
				tr := '"'
				lBallon.PushBack(
					&Ball{
						Id_ball:     GetIdBall(result[7]),
						Title:       strings.Trim(result[1], string(tr)),
						Date:        Lb.GetDateFormat(result[5]),
						Checkpoints: list.New(),
						Itinerary:   lstIt,
						Scoord:      tempCord.Front(),
						Coord:       tempCord.Front(),
						Wind:        GetWin(result[3], result[4]),
						Messages:    lstMess,
						Followers:   lstFols,
						Possessed:   possessed,
						Stats:       sStat,
						Creator:     userE})
			}
		}
		return errT
	})
	if err != nil {
		return nil, err
	}
	return lBallon, nil

}