text: --------------------------------------------------------------------------------
  -- CreateProgram ---------------------------------------------------------------
  --------------------------------------------------------------------------------
  /**
   * Создаёт программу
   * @param {uuid} pParent - Идентификатор объекта родителя
   * @param {uuid} pType - Идентификатор типа
   * @param {text} pCode - Код
   * @param {text} pName - Наименование
   * @param {text} pBody - Тело
   * @param {text} pDescription - Описание
   * @return {uuid}
   */
  CREATE OR REPLACE FUNCTION CreateProgram (
    pParent       uuid,
    pType         uuid,
    pCode         text,
    pName         text,
    pBody         text,
    pDescription	text default null
  ) RETURNS       uuid
  AS $$
  DECLARE
    uReference	uuid;
    uClass        uuid;
    uMethod       uuid;
  BEGIN
    SELECT class INTO uClass FROM db.type WHERE id = pType;
  
    IF GetEntityCode(uClass) <> 'program' THEN
      PERFORM IncorrectClassType();
    END IF;
  
    uReference := CreateReference(pParent, pType, pCode, pName, pDescription);
  
    INSERT INTO db.program (reference, body)
    VALUES (uReference, pBody);
  
    uMethod := GetMethod(uClass, GetAction('create'));
    PERFORM ExecuteMethod(uReference, uMethod);
  
    RETURN uReference;
  END;
  $$ LANGUAGE plpgsql
     SECURITY DEFINER
     SET search_path = kernel, pg_temp;
  
  --------------------------------------------------------------------------------
  -- EditProgram -----------------------------------------------------------------
  --------------------------------------------------------------------------------
  /**
   * Редактирует агента
   * @param {uuid} pId - Идентификатор
   * @param {uuid} pParent - Идентификатор объекта родителя
   * @param {uuid} pType - Идентификатор типа
   * @param {text} pCode - Код
   * @param {text} pName - Наименование
   * @param {text} pBody - Тело
   * @param {text} pDescription - Описание
   * @return {void}
   */
  CREATE OR REPLACE FUNCTION EditProgram (
    pId           uuid,
    pParent       uuid default null,
    pType         uuid default null,
    pCode         text default null,
    pName         text default null,
    pBody         text default null,
    pDescription	text default null
  ) RETURNS       void
  AS $$
  DECLARE
    uClass        uuid;
    uMethod       uuid;
  BEGIN
    PERFORM EditReference(pId, pParent, pType, pCode, pName, pDescription, current_locale());
  
    UPDATE db.program
       SET body = coalesce(pBody, body)
     WHERE id = pId;
  
    SELECT class INTO uClass FROM db.object WHERE id = pId;
  
    uMethod := GetMethod(uClass, GetAction('edit'));
    PERFORM ExecuteMethod(pId, uMethod);
  END;
  $$ LANGUAGE plpgsql
     SECURITY DEFINER
     SET search_path = kernel, pg_temp;
  
  --------------------------------------------------------------------------------
  -- FUNCTION GetProgram ---------------------------------------------------------
  --------------------------------------------------------------------------------
  
  CREATE OR REPLACE FUNCTION GetProgram (
    pCode		text
  ) RETURNS 	uuid
  AS $$
  BEGIN
    RETURN GetReference(pCode, 'program');
  END;
  $$ LANGUAGE plpgsql
     SECURITY DEFINER
     SET search_path = kernel, pg_temp;
  
  --------------------------------------------------------------------------------
  -- FUNCTION GetProgramBody -----------------------------------------------------
  --------------------------------------------------------------------------------
  
  CREATE OR REPLACE FUNCTION GetProgramBody (
    pId       uuid
  ) RETURNS 	text
  AS $$
    SELECT body FROM db.program WHERE id = pId;
  $$ LANGUAGE SQL
     SECURITY DEFINER
     SET search_path = kernel, pg_temp;
  