I've done a similar query for DB2 that fits our needs.
The ELT and FIELD MySQL functions has a difficult translation to DB2. I've used CASE-WHEN and POSITION respectively.
For POSITION I only use the Types that we are used to use. Feel free to add the ones that you need (see DB2 documentation)
For the ones that lacks, I use a Spanish expression ('puaj') in order to make Roo to fail.
I am not a DB2 expert (and it seems I'm not a good programmer either), so you will find extra whitespaces and maybe some other errors.
WHERE TBNAME = 'TABLE' is what you need to change (maybe you need permissions to read SYSIBM.SYSCOLUMNS, but I have no problems with that)
Here it is:
Code:
select
concat(
concat(
concat(
concat(
concat(
concat(
'field '
,
CASE
POSITION(
RTRIM(COLTYPE),'INTEGERSMALLINTFLOATCHARVARCHARDECIMALDATETIMETIMESTMP',CODEUNITS16
)
WHEN 1 THEN 'number'
WHEN 8 THEN 'number'
WHEN 16 THEN 'number'
WHEN 21 THEN 'string'
WHEN 25 THEN 'string'
WHEN 32 THEN 'number'
WHEN 39 THEN 'date'
WHEN 43 THEN 'date'
WHEN 47 THEN 'date'
ELSE 'puaj'
END
)
,
concat(' --fieldName ',LOWER(RTRIM(NAME)))
)
,
COALESCE(NULLIF(COALESCE(NULLIF(NULLS,'N'),' --notNull '), 'Y'), ' ')
)
,
CASE
POSITION(
RTRIM(COLTYPE),'CHARVARCHAR',CODEUNITS16
)
WHEN 1 THEN concat(concat(' --sizeMax ',CHAR(LENGTH)),' ')
WHEN 5 THEN concat(concat(' --sizeMax ',CHAR(LENGTH)),' ')
ELSE ' '
END
)
,
CASE
POSITION(
RTRIM(COLTYPE),'INTEGERSMALLINTFLOATCHARVARCHARDECIMALDATETIMETIMESTMP',CODEUNITS16
)
WHEN 1 THEN ' --type java.lang.Integer '
WHEN 8 THEN ' --type java.lang.Integer '
WHEN 16 THEN ' --type java.lang.Integer '
WHEN 21 THEN ' --type java.lang.String '
WHEN 25 THEN ' --type java.lang.String '
WHEN 32 THEN ' --type java.lang.Float '
WHEN 39 THEN ' --type java.util.Date '
WHEN 43 THEN ' --type java.util.Date '
WHEN 47 THEN ' --type java.util.Date '
ELSE 'puaj'
END
)
,
concat(' --column ',RTRIM(NAME))
)
from SYSIBM.SYSCOLUMNS cols
WHERE
TBNAME = 'TABLE'
AND TBCREATOR = 'GRUDES'