Exemple #1
0
 function GenerateSql($params)
 {
     parent::GenerateSql($params);
     if (is_array($params)) {
         extract($params);
     }
     if (!$this->Core->HasActiveRecord() && !$all && !$this->Core->__mismatched_set_equals) {
         // insert new record
         $this->Mode = "insert";
         return $this->insert();
     } else {
         if (!$this->Core->HasActiveRecord() || $all) {
             // update set
             $this->Mode = "update_set";
             return $this->update_set();
         } else {
             if ($this->Core->HasActiveRecord() || $this->Core->PrimaryKeyIsSet()) {
                 // update current record
                 $this->Mode = "update";
                 return $this->update();
             } else {
                 // not sure how we got here ...
             }
         }
     }
 }
Exemple #2
0
 function GenerateSql($params)
 {
     parent::GenerateSql($params);
     if (is_array($params)) {
         extract($params);
     }
     $sql = "delete from {$this->Core->__table} ";
     list($wsql, $fields) = $this->Where->GenerateSql($params);
     return array($sql . $wsql, $fields);
 }
Exemple #3
0
 function GenerateSql($params)
 {
     parent::GenerateSql($params);
     if (is_array($params)) {
         extract($params);
     }
     $sql = "select " . implode(', ', $this->Core->GetSelectFields()) . " from {$this->Core->__table} ";
     list($wsql, $fields) = $this->Where->GenerateSql($params);
     $ordering = array();
     if (is_array($this->Core->__ordering)) {
         foreach ($this->Core->__ordering as $fieldname => $order) {
             $ordering[] = $this->Core->GetQualifiedName($fieldname) . " {$order}";
         }
     }
     if (count($ordering) > 0) {
         $osql = " order by " . implode(", ", $ordering);
     }
     list($pagination, $page) = $this->Core->GetLimit();
     if (!is_null($pagination)) {
         $p = $page * $pagination;
         $lsql = " limit {$p}, {$pagination}";
     }
     return array($sql . $wsql . $osql . $lsql, $fields);
 }
Exemple #4
0
 function GenerateSql($params)
 {
     parent::GenerateSql($params);
     if (is_array($params)) {
         extract($params);
     }
     if (!isset($conjunction)) {
         $conjunction = 'and';
     }
     $where_clauses = array();
     $where_fields = array();
     foreach ($this->Core->__field_actions as $field => $action) {
         if ($this->Core->PrimaryKeyIsSet()) {
             //Is this important, or just an optimization that got out of hand?
             //It's important ... Noah 10/4/2013
             if ($field != $this->Core->GetPrimaryKeyField()) {
                 continue;
             }
         }
         foreach ($action as $comparator => $value) {
             switch ($comparator) {
                 case Yapo::NOT_EQ:
                 case Yapo::EQUALS:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . ($comparator == Yapo::EQUALS ? '=' : '!=') . " :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::NOT_LIKE:
                 case Yapo::LIKE:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . ($comparator == Yapo::NOT_LIKE ? ' not ' : '') . " like :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::GREATER:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . " > :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::LESS:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . " < :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::GREATER_EQ:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . " >= :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::LESS_EQ:
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . " <= :where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_");
                     $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_")] = $value;
                     break;
                 case Yapo::NOT_IN:
                 case Yapo::IN:
                     $Core = $this->Core;
                     $where_clauses[] = $this->Core->GetQualifiedName($field) . ($comparator == Yapo::NOT_IN ? ' not ' : '') . " in (" . implode(', ', array_map(function ($n) use($field, $Core, $comparator) {
                         return ":where_{$comparator}_" . $Core->GetQualifiedName($field, "_") . $n;
                     }, range(0, count($value) - 1, 1))) . ")";
                     $n = 0;
                     foreach ($value as $index => $v) {
                         $where_fields["where_{$comparator}_" . $this->Core->GetQualifiedName($field, "_") . $n] = $v;
                         $n++;
                     }
                     break;
             }
         }
     }
     if (count($where_clauses) > 0) {
         return array('where ' . implode(" {$conjunction} ", $where_clauses), $where_fields);
     }
     return array("", array());
 }