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(`
|
||||
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
|
||||
`)
|
||||
if err != nil {
|
||||
@@ -917,10 +917,8 @@ func (a *App) addWordsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
for i, wordReq := range req.Words {
|
||||
var id int
|
||||
dictionaryID := defaultDictID
|
||||
var dictIDParam interface{} = nil
|
||||
if wordReq.DictionaryID != nil {
|
||||
dictionaryID = *wordReq.DictionaryID
|
||||
dictIDParam = dictionaryID
|
||||
// Проверяем, что словарь принадлежит пользователю
|
||||
var dictUserID int
|
||||
err := tx.QueryRow(`
|
||||
@@ -941,7 +939,7 @@ func (a *App) addWordsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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 {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user