Пример #1
0
 /**
  *  検索条件SQL文を返す
  *
  *  @access public
  *  @param  string  検索対象カラム名
  *  @return SQL文
  */
 function toString($column)
 {
     $condition = "(";
     $tmp_value = $this->value;
     Ethna_AppSQL::escapeSQL($tmp_value);
     $condition .= Ethna_AppSQL::getCondition("{$column}", $tmp_value, $this->condition);
     foreach ($this->object_list as $elt) {
         if ($elt['condition'] == OBJECT_CONDITION_OR) {
             $condition .= " OR ";
         } else {
             $condition .= " AND ";
         }
         $condition .= $elt['object']->toString($elt['name']);
     }
     return $condition . ")";
 }
 /**
  *  オブジェクト検索SQLの条件文を構築する
  *
  *  @access private
  *  @param  array   $filter     WHERE検索条件(カラム名をキー、値には実際の条件値か、Ethna_AppSearchObjectを指定)
  *  @return string  オブジェクト検索の条件文(エラーならnull)
  */
 function _getSQL_SearchCondition($filter)
 {
     if (is_array($filter) == false) {
         return "";
     }
     $p_table = $this->_getPrimaryTable();
     //  検索用追加プロパティ
     //  プライマリーキー以外の検索キーが含まれていた
     //  場合は、その解釈を _SQLPlugin_SearchPropDef に任せる
     //
     //  これによって、複数のテーブルの条件を指定することが
     //  できる(一応. ダサいけど)
     if ($this->_isAdditionalField($filter)) {
         $search_prop_def = $this->_SQLPlugin_SearchPropDef();
     } else {
         $search_prop_def = array();
     }
     $prop_def = array_merge($this->prop_def, $search_prop_def);
     $condition = null;
     foreach ($filter as $k => $v) {
         if (isset($prop_def[$k]) == false) {
             trigger_error(sprintf("Unknown property [%s]", $k), E_USER_ERROR);
             return null;
         }
         if (is_null($condition)) {
             $condition = "WHERE ";
         } else {
             $condition .= " AND ";
         }
         $t = isset($prop_def[$k]['table']) ? $prop_def[$k]['table'] : $p_table;
         // 細かい条件を指定するには、Ethna_AppSearchObject
         // を使う必要がある  文字列の場合は LIKE, 数値の場合
         // は = 条件しか指定できないからである。
         if (is_object($v)) {
             // Ethna_AppSearchObjectが指定されている場合
             $condition .= $v->toString($this->my_db_ro->quoteIdentifier($t) . '.' . $this->my_db_ro->quoteIdentifier($k));
         } else {
             if (is_array($v) && count($v) > 0 && is_object($v[0])) {
                 // Ethna_AppSearchObjectが配列で指定されている場合
                 $n = 0;
                 foreach ($v as $so) {
                     if ($n > 0) {
                         $condition .= " AND ";
                     }
                     $condition .= $so->toString($this->my_db_ro->quoteIdentifier($t) . '.' . $this->my_db_ro->quoteIdentifier($k));
                     $n++;
                 }
             } else {
                 if ($prop_def[$k]['type'] == VAR_TYPE_STRING) {
                     // 省略形(文字列)
                     Ethna_AppSQL::escapeSQL($v, $this->my_db_type);
                     $condition .= Ethna_AppSQL::getCondition($this->my_db_ro->quoteIdentifier($t) . '.' . $this->my_db_ro->quoteIdentifier($k), $v, OBJECT_CONDITION_LIKE);
                 } else {
                     // 省略形(数値)
                     Ethna_AppSQL::escapeSQL($v, $this->my_db_type);
                     $condition .= Ethna_AppSQL::getCondition($this->my_db_ro->quoteIdentifier($t) . '.' . $this->my_db_ro->quoteIdentifier($k), $v, OBJECT_CONDITION_EQ);
                 }
             }
         }
     }
     return $condition;
 }
 /**
  *  オブジェクト検索SQLの条件文を構築する
  *
  *  @access private
  *  @param  array   $filter     検索条件
  *  @return string  オブジェクト検索の条件文(エラーならnull)
  */
 function _getSQL_SearchCondition($filter)
 {
     if (is_array($filter) == false) {
         return "";
     }
     $p_table = $this->_getPrimaryTable();
     // 検索用追加プロパティ
     if ($this->_isAdditionalField($filter)) {
         $search_prop_def = $this->_SQLPlugin_SearchPropDef();
     } else {
         $search_prop_def = array();
     }
     $prop_def = array_merge($this->prop_def, $search_prop_def);
     $condition = null;
     foreach ($filter as $k => $v) {
         if (isset($prop_def[$k]) == false) {
             trigger_error(sprintf("Unknown property [%s]", $k), E_USER_ERROR);
             return null;
         }
         if (is_null($condition)) {
             $condition = "WHERE ";
         } else {
             $condition .= " AND ";
         }
         $t = isset($prop_def[$k]['table']) ? $prop_def[$k]['table'] : $p_table;
         if (is_object($v)) {
             // Ethna_AppSearchObjectが指定されている場合
             $condition .= $v->toString("{$t}.{$k}");
         } else {
             if (is_array($v) && count($v) > 0 && is_object($v[0])) {
                 // Ethna_AppSearchObjectが配列で指定されている場合
                 $n = 0;
                 foreach ($v as $so) {
                     if ($n > 0) {
                         $condition .= " AND ";
                     }
                     $condition .= $so->toString("{$t}.{$k}");
                     $n++;
                 }
             } else {
                 if ($prop_def[$k]['type'] == VAR_TYPE_STRING) {
                     // 省略形(文字列)
                     Ethna_AppSQL::escapeSQL($v);
                     $condition .= Ethna_AppSQL::getCondition("{$t}.{$k}", $v, OBJECT_CONDITION_LIKE);
                 } else {
                     // 省略形(数値)
                     Ethna_AppSQL::escapeSQL($v);
                     $condition .= Ethna_AppSQL::getCondition("{$t}.{$k}", $v, OBJECT_CONDITION_EQ);
                 }
             }
         }
     }
     return $condition;
 }
Пример #4
0
 /**
  * @link http://www.bpsinc.jp/blog/archives/223
  */
 function _getSQL_Update()
 {
     $tables = implode(',', $this->my_db_rw->quoteIdentifier(array_keys($this->table_def)));
     // SET句構築
     $set_list = "";
     $prop_arg_list = $this->prop;
     Ethna_AppSQL::escapeSQL($prop_arg_list, $this->my_db_type);
     foreach ($this->prop_def as $k => $v) {
         if (isset($prop_arg_list[$k]) && $prop_arg_list[$k] !== null && $prop_arg_list[$k] !== '') {
             if ($set_list != "") {
                 $set_list .= ",";
             }
             $set_list .= sprintf("%s=%s", $this->my_db_rw->quoteIdentifier($k), $prop_arg_list[$k]);
         }
     }
     // 検索条件(primary key)
     $condition = null;
     foreach (to_array($this->id_def) as $k) {
         if (is_null($condition)) {
             $condition = "WHERE ";
         } else {
             $condition .= " AND ";
         }
         $v = $this->prop_backup[$k];
         // equals to $this->id
         Ethna_AppSQL::escapeSQL($v, $this->my_db_type);
         $condition .= Ethna_AppSQL::getCondition($this->my_db_rw->quoteIdentifier($k), $v);
     }
     $sql = "UPDATE {$tables} SET {$set_list} {$condition}";
     return $sql;
 }