コード例 #1
0
ファイル: expression.php プロジェクト: yunsite/mapleleaf
 function getFilteredResultSet(&$resultSet)
 {
     global $g_sqlComparisonOperators;
     for ($i = 0; $i < $this->getChildCount(); ++$i) {
         $child = $this->childs[$i];
         $this->resultSetsFromChilds[] = $child->getFilteredResultSet($resultSet);
     }
     $sp = new StringParser();
     //$or_expr=explode_resp_quotes(" OR ",$this->expr_str);
     $sp->setConfig(array("'", "\""), "\\", array(), array(" OR "), false, false);
     $sp->setString($this->expr_str);
     $or_expr = $sp->splitWithSpecialElements();
     $andResultSets = array();
     for ($i = 0; $i < count($or_expr); ++$i) {
         $fieldValuePair = array();
         $fields = array();
         $values = array();
         $operators = array();
         $childsToInclude = 0;
         //$and_expr=explode_resp_quotes(" AND ",$or_expr[$i]);
         $sp->setConfig(array("'", "\""), "\\", array(), array(" AND "), false, false);
         $sp->setString($or_expr[$i]);
         $and_expr = $sp->splitWithSpecialElements();
         array_walk($and_expr, "array_walk_trim");
         for ($j = 0; $j < count($and_expr); ++$j) {
             if ($and_expr[$j] == "%") {
                 $childsToInclude++;
             } else {
                 //$operators[]=explode_resp_quotes_multisep($g_sqlComparisonOperators,$and_expr[$j],$fieldValuePair);
                 $usedOps = array();
                 $sp->setConfig(array("'", "\""), "\\", array(), $g_sqlComparisonOperators, false, false);
                 $sp->setString($and_expr[$j]);
                 $fieldValuePair = $sp->splitWithSpecialElementsRetUsed($usedOps);
                 $operators[] = trim($usedOps[0]);
                 // Remove escape chars (because parseNextElementRaw() was used
                 // to parse Where Statements)
                 list($field, $value) = $fieldValuePair;
                 $fields[] = stripslashes(trim($field));
                 // like bugfix: don't remove escape chars on the LIKE value
                 if (strtoupper(trim($operators[count($operators) - 1])) == "LIKE") {
                     $values[] = trim($value);
                 } else {
                     $values[] = stripslashes(trim($value));
                 }
             }
         }
         if (TXTDBAPI_DEBUG) {
             echo "<br>fields and values to use for AND filter:<br>";
             print_r($fields);
             echo "<br>";
             print_r($values);
             echo "<br>";
             print_r($operators);
             echo "<br>";
             echo "childsToInclude:  " . $childsToInclude . "<br>";
         }
         $andResultSets[] = $resultSet->filterRowsByAndConditions($fields, $values, $operators);
         debug_print("filterRowsByAndConditions done<br>");
         for ($j = 0; $j < $childsToInclude; ++$j) {
             $andResultSets[$i]->filterResultSetAndWithAnother($this->resultSetsFromChilds[$this->childResultSetPos++]);
         }
         if (TXTDBAPI_DEBUG) {
             echo "Filtered ResultSet:<br>";
             $andResultSets[$i]->dump();
         }
     }
     $finalResultSet = $andResultSets[0];
     for ($i = 1; $i < count($andResultSets); ++$i) {
         $andResultSets[$i]->reset();
         while ($andResultSets[$i]->next()) {
             $finalResultSet->appendRow($andResultSets[$i]->getCurrentValues(), $andResultSets[$i]->getCurrentRowId());
         }
     }
     if (TXTDBAPI_DEBUG) {
         echo "<br><br>FINAL RESULT SET:<br>";
         $finalResultSet->dump();
     }
     return $finalResultSet;
 }