Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ private object internalGetString(int i)
// note that in general you should not trust third-party providers so such asserts should be
// followed by exception. I did not add it now to avoid breaking change
Debug.Assert(lengthOrIndicator >= 0 || lengthOrIndicator == ODBC32.SQL_NO_TOTAL, "unexpected lengthOrIndicator value");
if (0 == lengthOrIndicator)
{
break; // done
}

if (ODBC32.SQL_NO_TOTAL != lengthOrIndicator)
{
Expand Down
28 changes: 28 additions & 0 deletions src/libraries/System.Data.Odbc/tests/ReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Data.Odbc;
using System.Text;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

Expand Down Expand Up @@ -261,5 +264,30 @@ public void InvalidRowName()
exception.Message);
}
}

[ConditionalFact]
public void GetString_ShouldNotLoopIndefinitely_WhenDriverReturnsLessDataFollowedByNoData()
{
// This test simulates a driver that:
// - Returns a full length string indication (strLenOrInd)
// - First returns a partial chunk of data
// - Then returns a smaller chunk than expected
// - Finally returns SQL_NO_DATA_FOUND

command.CommandText = @"CREATE TABLE T (Val TEXT);
INSERT INTO T VALUES ('" + new string('X', 8000) + "');";
command.ExecuteNonQuery();

command.CommandText = "SELECT Val FROM T;";
using (var reader = command.ExecuteReader())
{
Assert.True(reader.Read());
string result = reader.GetString(0);

// The string should match the inserted string (even if fetched in chunks).
string expected = new string('X', 8000);
Assert.Equal(expected, result);
}
}
}
}
Loading