Skip to content

Commit d5a0ab3

Browse files
committed
Refactor GetBFileByteContent() - Column exists check in caller function
1 parent 015bb03 commit d5a0ab3

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

QueryDB/Resources/Utils.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal static bool IsBFileColumn(OracleDataReader reader, int columnIndex)
4646
/// </summary>
4747
/// <param name="reader">The Oracle data reader containing the column.</param>
4848
/// <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>
49+
/// <returns>Returns <c>true</c> if the column is of type "BFILE"; otherwise, <c>false</c>.</returns>
5050
internal static bool IsBFileColumn(OracleDataReader reader, string columnName)
5151
{
5252
const string BFILE_COLUMN = "BFILE";
@@ -88,32 +88,25 @@ internal static string GetBFileBase64Content(OracleDataReader reader, int column
8888
/// </summary>
8989
/// <param name="reader">The Oracle data reader containing the BFILE column.</param>
9090
/// <param name="columnName">The name of the BFILE column to read.</param>
91-
/// <returns>Returns the BFILE content as a byte array, or <c>null</c> if the BFILE is null or the column does not exist.</returns>
91+
/// <returns>Returns the BFILE content as a byte array, or <c>null</c> if the BFILE is null or the column value is null.</returns>
9292
internal static byte[] GetBFileByteContent(OracleDataReader reader, string columnName)
9393
{
9494
byte[] buffer = null;
95-
try
95+
int columnIndex = reader.GetOrdinal(columnName);
96+
var bFile = reader.GetOracleBFile(columnIndex);
97+
if (bFile != null && !reader.IsDBNull(columnIndex))
9698
{
97-
int columnIndex = reader.GetOrdinal(columnName);
98-
var bFile = reader.GetOracleBFile(columnIndex);
99-
if (bFile != null && !reader.IsDBNull(columnIndex))
99+
bFile.OpenFile();
100+
buffer = new byte[bFile.Length];
101+
int bytesReadTotal = 0;
102+
while (bytesReadTotal < buffer.Length)
100103
{
101-
bFile.OpenFile();
102-
buffer = new byte[bFile.Length];
103-
int bytesReadTotal = 0;
104-
while (bytesReadTotal < buffer.Length)
105-
{
106-
int bytesRead = bFile.Read(buffer, bytesReadTotal, buffer.Length - bytesReadTotal);
107-
if (bytesRead == 0)
108-
break;
109-
bytesReadTotal += bytesRead;
110-
}
111-
bFile.Close();
104+
int bytesRead = bFile.Read(buffer, bytesReadTotal, buffer.Length - bytesReadTotal);
105+
if (bytesRead == 0)
106+
break;
107+
bytesReadTotal += bytesRead;
112108
}
113-
}
114-
catch (IndexOutOfRangeException)
115-
{
116-
return buffer;
109+
bFile.Close();
117110
}
118111
return buffer;
119112
}

0 commit comments

Comments
 (0)