40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
namespace Omika.HfSqlProbe;
|
|
|
|
internal static class ProbeSqlBuilder
|
|
{
|
|
/// <summary>
|
|
/// Builds INSERT ... RETURNING <idColumn>.
|
|
/// Defensively validates all identifiers before interpolation.
|
|
/// </summary>
|
|
public static string BuildInsertReturning(string table, string idColumn, string markerColumn)
|
|
{
|
|
SqlIdentifierValidator.Validate(table);
|
|
SqlIdentifierValidator.Validate(idColumn);
|
|
SqlIdentifierValidator.Validate(markerColumn);
|
|
return $"INSERT INTO {table} ({markerColumn}) VALUES (?) RETURNING {idColumn}";
|
|
}
|
|
|
|
/// <summary>Count rows matching a marker value.</summary>
|
|
public static string BuildCountByMarker(string table, string markerColumn)
|
|
{
|
|
SqlIdentifierValidator.Validate(table);
|
|
SqlIdentifierValidator.Validate(markerColumn);
|
|
return $"SELECT COUNT(*) FROM {table} WHERE {markerColumn} = ?";
|
|
}
|
|
|
|
/// <summary>Insert a marker row (no RETURNING).</summary>
|
|
public static string BuildInsertMarker(string table, string markerColumn)
|
|
{
|
|
SqlIdentifierValidator.Validate(table);
|
|
SqlIdentifierValidator.Validate(markerColumn);
|
|
return $"INSERT INTO {table} ({markerColumn}) VALUES (?)";
|
|
}
|
|
|
|
/// <summary>Read GUID samples.</summary>
|
|
public static string BuildSelectGuids(int limit)
|
|
{
|
|
return "SELECT GUID FROM Client WHERE GUID IS NOT NULL AND GUID <> '' " +
|
|
$"LIMIT {limit}";
|
|
}
|
|
}
|