*** nodehierarchy_widgets.module.orig	2012-03-20 15:24:57.866909720 -0400
--- nodehierarchy_widgets.module	2012-03-20 15:44:45.635220004 -0400
***************
*** 93,99 ****
    if ($types) {
      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query(
!                         "SELECT n.nid, n.type as type, n.title as title, ml.*, IF(depth IS NULL, 1, depth) as depth, IF(ml.mlid IS NULL, CONCAT('nid:', n.nid), ml.mlid) as mlid, ml.mlid as linkid
                             FROM {node} n
                        LEFT JOIN {nodehierarchy_menu_links} nh_parent
                               ON nh_parent.nid = n.nid
--- 93,103 ----
    if ($types) {
      // TODO Please convert this statement to the D7 database API syntax.
      $result = db_query(
!                         "SELECT n.nid, n.type as type, n.title as title, ml.*, 
!                               CASE WHEN depth IS NULL THEN 1 ELSE depth END as depth, 
!                               CASE WHEN ml.mlid IS NULL THEN CONCAT('nid:', n.nid) ELSE cast (ml.mlid as char) END as mlid, 
!                               CASE WHEN p1 IS NULL THEN n.created ELSE 0 END AS pord,
!                               ml.mlid as linkid
                             FROM {node} n
                        LEFT JOIN {nodehierarchy_menu_links} nh_parent
                               ON nh_parent.nid = n.nid
***************
*** 102,108 ****
                            WHERE (ml.module = 'nodehierarchy' OR ml.module IS NULL)
                              AND n.type IN (" . implode(', ', $types) . ")
                              AND LOWER(n.title) LIKE :title
!                           ORDER BY IF(p1 IS NULL, n.created, 0) ASC, p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC",
                          array('title' => '%' . db_like(strtolower($string)) . '%'),
                          array('fetch' => PDO::FETCH_ASSOC)
                      );
--- 106,112 ----
                            WHERE (ml.module = 'nodehierarchy' OR ml.module IS NULL)
                              AND n.type IN (" . implode(', ', $types) . ")
                              AND LOWER(n.title) LIKE :title
!                           ORDER BY pord ASC, p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC",
                          array('title' => '%' . db_like(strtolower($string)) . '%'),
                          array('fetch' => PDO::FETCH_ASSOC)
                      );
