public function testResolveOperatorAndValueForNullOrEmpty() { $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNull'); $compareQueryPart = "IS NULL"; // Not Coding Standard $this->assertEquals($compareQueryPart, $queryPart); $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNotNull'); $compareQueryPart = "IS NOT NULL"; // Not Coding Standard $this->assertEquals($compareQueryPart, $queryPart); $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isEmpty'); $compareQueryPart = "= ''"; // Not Coding Standard $this->assertEquals($compareQueryPart, $queryPart); $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNotEmpty'); $compareQueryPart = "!= ''"; // Not Coding Standard $this->assertEquals($compareQueryPart, $queryPart); }
/** * 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); } }
protected static function bypassReadPermissionsOptimizationToSqlQueryBasedOnWhere($where) { $q = DatabaseCompatibilityUtil::getQuote(); $builtTemplateType = static::BUILT_TYPE_BUILDER_TEMPLATE; $isNull = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNull'); $expectedWhere = "({$q}emailtemplate{$q}.{$q}builttype{$q} = {$builtTemplateType}) and " . "({$q}emailtemplate{$q}.{$q}modelclassname{$q} {$isNull})"; if ($where == $expectedWhere) { return true; } return parent::bypassReadPermissionsOptimizationToSqlQueryBasedOnWhere($where); }