@@ -401,7 +401,6 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
401401 c.DATA_PRECISION,
402402 c.DATA_SCALE,
403403 c.NULLABLE,
404- c.DATA_DEFAULT,
405404 CASE WHEN cc.COLUMN_NAME IS NOT NULL THEN 'Y' ELSE 'N' END AS IS_PK
406405 FROM ALL_TAB_COLUMNS c
407406 LEFT JOIN (
@@ -424,8 +423,7 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
424423 let precision = row [ safe: 4 ] ?? nil
425424 let scale = row [ safe: 5 ] ?? nil
426425 let isNullable = ( row [ safe: 6 ] ?? nil ) == " Y "
427- let defaultValue = ( row [ safe: 7 ] ?? nil ) ? . trimmingCharacters ( in: . whitespacesAndNewlines)
428- let isPk = ( row [ safe: 8 ] ?? nil ) == " Y "
426+ let isPk = ( row [ safe: 7 ] ?? nil ) == " Y "
429427
430428 let fullType = buildOracleFullType ( dataType: dataType, dataLength: dataLength, precision: precision, scale: scale)
431429
@@ -434,7 +432,7 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
434432 dataType: fullType,
435433 isNullable: isNullable,
436434 isPrimaryKey: isPk,
437- defaultValue: defaultValue
435+ defaultValue: nil
438436 )
439437 columnsByTable [ tableName, default: [ ] ] . append ( col)
440438 }
@@ -509,15 +507,10 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
509507 func fetchTableDDL( table: String , schema: String ? ) async throws -> String {
510508 let escapedTable = table. replacingOccurrences ( of: " ' " , with: " '' " )
511509 let escaped = effectiveSchemaEscaped ( schema)
512- let sql = " SELECT DBMS_METADATA.GET_DDL('TABLE', ' \( escapedTable) ', ' \( escaped) ') FROM DUAL "
513- do {
514- let result = try await execute ( query: sql)
515- if let row = result. rows. first, let ddl = row. first ?? nil {
516- return ddl
517- }
518- } catch {
519- Self . logger. debug ( " DBMS_METADATA failed, building DDL manually: \( error. localizedDescription) " )
520- }
510+
511+ // Do NOT use DBMS_METADATA.GET_DDL — if the object type is wrong
512+ // (view, materialized view, etc.), Oracle returns ORA-31603 which
513+ // corrupts OracleNIO's connection state machine. Build DDL manually.
521514
522515 let cols = try await fetchColumns ( table: table, schema: schema)
523516 var ddl = " CREATE TABLE \" \( escaped) \" . \" \( escapedTable) \" ( \n "
@@ -535,9 +528,10 @@ final class OraclePluginDriver: PluginDatabaseDriver, @unchecked Sendable {
535528 func fetchViewDefinition( view: String , schema: String ? ) async throws -> String {
536529 let escapedView = view. replacingOccurrences ( of: " ' " , with: " '' " )
537530 let escaped = effectiveSchemaEscaped ( schema)
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 "
531+ // ALL_VIEWS.TEXT is LONG (crashes OracleNIO). TEXT_VC is VARCHAR2(4000), safe.
532+ // Do NOT use DBMS_METADATA.GET_DDL — wrong object type triggers ORA-31603
533+ // which corrupts OracleNIO's connection state machine.
534+ let sql = " SELECT TEXT_VC FROM ALL_VIEWS WHERE VIEW_NAME = ' \( escapedView) ' AND OWNER = ' \( escaped) ' "
541535 let result = try await execute ( query: sql)
542536 return result. rows. first? . first? . flatMap { $0 } ?? " "
543537 }
0 commit comments