meeting-room-booking-system / mrbs-code

MRBS application code
Other
121 stars 59 forks source link

Getting a db error when editing a message #3680

Closed berkerY closed 3 months ago

berkerY commented 3 months ago

I get the following db error when editing a message:

Uncaught exception 'MRBS\DBException' in /srv/www/nginx_https/htdocs/mrbs_ulb_dev/web/lib/MRBS/DB.php at line 145
SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "mrbs_uq_variable_name"
DETAIL:  Key (variable_name)=(message) already exists.
SQL: INSERT INTO "public"."mrbs_variables"                        ("variable_name", "variable_content")                 VALUES (:p0, :p1) ON CONFLICT ("id") DO UPDATE SET "variable_name"=:p0, "variable_content"=:p1 RETURNING id
Params: Array
(
    [:p0] => message
    [:p1] => {"text":"Das ist eine Message f\u00fcr einen Raum.","from":"2024-06-05T00:00:00","until":"2024-06-07T00:00:00"}
)

#0 /srv/www/nginx_https/htdocs/mrbs_ulb_dev/web/lib/MRBS/Message.php(76): MRBS\DB->command('INSERT INTO "pu...', Array)
#1 /srv/www/nginx_https/htdocs/mrbs_ulb_dev/web/edit_message_handler.php(31): MRBS\Message->save()
#2 {main}
berkerY commented 3 months ago

it's already solved :) ... you should change the conflict parameter for upsert function in Message.php as follow:

public function save() : bool
  {
    ....
    $sql = db()->syntax_upsert($data, _tbl('variables'), $sql_params, **['variable_name']**, ['id'], true);
    ....
  }
berkerY commented 3 months ago

You may want to fix the bug first for your code and close this.

campbell-m commented 3 months ago

Thanks. Now fixed in 46bb4d4.