Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions TablePro/Views/Structure/ClickHousePartsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Loading