Exemple #1
0
 public function testChainSQLAndOr()
 {
     $sql1 = new Pluf_SQL('title=%s', 'my title');
     $sql2 = Pluf::factory('Pluf_SQL');
     $sql1->Q('description=%s', '%par example')->Q('keywords=%s', "tag'gi`ng");
     $sql3 = Pluf::factory('Pluf_SQL');
     $sql3->Q('status=%s', '1');
     $sql1->SOr($sql3);
     if ($this->db->engine == 'SQLite') {
         $res = "(title='my title' AND description='%par example' AND keywords='tag''gi`ng')";
         $res .= " OR (status='1')";
     } else {
         $res = "(title='my title' AND description='%par example' AND keywords='tag\\''gi`ng')";
         $res .= " OR (status='1')";
     }
     $this->assertEquals($res, $sql1->gen());
 }
Exemple #2
0
 /**
  * Generate the where clause.
  *
  * @return string The ready to use where clause.
  */
 function filter()
 {
     if (strlen($this->where_clause) > 0) {
         return $this->where_clause;
     }
     if (!is_null($this->forced_where) or strlen($this->search_string) > 0 && !empty($this->search_fields)) {
         $lastsql = new Pluf_SQL();
         $keywords = $lastsql->keywords($this->search_string);
         foreach ($keywords as $key) {
             $sql = new Pluf_SQL();
             foreach ($this->search_fields as $field) {
                 $sqlor = new Pluf_SQL();
                 $sqlor->Q($field . ' LIKE %s', '%' . $key . '%');
                 $sql->SOr($sqlor);
             }
             $lastsql->SAnd($sql);
         }
         if (!is_null($this->forced_where)) {
             $lastsql->SAnd($this->forced_where);
         }
         $this->where_clause = $lastsql->gen();
         if (strlen($this->where_clause) == 0) {
             $this->where_clause = null;
         }
     }
     return $this->where_clause;
 }