Skip to content

Commit e3b6f92

Browse files
Hex-encode data blobs returned from internal SQL queries
1 parent f08f086 commit e3b6f92

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Signal/src/ViewControllers/AppSettings/Internal/InternalSQLClientViewController.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,30 @@ class InternalSQLClientViewController: UIViewController {
9696
}
9797

9898
let output = DependenciesBridge.shared.db.read { tx in
99+
let rows: [Row]
99100
do {
100-
return try Row
101-
.fetchAll(tx.database, sql: query)
102-
.map({"\($0)"})
103-
.joined(separator: "\n")
101+
rows = try Row.fetchAll(tx.database, sql: query)
104102
} catch let error {
105103
return "\(error)"
106104
}
105+
106+
let rowStrings: [String] = rows.map { row in
107+
let columnValueStrings: [String] = row.map { (columnName: String, dbValue: DatabaseValue) -> String in
108+
let valueString = switch dbValue.storage {
109+
case .string(let string): string
110+
case .int64(let int64): "\(int64)"
111+
case .double(let double): "\(double)"
112+
case .null: "NULL"
113+
case .blob(let data): data.hexadecimalString
114+
}
115+
116+
return "\(columnName):\(valueString)"
117+
}
118+
119+
return "[\(columnValueStrings.joined(separator: ", "))]"
120+
}
121+
122+
return rowStrings.joined(separator: "\n\n")
107123
}
108124

109125
outputTextView.text = output

0 commit comments

Comments
 (0)