addClause() public method

public addClause ( $type )
Ejemplo n.º 1
0
 function test_5_negate()
 {
     $where = new WhereClause('and');
     $where->add('password=%s', 'hello');
     $subclause = $where->addClause('or');
     $subclause->add('username!=%s', 'Bart');
     $subclause->negate();
     $result = DB::query("SELECT * FROM accounts WHERE %l", $where);
     $this->assert(count($result) === 1);
     $this->assert($result[0]['age'] === '15');
 }
Ejemplo n.º 2
0
        }
    }
    $sOrder = substr_replace($sOrder, "", -2);
    if ($sOrder == "ORDER BY") {
        $sOrder = "";
    }
}
/*
   * Filtering
   * NOTE this does not match the built-in DataTables filtering which does it
   * word by word on any field. It's possible to do here, but concerned about efficiency
   * on very large tables, and MySQL's regex functionality is very limited
*/
if ($_GET['sSearch'] != "") {
    //$sWhere .= " AND ";
    $subclause = $where->addClause('or');
    for ($i = 0; $i < count($aColumns); $i++) {
        $subclause->add($aColumns[$i] . " LIKE %ls", $_GET['sSearch']);
    }
}
// Do NOT show the items in PERSONAL FOLDERS
if (!empty($list_pf)) {
    $where->add('id_tree NOT IN %ls', $list_pf);
}
$rows = DB::query("SELECT * FROM " . $pre . "cache WHERE %l " . $sOrder . " " . $sLimit, $where);
$iFilteredTotal = DB::count();
DB::query("SELECT * FROM " . $pre . "cache");
$iTotal = DB::count();
/*
   * Output
*/
Ejemplo n.º 3
0
 public function addRand($QParts, $Subjects, $QTypes, $num)
 {
     //arrays of the numbers to include eg subj [0,1,4] for b,c,e
     global $MARK_AS_BAD_THRESHOLD, $ruleSet, $MAX_NUMQS, $DEFAULT_NUMQS;
     $num = normRange($num, 1, $MAX_NUMQS, $DEFAULT_NUMQS);
     $where = new WhereClause('and');
     $where->add('MarkBad<%i', $MARK_AS_BAD_THRESHOLD);
     $where->add('Deleted=0');
     $db = array("isB", "Subject", "isSA");
     foreach (array("QParts", "Subjects", "QTypes") as $i => $name) {
         if (!val('*i+', $indices = eval('$' . $name . ';'))) {
             continue;
         }
         //Fetches and verifies array of index values that the user may want.
         $indices = array_values(array_unique($indices));
         //Eliminates stupidity
         $sub = $where->addClause('or');
         foreach ($indices as $index) {
             if (inRange($index, 0, count($ruleSet[$name]) - 1)) {
                 //Make sure the index is correct.
                 $sub->add('%b=%i', $db[$i], $index);
             }
         }
         //Inserts the index into the proper DB field
     }
     $qresult = DB::queryRaw("SELECT * FROM questions WHERE %l ORDER BY TimesViewed ASC, " . SQLRAND('QID') . " LIMIT %i", $where, $num);
     //Order by TimesViewed, and then randomize within each TimesViewed value.
     //NOTE: TimesViewed is despite categories, and if you have something like 2 10 10 10, you'll get the 2 at least 8 times in a row.
     //The assumption that there is a large pool for _each_ possible classification (2*5*2=20 of them) eliminates this problem.
     if ($qresult->num_rows != $num) {
         $this->user_err("Not enough such questions exist.");
     }
     $this->addQResult($qresult);
     $this->updateIs(range(count($this->Questions) - $num, count($this->Questions) - 1), "TimesViewed=TimesViewed+1");
     //--todo-- do this in user-specific storage instead.
     return $this;
 }