/** * WHERE条件文を生成する * * @access public * @param string $field 検索対象のフィールド * @param mixed $value 検索値 * @param int $condition 検索条件(OBJECT_CONDITION_NE,...) * @return string 検索条件文 * @static */ function getCondition($field, $value, $condition = OBJECT_CONDITION_EQ) { switch ($condition) { case OBJECT_CONDITION_EQ: $op = "="; break; case OBJECT_CONDITION_NE: $op = "!="; break; case OBJECT_CONDITION_LIKE: $op = "LIKE"; break; case OBJECT_CONDITION_GT: $op = ">"; break; case OBJECT_CONDITION_LT: $op = "<"; break; case OBJECT_CONDITION_GE: $op = ">="; break; case OBJECT_CONDITION_LE: $op = "<="; break; } // default operand $operand = $value; if (is_array($value)) { if (count($value) > 0) { switch ($condition) { case OBJECT_CONDITION_EQ: $op = "IN"; break; case OBJECT_CONDITION_NE: $op = "NOT IN"; break; } $operand = sprintf("(%s)", implode(',', $value)); } else { // always be false $op = "="; $operand = "NULL"; } } else { if ($value == 'NULL') { switch ($condition) { case OBJECT_CONDITION_EQ: $op = "IS"; break; case OBJECT_CONDITION_NE: $op = "IS NOT"; break; } } if ($condition == OBJECT_CONDITION_LIKE) { Ethna_AppSQL::unescapeSQL($value); $value = '%' . str_replace('%', '\\%', $value) . '%'; Ethna_AppSQL::escapeSQL($value); $operand = $value; } } return "{$field} {$op} {$operand}"; }