0

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!

AngocA
  • 7,655
  • 6
  • 39
  • 55
Pedro Dusso
  • 2,100
  • 9
  • 34
  • 64
  • [SQLJ looks pretty dead?](http://en.wikipedia.org/wiki/SQLJ) But if it just passes the query to the database, it could use whatever feature the underlying database has. – Andomar May 05 '13 at 18:20
  • Yes, I know... not our choice, grad project. I will try if the whole query – Pedro Dusso May 06 '13 at 07:40

0 Answers0