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)