Skip to content

Commit 674944a

Browse files
authored
fix: avoid Oracle LONG column type that crashes OracleNIO decoder (#568)
1 parent 8849592 commit 674944a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Plugins/OracleDriverPlugin/OraclePlugin.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
276276
c.DATA_PRECISION,
277277
c.DATA_SCALE,
278278
c.NULLABLE,
279-
c.DATA_DEFAULT,
280279
CASE WHEN cc.COLUMN_NAME IS NOT NULL THEN 'Y' ELSE 'N' END AS IS_PK
281280
FROM ALL_TAB_COLUMNS c
282281
LEFT JOIN (
@@ -300,8 +299,7 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
300299
let precision = row[safe: 3] ?? nil
301300
let scale = row[safe: 4] ?? nil
302301
let isNullable = (row[safe: 5] ?? nil) == "Y"
303-
let defaultValue = (row[safe: 6] ?? nil)?.trimmingCharacters(in: .whitespacesAndNewlines)
304-
let isPk = (row[safe: 7] ?? nil) == "Y"
302+
let isPk = (row[safe: 6] ?? nil) == "Y"
305303

306304
let fullType = buildOracleFullType(dataType: dataType, dataLength: dataLength, precision: precision, scale: scale)
307305

@@ -310,7 +308,7 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
310308
dataType: fullType,
311309
isNullable: isNullable,
312310
isPrimaryKey: isPk,
313-
defaultValue: defaultValue
311+
defaultValue: nil
314312
)
315313
}
316314
}
@@ -537,7 +535,9 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
537535
func fetchViewDefinition(view: String, schema: String?) async throws -> String {
538536
let escapedView = view.replacingOccurrences(of: "'", with: "''")
539537
let escaped = effectiveSchemaEscaped(schema)
540-
let sql = "SELECT TEXT FROM ALL_VIEWS WHERE VIEW_NAME = '\(escapedView)' AND OWNER = '\(escaped)'"
538+
// Use DBMS_METADATA.GET_DDL instead of ALL_VIEWS.TEXT to avoid LONG column type
539+
// that crashes OracleNIO's decoder
540+
let sql = "SELECT DBMS_METADATA.GET_DDL('VIEW', '\(escapedView)', '\(escaped)') FROM DUAL"
541541
let result = try await execute(query: sql)
542542
return result.rows.first?.first?.flatMap { $0 } ?? ""
543543
}
@@ -568,6 +568,19 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
568568
comment: comment
569569
)
570570
}
571+
572+
// Fallback for views: ALL_TABLES returns no rows for views
573+
let viewSQL = """
574+
SELECT tc.COMMENTS
575+
FROM ALL_TAB_COMMENTS tc
576+
WHERE tc.TABLE_NAME = '\(escapedTable)' AND tc.OWNER = '\(escaped)'
577+
"""
578+
let viewResult = try await execute(query: viewSQL)
579+
if let row = viewResult.rows.first {
580+
let comment = row[safe: 0] ?? nil
581+
return PluginTableMetadata(tableName: table, comment: comment)
582+
}
583+
571584
return PluginTableMetadata(tableName: table)
572585
}
573586

0 commit comments

Comments
 (0)