I am working with Ubercart and am writing a module that does specialized order processing on all orders in a given day. I need to get the orders, their line items, their products, their customers (users), and other stuff, perhaps. and produce some specialized documentation used by our suppliers. Products are nodes, and have extended CCK attributes. Other tables are not.

Option 1
* select the orders needing processing using db_query()
* for each order
- find its line items, products, and user with separate db_query() calls, or load_node() for product since it's a node
- load all results into my own array of arrays, e.g. $orders_to_process[$order][$product] and so on
- do the needed work to create the specialized documentation
>> pros: easy, cons: multiple DB requests (e.g. 400 requests if we're processing 100 orders)

Option 2
* do a big join that selects all the items into a big flattened array
* write gnarly code to process
>> pros: single DB request, cons: gnarly

Option 3
* Use the magic Drupal feature or module that I haven't found yet :-)

So what say thee, gods and goddesses of Drupal? How should a simple knave like me proceed?

Thanks in advance!

Tom