<jsp:directive.page pageEncoding="UTF-8" />
<og:query command="{@command}" debug="{@debug}" maxRowCount="0">
	select	'1' as WRITABLE, UPPER(TABLE_NAME) AS TABLE_NAME,UPPER(CLM) AS CLM,NAME_JA,CLS_NAME,
			COALESCE(RENDERER,(CASE
						WHEN ( UPPER(CLM) LIKE 'CD%' OR UPPER(CLM) LIKE 'FG%' OR UPPER(CLM) LIKE 'KB%' )
							AND USE_LENGTH <= '2' THEN 'MENU'
						WHEN ( UPPER(CLM) LIKE 'DY%' ) THEN
							CASE WHEN USE_LENGTH = '6'  THEN 'YM'
								 WHEN USE_LENGTH = '8'  THEN 'YMD'
								 WHEN USE_LENGTH = '14' THEN 'YMDH'
							     ELSE 'TEXT'
							END
						ELSE 'LABEL'
						END)
			) AS RENDERER,
			COALESCE(EDITOR,(CASE
						WHEN ( UPPER(CLM) LIKE 'CD%' OR UPPER(CLM) LIKE 'FG%' OR UPPER(CLM) LIKE 'KB%' )
							AND USE_LENGTH <= '2' THEN 'MENU'
						WHEN ( UPPER(CLM) LIKE 'DY%' ) THEN
							CASE WHEN USE_LENGTH = '6'  THEN 'YM'
								 WHEN USE_LENGTH = '8'  THEN 'YMD'
								 WHEN USE_LENGTH = '14' THEN 'YMDH'
							     ELSE 'TEXT'
							END
						ELSE 'TEXT'
						END)
			) AS EDITOR,
			COALESCE(DBTYPE,(CASE 
						WHEN CLS_NAME in ( 'NUMBER','INTEGER' ) THEN 'S9'
						WHEN CLS_NAME LIKE 'VARCHAR%' THEN
							CASE WHEN to_number(USE_LENGTH)  <= 30   THEN 'X'
								 WHEN to_number(USE_LENGTH)  <= 100  THEN 'XK'
								 WHEN to_number(USE_LENGTH)  >  100  THEN 'KX'
							     ELSE 'X'
							END
						ELSE 'X'
						END)
			) AS DBTYPE, 
			CASE WHEN RENDERER LIKE '%DBMENU' THEN BIKO ELSE '' END AS RENDERER_PARAM ,
			CASE WHEN EDITOR   LIKE '%DBMENU' THEN '='  ELSE '' END AS EDITOR_PARAM ,
			VIEW_LENGTH,USE_LENGTH,DATA_DEFAULT,UNIQ,SYSTEM_ID,0 SEQ
	from GF05
	where SYSTEM_ID = '{@SYSTEM_ID_D}'
	and   TBLSYU    = '{@TBLSYU_D}'
	<og:where startKey="and">
		<og:and value="TABLE_NAME like '{@TABLE_NAME_D}'"	/>
		<og:and value="CLM        like '{@CLM_D}'"			/>
	</og:where>
	and   KBCLM		<= '7'
	and   FGJ       = '1'
	order by CLM,TABLE_NAME
</og:query>

<og:query command="{@command}" debug="{@debug}" dbid="{@DBID_R}" maxRowCount="0" scope="request">
	select '0' as WRITABLE, '' as TABLE_NAME,CLM,NAME_JA,CLS_NAME,
			RENDERER,EDITOR,DBTYPE, RENDERER_PARAM,EDITOR_PARAM,
			VIEW_LENGTH,USE_LENGTH,DATA_DEFAULT,UNIQ,SYSTEM_ID,0 SEQ
	from GEA03
	where SYSTEM_ID = '{@SYSTEM_ID_R}'
	<og:where startKey="and">
		<og:and value="CLM like '{@CLM_R}'" />
	</og:where>
	and   FGJ       = '1'
	ORDER BY SYSTEM_ID DESC, KBSAKU DESC, CLM
</og:query>

<og:tableMerge
	action        = "DIFFERENCE"
	masterScope   = "session"
	masterKeys    = "CLM"
	diffKeys      = "{@diffKeys11}"
	modifyClms    = "UNIQ"
	slaveScope    = "request"
	display       = "true"
/>

<og:value key="lblKey" value="C" />

<!-- UNIQ のみでユニークになるが、安全のため、SYSTEM_IDとCLMだけは条件に加えておく -->
<og:hidden name="SQL">
	UPDATE GEA03 SET
			NAME_JA			= [NAME_JA],
			CLS_NAME		= [CLS_NAME],
			RENDERER		= [RENDERER],
			EDITOR			= [EDITOR],
			DBTYPE			= [DBTYPE],
			RENDERER_PARAM	= [RENDERER_PARAM],
			EDITOR_PARAM	= [EDITOR_PARAM],
			VIEW_LENGTH		= [VIEW_LENGTH],
			USE_LENGTH		= [USE_LENGTH],
			DATA_DEFAULT	= [DATA_DEFAULT],
			DYUPD			= '{@USER.YMDH}',
			USRUPD			= '{@USER.ID}',
			PGUPD			= '{@GUI.KEY}'
	WHERE	UNIQ			= [UNIQ]
	AND		SYSTEM_ID		= '{@SYSTEM_ID_R}'
	AND		CLM				= [CLM]
</og:hidden>

<og:hidden name="SQL2">
	INSERT INTO GEA08
		(SYSTEM_ID,CLM,NAME_JA,LNAME,KBSAKU,KBLBL,LANG,
		 FGJ,DYSET,DYUPD,USRSET,USRUPD,PGUPD)
	VALUES
		('{@SYSTEM_ID_R}',[CLM],[NAME_JA],[NAME_JA],'1','1','ja',
		 '1','{@USER.YMDH}','{@USER.YMDH}','{@USER.ID}','{@USER.ID}','{@GUI.KEY}')
</og:hidden>

<!-- ラベルリソース(GEA08) をINSERT するので、既存のリソースを、削除(FGJ='9')する。 -->
<og:hidden name="SQLD2">
	UPDATE GEA08 SET
			FGJ		= '9',
			DYUPD	= '{@USER.YMDH}',
			USRUPD	= '{@USER.ID}',
			PGUPD	= '{@GUI.KEY}'
	WHERE	SYSTEM_ID	= '{@SYSTEM_ID_R}'
	AND		CLM			= [CLM]
	AND		LANG		= 'ja'
	AND		KBSAKU	!= '0'
</og:hidden>

<og:hidden name="DBID2" value="{@DBID_R}" />
