public function testIsValidOperatorTypeByValue() { $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('startsWith', 'abc')); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('greaterThan', 'abc')); $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue('startsWith', 5)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('greaterThan', 5)); $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue('doesNotMatter', null)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('oneOf', array(4, 5, 6))); $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue('oneOf', null)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('greaterThanOrEqualTo', 'abc')); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('lessThanOrEqualTo', 'abc')); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('isNull', null)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('isNotNull', null)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('isEmpty', null)); $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue('isNotEmpty', null)); }
/** * Given an operator type and value, SQL is constructed. Example * return would be '>= 5'. * @return string */ public static function getOperatorAndValueWherePart($operatorType, $value) { assert('is_string($operatorType)'); if (!SQLOperatorUtil::isValidOperatorTypeByValue($operatorType, $value)) { throw new NotSupportedException('value: ' . $value . ' operator type: ' . $operatorType); } if (is_string($value)) { return self::resolveToLowerForStringComparison($operatorType, self::escape($value)); } elseif (is_array($value) && count($value) > 0) { return SQLOperatorUtil::resolveOperatorAndValueForOneOf($operatorType, $value); } elseif ($value !== null) { return SQLOperatorUtil::getOperatorByType($operatorType) . " " . self::escape($value); } elseif ($value === null) { return SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty($operatorType); } }