How to load Ubercart orders for certain user ID? How to load Ubercart orders for certain user ID programatically?

There is only uc_order_history() which returns formatted order table and does not work in that case.
Find the following function in Drupal 7:

/**
 * Custom function to return list of orders for certain user
 */
function foo_get_user_orders($user, $order_status = 'completed') {
  $query = db_select('uc_orders', 'uo');
  $query-&gt;addField('uo', 'order_id');
  $query-&gt;addField('uo', 'order_total');
  $query-&gt;addField('uo', 'order_status'); // optional: $query-&gt;addField('uo', 'product_count');
  $query-&gt;addJoin('LEFT', 'uc_order_products', 'p', 'p.order_id = uo.order_id');
  $query-&gt;addField('p', 'nid');
  $query-&gt;condition('order_status', $order_status);
  $query-&gt;condition('uid', $user-&gt;uid);
  $result = $query-&gt;execute()-&gt;fetchAll();
  return $result;
}


For Drupal 6, please install dbtng module and it should work as well.