I would like some help in SQLJ (yes...). I'm googling how to reproduce a recursive SQL query in this inline-java SQL. References are also welcome, because it has being really hard to find also...
My SQL query:
WITH attachedemails(id, subject, filename)
AS (
-- Ancora (224)
SELECT email
FROM (SELECT addressee.email AS email
FROM addressee
WHERE addressee.email->from
IN (SELECT address
FROM use
WHERE use.user->nickname = User.nickname <arg>)
UNION
SELECT addressee.email
FROM addressee
WHERE addressee.to
IN (SELECT address
FROM use
WHERE use.user->nickname = = User.nickname <arg>)))
AS t
WHERE email->DATE >= FROM <arg> AND email->DATE <= TO <arg> )
UNION ALL
SELECT m.id
FROM email AS m,
attachedemails AS c
WHERE m.contained_in = c.id
AND m.DATE >= FROM <arg> AND email->DATE <= TO <arg> ))
Basically, I'm getting all emails from some given user and email attached in other emails. I marked with my Java arguments, which I should use to filter the results.
I'm aware that in order to return multiple rows using SQLJ we need a iterator, and that I can different levels of them in subqueries, but recursion is being extremely hard to simulate. Maybe there is some other kind of construction specifically for SQLJ that I'm not aware. I hope someone can help!