Monday, 27 June 2011

Two tables combined display or maintain session.



Can we build a maintain or display session which works on 2 main tables?

Yes, we can and the answer is out here.

Every maintain or display session has four sets of queries to fetch the records from the database.
1) Query the first set.
2) Query the next set.
3) Query the previous set.
4) Query the last set.

These queries can be seen by pressing the key combination <Ctrl> <Shift> <8>.
Now how to modify it to make use of it to incorporate two or more tables.
All the above set of four queries have fixed sql ids linked to them (Like in case of dynamic Sql), we just need to assign the new query to them which make use of two or more tables.

The fixed Sql ids linked to above queries are:-
1) g.sql.first.id  for the first set.
2) g.sql.next.id  for the next set.
3) g.sql.prev.id  for the prev set.
4) g.sql.last.id  for the last set.
Just modify the queries like below:-

g.sql.first.id = sql.parse("select table1.*, table2.* from table1, table2 where <condition you like> order by <your choice>")

g.sql.first.id = sql.parse("select table1.*, table2.* from table1, table2 where <condition you like> order by <your choice> desc")

In case of display session it will work perfectly without any modification.
But in case of maintain session you will have to do some extra coding for assigning values and writing data of extra table to data base.(By using db.update, db.delete and db.insert without commit in main table io sections)

:) Just Modify these and enjoy!!!!!!!

1 comment: