Exemplo n.º 1
0
 /**
  * Begin nesting predicates
  *
  * @return Predicate
  */
 public function nest()
 {
     $predicateSet = new Predicate();
     $predicateSet->setUnnest($this);
     $this->addPredicate($predicateSet, $this->nextPredicateCombineOperator ?: $this->defaultCombination);
     $this->nextPredicateCombineOperator = null;
     return $predicateSet;
 }
Exemplo n.º 2
0
    public static $singleMale;
    public static $singleOrFemale = NULL;
}
Person::$male = new Predicate(function ($person) {
    return strtoupper($person->getGender()) == "MALE";
});
Person::$female = new Predicate(function ($person) {
    return strtoupper($person->getGender()) == "FEMALE";
});
Person::$single = new Predicate(function ($person) {
    return strtoupper($person->getMaritalStatus()) == "SINGLE";
});
Person::$singleMale = Person::$single->pAnd(Person::$male);
Person::$singleOrFemale = Person::$single->pOr(Person::$female);
$john2 = new Person("John", "Male", "Married");
$notJohn = Predicate::isEqual($john2)->not();
$people = Person::people();
$males = Person::filter($people, Person::$male);
$females = Person::filter($people, Person::$female);
$singleMales = Person::filter($people, Person::$singleMale);
$singleOrFemales = Person::filter($people, Person::$singleOrFemale);
$notJohns = Person::filter($people, $notJohn);
echo "Everyone:\t\t";
Person::display($people);
echo "\nNot John:\t\t";
Person::display($notJohns);
echo "\nSingle or Female:\t";
Person::display($singleOrFemales);
echo "\nMales:\t\t\t";
Person::display($males);
echo "\nSingle Males:\t\t";
 public function __construct($parent = null, $compareTo = null)
 {
     parent::__construct($parent, "less_than_eq", array($compareTo));
 }
Exemplo n.º 4
0
 /**
  * Merge an external predicates bindings with the current bindings.
  *
  * @param \Titon\Db\Query\Predicate $predicate
  * @return $this
  */
 public function resolvePredicate(Predicate $predicate)
 {
     $this->_bindings = array_merge($this->_bindings, $predicate->getBindings());
     return $this;
 }
Exemplo n.º 5
0
 function DatePredicate(&$parent, $col, $value)
 {
     $this->col = $col;
     parent::Predicate($parent, $value);
 }
Exemplo n.º 6
0
 public function __construct($parent = null, $compareTo = null)
 {
     parent::__construct($parent, "matches", array($compareTo));
 }
Exemplo n.º 7
0
 public function __construct($parent = null, $compareTo = null, $distance = 1)
 {
     parent::__construct($parent, "similar_to", array($compareTo, $distance));
 }
Exemplo n.º 8
0
 public function __construct($parent = null, $min = null, $max = null, $inclusive = true)
 {
     parent::__construct($parent, "between", array($min, $max, $inclusive));
 }
Exemplo n.º 9
0
 public function __construct($parent = null, $compareTo = null)
 {
     parent::__construct($parent, "greater_than", array($compareTo));
 }
Exemplo n.º 10
0
 public function noneMatch(Predicate $predicate) : bool
 {
     $gen = $this->execute();
     while ($gen->valid()) {
         if ($predicate->test($gen->current())) {
             return false;
         }
         $gen->next();
     }
     return true;
 }
Exemplo n.º 11
0
 protected static function processSelectStatement($parsed = array())
 {
     $query = $parsed["SQL"];
     // SELECT <select list> FROM <table reference>
     preg_match_all("/SELECT ([\\w,\\*`\\s]+) FROM\\s+([\\w,`]+)/i", $query, $matches);
     if (!empty($matches[1][0]) && !empty($matches[2][0])) {
         $column = $matches[1][0] == "*" ? null : $matches[1][0];
         $column = str_replace("`", "", $column);
         $column = str_replace(" ", "", $column);
         $table = str_replace("`", "", $matches[2][0]);
         $rowkey = "*";
         $filter = "";
         // SQL 有挑選特定欄位就加入 MultipleColumnPrefixFilter
         if ($column != "*" && !empty($column)) {
             // Convert Col1,Col2 => 'Col1','Col2'
             $column = "'" . str_replace(",", "','", $column) . "'";
             $filter .= "MultipleColumnPrefixFilter ({$column}) AND ";
         }
     }
     // SELECT <select list> FROM <table reference> WHERE <search condition>
     preg_match_all("/SELECT ([\\w,\\*`\\s]+) FROM\\s+([\\w,`]+)\\s+(WHERE ([\\w\\W,`\\s<=>'\"\\-:]+)*)/i", $query, $matches);
     if (!empty($matches[3])) {
         self::debug(print_r($matches, true));
         $condition_str = trim($matches[4][0]);
         //debugdump($condition_str);
         Predicate::parseMultiPredicate($condition_str);
         $predicates = Predicate::getPredicates();
         $operators = Predicate::getOperators();
         foreach ($predicates as $predicate_str) {
             $predicate = Predicate::getMappingPredicate($predicate_str);
             //new \Predicate($condition_str);
             if (!$predicate) {
                 throw new SQLBridgeException('查詢子句語意不明! (WHERE clause is ambiguity.)');
             }
             $args = $predicate->toFilterArguments();
             $qualifier = $args->qualifier;
             $op = $args->compareOperator;
             $comparator = $args->comparatorType;
             $value = $args->comparatorValue;
             $comparator = !empty($comparator) ? $comparator : $default_comparator;
             $cf = self::$hbase->getFirstColumnFamilyName($table);
             if (!preg_match("/^rowkey|id\$/i", $qualifier)) {
                 // SQL WHERE 條件子句以 SingleColumnValueFilter 處理
                 $filter .= "SingleColumnValueFilter ('{$cf}', '{$qualifier}', {$op}, '{$comparator}:{$value}', true, false)";
             } else {
                 $filter .= "RowFilter ({$op}, '{$comparator}:{$value}')";
             }
             $filter .= " " . current($operators) . " ";
             next($operators);
         }
     }
     // LIMIT
     preg_match_all("/LIMIT\\s*([\\d]+)/i", $query, $matches);
     if (!empty($matches[1][0])) {
         $limit = $matches[1][0];
         if (!empty($filter)) {
             $filter .= " AND ";
         }
         $filter .= "PageFilter ({$limit})";
     }
     if (preg_match("/^\\s*SELECT /i", $query)) {
         return MMB::select($table, $rowkey, $column, $filter);
     }
 }
Exemplo n.º 12
0
 public function __construct($parent = null, $start = null)
 {
     parent::__construct($parent, "starts_with", array($start));
 }
Exemplo n.º 13
0
 public function __construct($parent = null, $end = null)
 {
     parent::__construct($parent, "ends_with", array($end));
 }
Exemplo n.º 14
0
 public function __construct($parent = null, $set = array())
 {
     parent::__construct($parent, "set_member", $set);
 }