Ignore:
Timestamp:
05/15/13 16:17:00 (12 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge SQL changes and other miscellaneous fixes from /trunk through r553.

Location:
branches/stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/cgi-bin/search.cgi

    r593 r594  
    146146  my $cols = "cidr,custid,type,city,description";
    147147
     148  # hack fix for undefined variables
     149  $webvar{custid} = '' if !$webvar{custid};
     150  $webvar{desc}   = '' if !$webvar{desc};
     151  $webvar{notes}  = '' if !$webvar{notes};
     152  $webvar{custexclude}  = '' if !$webvar{custexclude};
     153  $webvar{descexclude}  = '' if !$webvar{descexclude};
     154  $webvar{notesexclude} = '' if !$webvar{notesexclude};
     155
    148156  # First chunk of SQL.  Filter on custid, description, and notes as necessary.
    149   my $sql = "(select $cols from searchme where".
    150         " $webvar{custexclude} (custid ilike '%$webvar{custid}%'".
    151         " $sqlconcat (select $cols from searchme where $webvar{descexclude} description ilike '%$webvar{desc}%')".
    152         " $sqlconcat (select $cols from searchme where $webvar{notesexclude} notes ilike '%$webvar{notes}%')";
     157  my $sql = qq(SELECT $cols FROM searchme\n);
     158  $sql .= " WHERE $webvar{custexclude} (custid ~ '$webvar{custid}')\n";
     159  $sql .= " $sqlconcat (select $cols from searchme where $webvar{descexclude} description ~ '$webvar{desc}')\n";
     160  $sql .= " $sqlconcat (select $cols from searchme where $webvar{notesexclude} notes ~ '$webvar{notes}')";
    153161
    154162  # If we're not supposed to search for all types, search for the selected types.
     163  $webvar{alltypes} = '' if !$webvar{alltypes};
     164  $webvar{typeexclude} = '' if !$webvar{typeexclude};
    155165  if ($webvar{alltypes} ne 'on') {
    156166    $sql .= " $sqlconcat (select $cols from searchme where $webvar{typeexclude} type in (";
     
    164174  # If we're not supposed to search for all cities, search for the selected cities.
    165175  # This could be vastly improved with proper foreign keys in the database.
     176  $webvar{allcities} = '' if !$webvar{allcities};
     177  $webvar{cityexclude} = '' if !$webvar{cityexclude};
    166178  if ($webvar{allcities} ne 'on') {
    167179    $sql .= " $sqlconcat (select $cols from searchme where $webvar{cityexclude} city in (";
     
    315327# Creates appropriate SQL to run the search and display the results
    316328# with queryResults()
    317 sub viewBy($$) {
     329sub viewBy {
    318330  my ($category,$query) = @_;
    319331
     
    445457# Display search queries based on the passed SQL.
    446458# Takes SQL, page number (for multipage search results), and a total count.
    447 sub queryResults($$$) {
     459sub queryResults {
    448460  my ($sql, $pageNo, $rowCount) = @_;
    449461  my $offset = 0;
     
    529541# Return count of rows to be returned in a "real" query
    530542# with the passed SQL statement
    531 sub countRows($) {
     543sub countRows {
    532544  # Note that the "as foo" is required
    533545  my $sth = $ip_dbh->prepare("select count(*) from ($_[0]) as foo");
Note: See TracChangeset for help on using the changeset viewer.