@@ -34,21 +34,40 @@ internal static bool ColumnExists(IDataReader reader, string columnName)
3434 /// <param name="reader">The Oracle data reader containing the column.</param>
3535 /// <param name="columnIndex">The index of the column to check.</param>
3636 /// <returns>Returns <c>true</c> if the column is of type "BFILE"; otherwise, <c>false</c>.</returns>
37-
3837 internal static bool IsBFileColumn ( OracleDataReader reader , int columnIndex )
3938 {
4039 const string BFILE_COLUMN = "BFILE" ;
4140 string columnType = reader . GetDataTypeName ( columnIndex ) ;
4241 return columnType . Equals ( BFILE_COLUMN , StringComparison . OrdinalIgnoreCase ) ;
4342 }
4443
44+ /// <summary>
45+ /// Determines if a specified column in an Oracle data reader, identified by its column name, is of type "BFILE".
46+ /// </summary>
47+ /// <param name="reader">The Oracle data reader containing the column.</param>
48+ /// <param name="columnName">The name of the column to check.</param>
49+ /// <returns>Returns <c>true</c> if the column is of type "BFILE"; otherwise, <c>false</c>. Returns <c>false</c> if the column does not exist.</returns>
50+ internal static bool IsBFileColumn ( OracleDataReader reader , string columnName )
51+ {
52+ const string BFILE_COLUMN = "BFILE" ;
53+ try
54+ {
55+ int columnIndex = reader . GetOrdinal ( columnName ) ;
56+ string columnType = reader . GetDataTypeName ( columnIndex ) ;
57+ return columnType . Equals ( BFILE_COLUMN , StringComparison . OrdinalIgnoreCase ) ;
58+ }
59+ catch ( IndexOutOfRangeException )
60+ {
61+ return false ;
62+ }
63+ }
64+
4565 /// <summary>
4666 /// Retrieves the content of a BFILE column from an Oracle data reader as a Base64-encoded string.
4767 /// </summary>
4868 /// <param name="reader">The Oracle data reader containing the BFILE column.</param>
4969 /// <param name="columnIndex">The index of the BFILE column to read.</param>
5070 /// <returns>Returns the BFILE content as a Base64-encoded string, or an empty string if the BFILE is null.</returns>
51-
5271 internal static string GetBFileContent ( OracleDataReader reader , int columnIndex )
5372 {
5473 string content = string . Empty ;
@@ -70,5 +89,42 @@ internal static string GetBFileContent(OracleDataReader reader, int columnIndex)
7089 }
7190 return content ;
7291 }
92+
93+ /// <summary>
94+ /// Retrieves the content of a BFILE column from an Oracle data reader as a Base64-encoded string, using the column name.
95+ /// </summary>
96+ /// <param name="reader">The Oracle data reader containing the BFILE column.</param>
97+ /// <param name="columnName">The name of the BFILE column to read.</param>
98+ /// <returns>Returns the BFILE content as a Base64-encoded string, or an empty string if the BFILE is null or the column does not exist.</returns>
99+ internal static string GetBFileContent ( OracleDataReader reader , string columnName )
100+ {
101+ string content = string . Empty ;
102+ try
103+ {
104+ int columnIndex = reader . GetOrdinal ( columnName ) ;
105+ var bFile = reader . GetOracleBFile ( columnIndex ) ;
106+ if ( bFile != null )
107+ {
108+ bFile . OpenFile ( ) ;
109+ byte [ ] buffer = new byte [ bFile . Length ] ;
110+ int bytesReadTotal = 0 ;
111+ while ( bytesReadTotal < buffer . Length )
112+ {
113+ int bytesRead = bFile . Read ( buffer , bytesReadTotal , buffer . Length - bytesReadTotal ) ;
114+ if ( bytesRead == 0 )
115+ break ;
116+ bytesReadTotal += bytesRead ;
117+ }
118+ content = Convert . ToBase64String ( buffer ) ;
119+ bFile . Close ( ) ;
120+ }
121+ }
122+ catch ( IndexOutOfRangeException )
123+ {
124+ return content ;
125+ }
126+ return content ;
127+ }
128+
73129 }
74130}
0 commit comments