|
4 | 4 | // |
5 | 5 |
|
6 | 6 | import Foundation |
7 | | -import Testing |
8 | 7 | @testable import TablePro |
| 8 | +import Testing |
9 | 9 |
|
10 | 10 | @Suite("SQL Row To Statement Converter") |
11 | 11 | struct SQLRowToStatementConverterTests { |
@@ -92,6 +92,13 @@ struct SQLRowToStatementConverterTests { |
92 | 92 | #expect(result == "UPDATE `users` SET `id` = '1', `name` = NULL, `email` = 'alice@example.com' WHERE `id` = '1' AND `name` IS NULL AND `email` = 'alice@example.com';") |
93 | 93 | } |
94 | 94 |
|
| 95 | + @Test("UPDATE with PK uses IS NULL in WHERE when PK value is NULL") |
| 96 | + func updateNullPrimaryKeyValue() { |
| 97 | + let converter = makeConverter() |
| 98 | + let result = converter.generateUpdates(rows: [[nil, "Alice", "alice@example.com"]]) |
| 99 | + #expect(result == "UPDATE `users` SET `name` = 'Alice', `email` = 'alice@example.com' WHERE `id` IS NULL;") |
| 100 | + } |
| 101 | + |
95 | 102 | // MARK: - Database-Specific Quoting |
96 | 103 |
|
97 | 104 | @Test("ClickHouse uses ALTER TABLE ... UPDATE syntax") |
@@ -122,6 +129,15 @@ struct SQLRowToStatementConverterTests { |
122 | 129 | #expect(result == "INSERT INTO `users` (`id`, `name`, `email`) VALUES ('1', 'Alice', 'alice@example.com');") |
123 | 130 | } |
124 | 131 |
|
| 132 | + @Test("DuckDB uses double-quote quoting and standard UPDATE syntax") |
| 133 | + func duckdbUsesDoubleQuoteAndStandardUpdate() { |
| 134 | + let converter = makeConverter(databaseType: .duckdb) |
| 135 | + let insert = converter.generateInserts(rows: [["1", "Alice", "alice@example.com"]]) |
| 136 | + #expect(insert == "INSERT INTO \"users\" (\"id\", \"name\", \"email\") VALUES ('1', 'Alice', 'alice@example.com');") |
| 137 | + let update = converter.generateUpdates(rows: [["1", "Alice", "alice@example.com"]]) |
| 138 | + #expect(update == "UPDATE \"users\" SET \"name\" = 'Alice', \"email\" = 'alice@example.com' WHERE \"id\" = '1';") |
| 139 | + } |
| 140 | + |
125 | 141 | // MARK: - Edge Cases |
126 | 142 |
|
127 | 143 | @Test("Empty rows input returns empty string") |
|
0 commit comments