Skip to content

Commit 099fbc2

Browse files
fix: escape strings for hypertables correctly
1 parent ea30294 commit 099fbc2

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/Eftdb/Generators/HypertableOperationGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ private static string WrapCommunityFeatures(List<string> sqlStatements)
309309
/// Escapes existing double quotes.
310310
/// Example: TenantId -> "TenantId"
311311
/// </summary>
312-
private static string QuoteIdentifier(string identifier)
312+
private string QuoteIdentifier(string identifier)
313313
{
314-
return $"\"{identifier.Replace("\"", "\"\"")}\"";
314+
return $"{quoteString}{identifier.Replace("\"", "\"\"")}{quoteString}";
315315
}
316316

317317
/// <summary>
318318
/// Quotes the column name within an ORDER BY clause while preserving direction/nulls.
319319
/// Example: Timestamp DESC -> "Timestamp" DESC
320320
/// </summary>
321-
private static string QuoteOrderByList(IEnumerable<string> orderByClauses)
321+
private string QuoteOrderByList(IEnumerable<string> orderByClauses)
322322
{
323323
return string.Join(", ", orderByClauses.Select(clause =>
324324
{

tests/Eftdb.Tests/Generators/HypertableOperationGeneratorComprehensiveTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void DesignTime_Create_WithCompressionSegmentBy_GeneratesCorrectCode()
383383
license := current_setting('timescaledb.license', true);
384384
385385
IF license IS NULL OR license != 'apache' THEN
386-
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""tenant_id"", ""device_id""'')';
386+
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""tenant_id"""", """"device_id""""'')';
387387
ELSE
388388
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
389389
END IF;
@@ -418,7 +418,7 @@ public void DesignTime_Create_WithCompressionOrderBy_GeneratesCorrectCode()
418418
license := current_setting('timescaledb.license', true);
419419
420420
IF license IS NULL OR license != 'apache' THEN
421-
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""time"" DESC, ""value"" ASC NULLS LAST'')';
421+
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""""time"""" DESC, """"value"""" ASC NULLS LAST'')';
422422
ELSE
423423
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
424424
END IF;
@@ -862,7 +862,7 @@ public void DesignTime_Alter_AddingCompressionSegmentBy_GeneratesCorrectCode()
862862
license := current_setting('timescaledb.license', true);
863863
864864
IF license IS NULL OR license != 'apache' THEN
865-
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""device_id""'')';
865+
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""device_id""""'')';
866866
ELSE
867867
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
868868
END IF;

tests/Eftdb.Tests/Generators/HypertableOperationGeneratorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void Generate_Create_With_Compression_Segment_And_OrderBy_Generates_Corre
187187
license := current_setting('timescaledb.license', true);
188188
189189
IF license IS NULL OR license != 'apache' THEN
190-
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""TenantId"", ""DeviceId""'', timescaledb.compress_orderby = ''""Timestamp"" DESC, ""Value"" ASC NULLS LAST'')';
190+
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""TenantId"""", """"DeviceId""""'', timescaledb.compress_orderby = ''""""Timestamp"""" DESC, """"Value"""" ASC NULLS LAST'')';
191191
ELSE
192192
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
193193
END IF;
@@ -222,7 +222,7 @@ public void Generate_Alter_Adding_Compression_SegmentBy_Generates_Correct_Sql()
222222
license := current_setting('timescaledb.license', true);
223223
224224
IF license IS NULL OR license != 'apache' THEN
225-
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""DeviceId""'')';
225+
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""DeviceId""""'')';
226226
ELSE
227227
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
228228
END IF;
@@ -257,7 +257,7 @@ public void Generate_Alter_Modifying_Compression_OrderBy_Generates_Correct_Sql()
257257
license := current_setting('timescaledb.license', true);
258258
259259
IF license IS NULL OR license != 'apache' THEN
260-
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""Timestamp"" DESC'')';
260+
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""""Timestamp"""" DESC'')';
261261
ELSE
262262
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
263263
END IF;

tests/Eftdb.Tests/Integration/HypertableIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public async Task Should_Handle_LargeDataset()
980980
for (int i = 0; i < 100; i++)
981981
{
982982
DateTime timestamp = baseTime.AddMinutes(i);
983-
valueRows.Add($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})");
983+
valueRows.Add(FormattableString.Invariant($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})"));
984984
}
985985

986986
string sql = $@"INSERT INTO ""PerformanceTest"" (""Timestamp"", ""SensorId"", ""Value"")

0 commit comments

Comments
 (0)