Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

fix(redis): share CLI tokenization for select ownership

Tobi04bf50058866
diff --git a/macos/App/State/AppState.swift b/macos/App/State/AppState.swift
index 76b126a..e9d782b 100644
--- a/macos/App/State/AppState.swift
+++ b/macos/App/State/AppState.swift
@@ -870,14 +870,16 @@ final class AppState: ObservableObject {
}
static func redisDatabaseNameSelected(by statement: String) -> String? {
- let components = statement.split(whereSeparator: { $0.isWhitespace })
- guard components.count == 2,
- components[0].lowercased() == "select",
- !components[1].isEmpty,
- components[1].unicodeScalars.allSatisfy({
+ let tokens = RedisAdapter.tokenizeCommand(
+ statement.trimmingCharacters(in: .whitespacesAndNewlines)
+ )
+ guard tokens.count == 2,
+ tokens[0].lowercased() == "select",
+ !tokens[1].isEmpty,
+ tokens[1].unicodeScalars.allSatisfy({
$0.value >= 48 && $0.value <= 57
}),
- let index = Int(components[1]) else { return nil }
+ let index = Int(tokens[1]) else { return nil }
return "db\(index)"
}
diff --git a/macos/Data/Adapters/Redis/RedisAdapter.swift b/macos/Data/Adapters/Redis/RedisAdapter.swift
index d0335de..a25259b 100644
--- a/macos/Data/Adapters/Redis/RedisAdapter.swift
+++ b/macos/Data/Adapters/Redis/RedisAdapter.swift
@@ -101,7 +101,7 @@ final class RedisAdapter: DatabaseAdapter, @unchecked Sendable {
}
/// Parse a space-separated Redis command string (respecting quoted strings).
- private func parseCommand(_ raw: String) -> [String] {
+ static func tokenizeCommand(_ raw: String) -> [String] {
var tokens: [String] = []
var current = ""
var inQuote: Character?
@@ -129,7 +129,7 @@ final class RedisAdapter: DatabaseAdapter, @unchecked Sendable {
func executeRaw(sql: String) async throws -> QueryResult {
let start = CFAbsoluteTimeGetCurrent()
- let tokens = parseCommand(sql.trimmingCharacters(in: .whitespacesAndNewlines))
+ let tokens = Self.tokenizeCommand(sql.trimmingCharacters(in: .whitespacesAndNewlines))
guard let keyword = tokens.first?.uppercased() else {
throw GridexError.queryExecutionFailed("Empty command")
}