CMDBuild Forum

Errore Postgres in: _cm_update_reference

Buongiorno, vorrei segnalarvi un bug che ho riscontrato in Cmdbuild 1.3.

Nella cancellazione di una relazione, a cui è associato un attributo di tipo reference, compare il seguente messaggio di errore (a livello Postgres)

An error has occurred:

ERROR:  syntax error at or near "NULL"
LINE 1: ...ULL WHERE "Status"='A' AND "Id" = 8556 AND serverIS NOT NULL
                                                                   ^
QUERY:  UPDATE upgrade SET server = NULL WHERE "Status"='A' AND "Id" = 8556 AND serverIS NOT NULL
CONTEXT:  PL/pgSQL function "_cm_update_reference" line 2 at EXECUTE statement
SQL statement "SELECT  _cm_update_reference( $1 ,  $2 ,  $3 ,  $4 )"
PL/pgSQL function "_cm_trigger_update_reference" line 37 at PERFORM
SQL statement "UPDATE "Map_upgrade_server" SET "Status" = 'N', "User" = 'admin' WHERE "Status" = 'A' AND "IdObj1" = 8556"
PL/pgSQL function "_cm_delete_relation" line 4 at EXECUTE statement
SQL statement "SELECT  _cm_delete_relation( $1 ,  $2 ,  $3 ,  $4 )"
PL/pgSQL function "_cm_trigger_update_relation" line 28 at PERFORM

Notare serverIS NOT NULL.

Ho identificato l'errore nella funzione _cm_update_reference; di seguito allego la versione che ho modificato.

CREATE FUNCTION _cm_update_reference(tableid oid, attributename text, cardid integer, referenceid integer) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    EXECUTE 'UPDATE ' || TableId::regclass ||
        ' SET ' || quote_ident(AttributeName) || ' = ' || coalesce(ReferenceId::text, 'NULL') ||
        ' WHERE "Status"=''A'' AND "Id" = ' || CardId::text ||
        ' AND ' || quote_ident(AttributeName) || coalesce(' <> ' || ReferenceId::text, ' IS NOT NULL');
END;
$$;

 

Notare lo spazio in ' IS NOT NULL'.

 

Vorrei sapere se la modifica è corretta e se l'errore verrà risolto nelle prossime versioni.

Salve, c’era effettivamente un bug in tale funzione nella release 1.3 per cui è stata modificata come segue nella patch release 1.3.0.1, già disponibile per il download

dal 13 gennaio.

CREATE OR REPLACE FUNCTION _cm_update_reference(TableId oid, AttributeName text, CardId integer, ReferenceId integer) RETURNS void AS $$
BEGIN
    EXECUTE 'UPDATE ' || TableId::regclass ||
        ' SET ' || quote_ident(AttributeName) || ' = ' || coalesce(ReferenceId::text, 'NULL') ||
        ' WHERE "Status"=''A'' AND "Id" = ' || CardId::text ||
        ' AND coalesce(' || quote_ident(AttributeName) || ', 0) <> ' || coalesce(ReferenceId, 0)::text;
END;
$$ LANGUAGE PLPGSQL;

L'aggiornamento alla 1.3.0.1 comprende anche una patch che provvede ad allineare i reference di tutte le relazioni dall'installazione della 1.3.

Grazie per la collaborazione.

Paolo