-- 出品者情報、出品者用ページ
CREATE OR REPLACE FUNCTION f_seller_infomation_update(
    IN integer,
    IN integer,

    IN character varying,

    IN character varying,
    IN character varying,
    IN integer,

    OUT errcd integer,
    OUT errmsg character varying,
    OUT code integer) AS
$$

DECLARE
    kubun ALIAS FOR $1;                  -- 区分
    i_membercd ALIAS FOR $2;                  -- 会員コード

    i_infomation ALIAS FOR $3;               -- 出品者用ページHTML

    i_updusrnm ALIAS FOR $4;             -- 更新ユーザー名
    i_updpcnm ALIAS FOR $5;              -- 更新マシン名
    i_updcnt ALIAS FOR $6;               -- UpdCnt

    cntcheck integer;
    nowdate timestamp;
    newupdcnt integer;

BEGIN
-- 必須チェック --

    IF kubun IS NULL OR kubun NOT IN (2) THEN
        RAISE EXCEPTION '処理区分が不正です';
    END IF;

    IF i_updusrnm IS NULL THEN
        RAISE EXCEPTION '更新ユーザー名は必須です';
    END IF;
    IF i_updpcnm IS NULL THEN
        RAISE EXCEPTION '更新PC名は必須です';
    END IF;
    IF i_updcnt IS NULL THEN
        RAISE EXCEPTION 'UpdCntは必須です';
    END IF;

    -- 更新カウンタチェック
    IF kubun IN (2) THEN
        SELECT updcnt INTO cntcheck FROM t_seller_attr WHERE membercd=i_membercd;
          IF NOT FOUND OR cntcheck <> i_updcnt THEN
            RAISE EXCEPTION '更新カウンタが不正です';
          END IF;
    END IF;

    --- 更新処理 ---
     IF kubun = 2 THEN
        UPDATE t_seller_attr SET
            infomation     = i_infomation,
            upddate      = nowdate,
            updusrnm     = i_updusrnm,
            updpcnm      = i_updpcnm
            WHERE membercd=i_membercd;
    END IF;

    code := 1;

END;
$$
LANGUAGE 'plpgsql' VOLATILE;
