/** * Prepares a fragment of SQL to be used within a query. * This supports both [field] = [value]|[placeholder] or just [value]|[placeholder] * * @param string $field The field name to be used, set to null if it's not needed * @param string $placeholder The placeholder name to be used, set to null if a value is specified instead * @param string $value The value to be used, set to null if a placeholder is specified instead * @param Driver $driver Database driver, used to quote field names * @param bool $is_for_nulls if true, we treat NULL different, otherwise use '=' only ( for UPDATE ) * * @return string */ private static function prepareClause($field, $placeholder, $value, Driver $driver, $is_for_nulls = true) { $rhs = $placeholder === null ? $value : $placeholder; if ($field === null) { return $rhs; } // If the value is NULL, we need to use IS NULL, rather than =. $operator = $is_for_nulls && $value === null ? 'IS' : '='; return "{$driver->getQuotedName($field)} {$operator} {$rhs}"; }