Answer the question
In order to leave comments, you need to log in
Why do I have after Update, Select returns the old data?
//session /ответ
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
msg := obj.Message.Text
//prefix
startWith := "/ответ"
//check prefix
starts := strings.HasPrefix(msg, startWith)
if starts == true {
//trim message
res_trim := strings.Trim(msg, "/ответ ")
//check empty text
if res_trim != "" {
//search note in table where asker -> answer = ask_id
res_search_active_ask, err100 := db.Query(fmt.Sprintf("SELECT `asker`, `answer`, `closed` FROM `ucp` WHERE `closed` = '0' AND (`asker` = '%d' OR `answer` = '%d')", msg_from_id))
if err100 != nil {
panic(err100)
}
for res_search_active_ask.Next(){
err := res_search_active_ask.Scan(&ucp.Asker, &ucp.Answer, &ucp.Closed)
if err != nil {
panic(err)
}
}
if ucp.Closed == 0 {
if msg_from_id == ucp.Answer {
session_message_redirect, err11 := vk.MessagesSend(api.Params{
"peer_id": ucp.Asker,
"random_id": 0,
"message": assistant + res_trim,
})
//err check
if err11 != nil {
panic(err11)
}
spew.Dump(session_message_redirect)
}else{
session_message_redirect2, err112 := vk.MessagesSend(api.Params{
"peer_id": msg_from_id,
"random_id": 0,
"message": error_assistant_havent_ask,
})
//err check
if err112 != nil {
panic(err112)
}
spew.Dump(session_message_redirect2)
}
}else{
session_message_redirect3, err1123 := vk.MessagesSend(api.Params{
"peer_id": msg_from_id,
"random_id": 0,
"message": error_user_havent_ask,
})
//err check
if err1123 != nil {
panic(err1123)
}
spew.Dump(session_message_redirect3)
}
}
}
})
//close ask
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
msg := obj.Message.Text
//prefix
startWith := "/close"
//cheack prefix
starts := strings.HasPrefix(msg, startWith)
if starts == true {
//trim message
res_trim := strings.Trim(msg, "/close ")
//cheack empty text
if res_trim != "" {
res_answer_active_status, err35 := db.Query(fmt.Sprintf("SELECT `answer`, `asker`, `closed` FROM `ucp` WHERE `closed` = '0' AND (`answer` = '%d' OR `asker` = '%d')", msg_from_id))
if err35 != nil {
panic(err35)
}
for res_answer_active_status.Next() {
err36 := res_answer_active_status.Scan(&ucp.Answer, &ucp.Asker, &ucp.Closed)
if err36 != nil {
panic(err36)
}
}
if ucp.Closed == 0 {
if msg_from_id == ucp.Answer || msg_from_id == ucp.Asker {
//revers string to int for req
res_trim_int, err34 := strconv.Atoi(res_trim)
if err34 != nil {
panic(err34)
}
// update answer id
update_answer_id_start, err33 := db.Query(fmt.Sprintf("UPDATE `ucp` SET `closed` = '1' WHERE `id` = '%d'", res_trim_int))
if err33 != nil {
panic(err33)
}
defer update_answer_id_start.Close()
//send message
send, err := vk.MessagesSend(api.Params{
"peer_id": msg_from_id,
"random_id": 0,
"message": closed_ask + res_trim,
})
if err != nil {
panic(err)
}
spew.Dump(send)
spew.Dump(update_answer_id_start)
}else{
send, err := vk.MessagesSend(api.Params{
"peer_id": msg_from_id,
"random_id": 0,
"message": "ERROR: You havenot active ask.",
})
if err != nil {
panic(err)
}
spew.Dump(send)
}
}else{
session_message_redirect3, err1123 := vk.MessagesSend(api.Params{
"peer_id": msg_from_id,
"random_id": 0,
"message": error_user_havent_ask,
})
//err check
if err1123 != nil {
panic(err1123)
}
spew.Dump(session_message_redirect3)
}
}
}
})
Answer the question
In order to leave comments, you need to log in
The problem is in this section, Query is used to retrieve data, you need to use Exec to change
update_answer_id_start, err33 := db.Query(fmt.Sprintf("UPDATE `ucp` SET `closed` = '1' WHERE `id` = '%d'", res_trim_int))
defer update_answer_id_start.Close()
update_answer_id_start, err33 := db.Exec("UPDATE `ucp` SET `closed` = '1' WHERE `id` = ?", res_trim_int)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question