Fix dictionary_id type error by removing COALESCE from prepared statement (v2.0.8)
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 34s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 34s
This commit is contained in:
@@ -903,7 +903,7 @@ func (a *App) addWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stmt, err := tx.Prepare(`
|
stmt, err := tx.Prepare(`
|
||||||
INSERT INTO words (name, translation, description, dictionary_id, user_id)
|
INSERT INTO words (name, translation, description, dictionary_id, user_id)
|
||||||
VALUES ($1, $2, $3, COALESCE($4, $5), $6)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -917,10 +917,8 @@ func (a *App) addWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
for i, wordReq := range req.Words {
|
for i, wordReq := range req.Words {
|
||||||
var id int
|
var id int
|
||||||
dictionaryID := defaultDictID
|
dictionaryID := defaultDictID
|
||||||
var dictIDParam interface{} = nil
|
|
||||||
if wordReq.DictionaryID != nil {
|
if wordReq.DictionaryID != nil {
|
||||||
dictionaryID = *wordReq.DictionaryID
|
dictionaryID = *wordReq.DictionaryID
|
||||||
dictIDParam = dictionaryID
|
|
||||||
// Проверяем, что словарь принадлежит пользователю
|
// Проверяем, что словарь принадлежит пользователю
|
||||||
var dictUserID int
|
var dictUserID int
|
||||||
err := tx.QueryRow(`
|
err := tx.QueryRow(`
|
||||||
@@ -941,7 +939,7 @@ func (a *App) addWordsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := stmt.QueryRow(wordReq.Name, wordReq.Translation, wordReq.Description, dictIDParam, dictionaryID, userID).Scan(&id)
|
err := stmt.QueryRow(wordReq.Name, wordReq.Translation, wordReq.Description, dictionaryID, userID).Scan(&id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error inserting word %d (name='%s', dict_id=%d, user_id=%d): %v", i, wordReq.Name, dictionaryID, userID, err)
|
log.Printf("Error inserting word %d (name='%s', dict_id=%d, user_id=%d): %v", i, wordReq.Name, dictionaryID, userID, err)
|
||||||
sendErrorWithCORS(w, err.Error(), http.StatusInternalServerError)
|
sendErrorWithCORS(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|||||||
Reference in New Issue
Block a user