From 58e4f35f44840b2096afd0d58b06f7001da9e091 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Sat, 30 May 2026 13:39:00 +0700 Subject: [PATCH] refactor: route ClickHouse partition SQL through the driver's dialect-aware quoting --- TablePro/Views/Structure/ClickHousePartsView.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/TablePro/Views/Structure/ClickHousePartsView.swift b/TablePro/Views/Structure/ClickHousePartsView.swift index 1f0039d3d..6e5d35c49 100644 --- a/TablePro/Views/Structure/ClickHousePartsView.swift +++ b/TablePro/Views/Structure/ClickHousePartsView.swift @@ -112,8 +112,7 @@ struct ClickHousePartsView: View { private func optimizeTable() { Task { guard let driver = DatabaseManager.shared.driver(for: connectionId) else { return } - let escapedTable = tableName.replacingOccurrences(of: "`", with: "``") - let sql = "OPTIMIZE TABLE `\(escapedTable)` FINAL" + let sql = "OPTIMIZE TABLE \(driver.quoteIdentifier(tableName)) FINAL" do { _ = try await driver.execute(query: sql) await loadParts() @@ -138,8 +137,7 @@ struct ClickHousePartsView: View { guard confirmed else { return } guard let driver = DatabaseManager.shared.driver(for: connectionId) else { return } - let escapedTable = tableName.replacingOccurrences(of: "`", with: "``") - let sql = "ALTER TABLE `\(escapedTable)` DROP PARTITION '\(partitionValue.replacingOccurrences(of: "'", with: "''"))'" + let sql = "ALTER TABLE \(driver.quoteIdentifier(tableName)) DROP PARTITION '\(driver.escapeStringLiteral(partitionValue))'" do { _ = try await driver.execute(query: sql) selection.removeAll() @@ -165,8 +163,7 @@ struct ClickHousePartsView: View { guard confirmed else { return } guard let driver = DatabaseManager.shared.driver(for: connectionId) else { return } - let escapedTable = tableName.replacingOccurrences(of: "`", with: "``") - let sql = "ALTER TABLE `\(escapedTable)` DETACH PARTITION '\(partitionValue.replacingOccurrences(of: "'", with: "''"))'" + let sql = "ALTER TABLE \(driver.quoteIdentifier(tableName)) DETACH PARTITION '\(driver.escapeStringLiteral(partitionValue))'" do { _ = try await driver.execute(query: sql) selection.removeAll() @@ -197,12 +194,11 @@ struct ClickHousePartsView: View { } do { - let escapedTable = tableName.replacingOccurrences(of: "'", with: "''") let sql = """ SELECT partition, name, rows, bytes_on_disk, toString(modification_time) AS mod_time, active FROM system.parts - WHERE database = currentDatabase() AND table = '\(escapedTable)' + WHERE database = currentDatabase() AND table = '\(driver.escapeStringLiteral(tableName))' ORDER BY partition, name """ let result = try await driver.execute(query: sql)