Path: redb/redb.Core/Query/Window/WindowFunctionName.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Query/Window/WindowFunctionName.cs
----
using System;
namespace redb.Core.Query.Window;
///
/// Validates a caller-supplied window function name before it is emitted into SQL.
///
///
/// The name arrives from , a public settable string, so it is
/// data and not SQL. Every provider used to append it to the call text as-is
/// (func + "()"), which let a quote, a bracket or a comment marker reach the statement and
/// turn the remainder of the name into live SQL (SQLI-PoC: window function name fallback, all
/// dialects including Pro). Providers call this helper instead: a name that is not a plain
/// identifier is refused rather than pasted.
///
public static class WindowFunctionName
{
/// Longest accepted name. T-SQL caps an identifier at 128 characters; 64 is ample.
public const int MaxLength = 64;
/// True when holds only letters, digits and underscores.
public static bool IsPlainIdentifier(string? name)
{
if (string.IsNullOrEmpty(name) || name.Length > MaxLength)
return false;
foreach (var c in name)
{
if (!char.IsLetterOrDigit(c) && c != '_')
return false;
}
return true;
}
///
/// Renders a zero-argument call for , or throws when the name is not a
/// plain identifier. Throwing is deliberate: the previous behaviour appended the raw string.
///
public static string ZeroArgCall(string? name)
{
if (!IsPlainIdentifier(name))
throw new ArgumentException(
$"Unsupported window function: '{name}'. The name must be a plain identifier.",
nameof(name));
return name!.ToUpperInvariant() + "()";
}
}