Skip to content

Commit 60bd986

Browse files
committed
fix: add MSSQL table counts in batch path and restore plugin test coverage
1 parent cac32e9 commit 60bd986

File tree

9 files changed

+2221
-1
lines changed

9 files changed

+2221
-1
lines changed

Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,32 @@ final class MSSQLPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
748748
"""
749749
do {
750750
let result = try await execute(query: sql)
751-
return result.rows.compactMap { row -> PluginDatabaseMetadata? in
751+
var metadata = result.rows.compactMap { row -> PluginDatabaseMetadata? in
752752
guard let name = row[safe: 0] ?? nil else { return nil }
753753
let sizeBytes = (row[safe: 1] ?? nil).flatMap { Int64($0) }
754754
return PluginDatabaseMetadata(name: name, sizeBytes: sizeBytes)
755755
}
756+
757+
for i in metadata.indices {
758+
let dbName = metadata[i].name.replacingOccurrences(of: "]", with: "]]")
759+
do {
760+
let countResult = try await execute(
761+
query: "SELECT COUNT(*) FROM [\(dbName)].sys.tables"
762+
)
763+
if let countStr = countResult.rows.first?[safe: 0] ?? nil,
764+
let count = Int(countStr) {
765+
metadata[i] = PluginDatabaseMetadata(
766+
name: metadata[i].name,
767+
tableCount: count,
768+
sizeBytes: metadata[i].sizeBytes
769+
)
770+
}
771+
} catch {
772+
// Database offline or permission denied — leave tableCount as nil
773+
}
774+
}
775+
776+
return metadata
756777
} catch {
757778
// Fall back to N+1 if permission denied on sys.master_files
758779
let dbs = try await fetchDatabases()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Plugins/MongoDBDriverPlugin/MongoDBQueryBuilder.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Plugins/MongoDBDriverPlugin/MongoDBStatementGenerator.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Plugins/RedisDriverPlugin/RedisQueryBuilder.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Plugins/RedisDriverPlugin/RedisStatementGenerator.swift

0 commit comments

Comments
 (0)