Приведение наименований в менеджере
Материал из wiki.standart-n.ru
Версия от 18:22, 12 августа 2016; Aleksnick (обсуждение | вклад)
Устанавливаем процедуру PR_GET_WARE.
SET TERM ^ ; create or alter procedure PR_INSTALL_PR_GET_WARE as declare variable IDX_U_EXISTS DM_STATUS; declare variable IDX_100_EXISTS DM_STATUS; declare variable GLOBAL_ID DM_STATUS; declare variable INDEX_NAME DM_TEXT; declare variable S DM_TEXT_BIG; declare variable FIELD DM_TEXT; begin if ((select upper(RF.RDB$FIELD_SOURCE) from RDB$RELATION_FIELDS RF where 1 = 1 and RF.RDB$FIELD_NAME = 'ID' and RF.RDB$RELATION_NAME = 'WARES') = 'DM_UUID') then GLOBAL_ID = 1; else GLOBAL_ID = 0; if ((select first 1 count(1) from RDB$INDICES RIN where RIN.RDB$INDEX_NAME = 'WARES_IDX_U' and RIN.RDB$RELATION_NAME = 'WARES') > 0) then IDX_U_EXISTS = 1; else IDX_U_EXISTS = 0; if (IDX_U_EXISTS = 1) then INDEX_NAME = 'WARES_IDX_U'; else INDEX_NAME = 'WARES_IDX1'; if ((select first 1 count(1) from RDB$INDICES RIN where RIN.RDB$INDEX_NAME = 'WARES_IDX100' and RIN.RDB$RELATION_NAME = 'WARES') > 0) then IDX_100_EXISTS = 1; else IDX_100_EXISTS = 0; S = ' create or alter procedure PR_GET_WARE ( SNAME type of DM_TEXT, SIZG type of DM_TEXT, SCOUNTRY type of DM_TEXT, ORIG_CODE type of DM_TEXT = '''', SORIG_NAME type of DM_TEXT = '''', SORIG_IZG type of DM_TEXT = '''', SORIG_COUNTRY type of DM_TEXT = '''', BARCODE type of DM_TEXT = '''', Z_ID type of DM_ID = 0, SKLAD_ID DM_TEXT = '''', ALTTYPE DM_STATUS = 0, MNN DM_TEXT = '''') returns ( '; if (GLOBAL_ID = 1) then S = S || 'W_ID type of DM_UUID_NULL)'; else S = S || 'W_ID type of DM_ID)'; S = S || ' as declare variable OLD_BARCODE DM_TEXT1024;'; if (GLOBAL_ID = 1) then S = S || ' declare variable NAME_ID type of DM_UUID_NULL; declare variable IZG_ID type of DM_UUID_NULL; declare variable COUNTRY_ID type of DM_UUID_NULL; declare variable ORIG_NAME_ID type of DM_UUID_NULL; declare variable ORIG_IZG_ID type of DM_UUID_NULL; declare variable ORIG_COUNTRY_ID type of DM_UUID_NULL; declare variable WHASH DM_ID; '; else S = S || ' declare variable NAME_ID type of DM_ID; declare variable IZG_ID type of DM_ID; declare variable COUNTRY_ID type of DM_ID; declare variable ORIG_NAME_ID type of DM_ID; declare variable ORIG_IZG_ID type of DM_ID; declare variable ORIG_COUNTRY_ID type of DM_ID; declare variable WHASH DM_ID; '; S = S || ' begin '; if (GLOBAL_ID = 1) then S = S || ' /* BASE WITH GLOBAL ID */ '; else S = S || ' /* BASE WITHOUT GLOBAL ID */ '; if (IDX_U_EXISTS = 1) then S = S || ' /* BASE WITH WARES_IDX_U */ '; else S = S || ' /* BASE WITHOUT WARES_IDX_U */ '; if (IDX_100_EXISTS = 1) then S = S || ' /* BASE WITH WARES_IDX100 */ '; else S = S || ' /* BASE WITHOUT WARES_IDX100 */ '; S = S || ' if (ORIG_CODE is null) then ORIG_CODE = ''''; select VAL_ID from PR_GETVAL_ID(:SNAME, 0, :ALTTYPE, :MNN) into :NAME_ID; select VAL_ID from PR_GETVAL_ID(:SIZG, 3, :ALTTYPE) into :IZG_ID; select VAL_ID from PR_GETVAL_ID(:SCOUNTRY, 2, :ALTTYPE) into :COUNTRY_ID; select VAL_ID from PR_GETVAL_ID(:SORIG_NAME, 1, :ALTTYPE) into :ORIG_NAME_ID; select VAL_ID from PR_GETVAL_ID(:SORIG_IZG, 6, :ALTTYPE) into :ORIG_IZG_ID; select VAL_ID from PR_GETVAL_ID(:SORIG_COUNTRY, 5, :ALTTYPE) into :ORIG_COUNTRY_ID; '; if (IDX_100_EXISTS = 0) then begin S = S || ' select ID, BARCODE from WARES where 1 = 1 '; select list('and ' || trim(RIS.RDB$FIELD_NAME) || ' = :' || trim(RIS.RDB$FIELD_NAME), ascii_char(13)) from RDB$INDEX_SEGMENTS RIS where RIS.RDB$INDEX_NAME = :INDEX_NAME into :FIELD; S = S || :FIELD || ' into :W_ID, :OLD_BARCODE; if (W_ID is null) then begin '; end else begin S = S || ' whash = ('; select list(':' || trim(RIS.RDB$FIELD_NAME), ',') from RDB$INDEX_SEGMENTS RIS where RIS.RDB$INDEX_NAME = :INDEX_NAME into :FIELD; S = S || :FIELD || ');'; S = S || ' select ID, BARCODE from WARES WHERE WHASH = :WHASH into :W_ID, :OLD_BARCODE; '; end if (GLOBAL_ID = 1) then S = S || ' W_ID = uuid_to_char(gen_uuid()); '; else S = S || ' W_ID = gen_id(GEN_WARES_ID, 1); '; S = S || ' insert into WARES (ID, NAME_ID, IZG_ID, COUNTRY_ID, ORIG_CODE, ORIG_NAME_ID, ORIG_IZG_ID, ORIG_COUNTRY_ID, BARCODE, Z_ID, SKLAD_ID) values (:W_ID, :NAME_ID, :IZG_ID, :COUNTRY_ID, :ORIG_CODE, :ORIG_NAME_ID, :ORIG_IZG_ID, :ORIG_COUNTRY_ID, :BARCODE, :Z_ID, :SKLAD_ID); end else if (OLD_BARCODE <> BARCODE) then update WARES set BARCODE = :BARCODE where ID = :W_ID; '; S = S || ' suspend; end '; execute statement(S); end^ SET TERM ; ^ /* Existing privileges on this procedure */ GRANT EXECUTE ON PROCEDURE PR_INSTALL_PR_GET_WARE TO SYSDBA; EXECUTE PROCEDURE PR_INSTALL_PR_GET_WARE; DROP PROCEDURE PR_INSTALL_PR_GET_WARE;