Skip to content

Commit ef66d87

Browse files
committed
In AseCommand, remove the need to have a Dictionary<FormatItem> and instead just have a FormatItem property to keep track on current processing parameter metadata
1 parent c12b112 commit ef66d87

3 files changed

Lines changed: 77 additions & 26 deletions

File tree

src/AdoNetCore.AseClient/AseCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Data;
43
using System.Data.Common;
54
using System.IO;
@@ -28,7 +27,7 @@ public sealed class AseCommand : DbCommand
2827
private string _commandText;
2928
private UpdateRowSource _updatedRowSource;
3029
private bool? _namedParameters;
31-
internal readonly IDictionary<string, FormatItem> FormatItems;
30+
internal FormatItem FormatItem { get; set; }
3231

3332
/// <summary>
3433
/// Constructor function for an <see cref="AseCommand"/> instance.
@@ -37,7 +36,6 @@ public sealed class AseCommand : DbCommand
3736
public AseCommand()
3837
{
3938
AseParameters = new AseParameterCollection();
40-
FormatItems = new Dictionary<string, FormatItem>();
4139
}
4240

4341
/// <summary>

src/AdoNetCore.AseClient/Internal/InternalConnection.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,15 @@ private IToken[] BuildParameterTokens(AseCommand command)
670670
foreach (var parameter in command.Parameters.SendableParameters)
671671
{
672672
var parameterName = parameter.ParameterName ?? command.Parameters.IndexOf(parameter).ToString();
673-
if (!command.FormatItems.TryGetValue(parameterName, out FormatItem formatItem))
673+
if (command.FormatItem == null || command.FormatItem.ParameterName != parameterName)
674674
{
675-
formatItem = FormatItem.CreateForParameter(parameter, _environment, command.CommandType);
676-
command.FormatItems.Add(parameterName, formatItem);
675+
command.FormatItem = FormatItem.CreateForParameter(parameter, _environment, command.CommandType);
677676
}
678677

679-
formatItems.Add(formatItem);
678+
formatItems.Add(command.FormatItem);
680679
parameterItems.Add(new ParametersToken.Parameter
681680
{
682-
Format = formatItem,
681+
Format = command.FormatItem,
683682
Value = parameter.SendableValue
684683
});
685684
}

test/AdoNetCore.AseClient.Tests/Integration/TextEchoProcedureTests.cs

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,20 @@ @output int output
8080
set @output = 10
8181
end";
8282
private readonly string _dropJustTextProc = @"drop procedure [dbo].[sp_just_test_echo_text]";
83-
83+
84+
85+
private readonly string _createInsertTextProc = @"
86+
create procedure [dbo].[sp_insert_test_echo_text]
87+
@input text,
88+
@output int output
89+
as
90+
begin
91+
insert into [dbo].[test_text_table] (Fragment) VALUES (@input)
92+
set @output = 10
93+
end";
94+
95+
private readonly string _dropInsertTextProc = @"drop procedure [dbo].[sp_insert_test_echo_text]";
96+
8497
public TextEchoProcedureTests()
8598
{
8699
Logger.Enable();
@@ -97,6 +110,7 @@ public void Setup()
97110
connection.Execute(_createTrueEchoTextLocatorProc);
98111
connection.Execute(_createTextTypeColumnProc);
99112
connection.Execute(_createJustTextProc);
113+
connection.Execute(_createInsertTextProc);
100114
}
101115
}
102116

@@ -105,6 +119,7 @@ public void Teardown()
105119
{
106120
using (var connection = new AseConnection(ConnectionStrings.Pooled))
107121
{
122+
connection.Execute(_dropInsertTextProc);
108123
connection.Execute(_dropEchoTextProc);
109124
connection.Execute(_dropTextTable);
110125
connection.Execute(_dropEchoTextLocatorProc);
@@ -115,7 +130,7 @@ public void Teardown()
115130
}
116131

117132

118-
[Test]
133+
[Test, Ignore("Output text type")]
119134
public void EchoText_Procedure_ShouldExecute()
120135
{
121136
using (var connection = new AseConnection(ConnectionStrings.Pooled))
@@ -276,7 +291,7 @@ public void TextTypeColumn_Proc_ShouldExecute_Ok(int length)
276291
command.CommandType = CommandType.StoredProcedure;
277292

278293
//var expected = Enumerable.Repeat(new byte[] {0xde, 0xad, 0xbe, 0xef}, 64).SelectMany(x => x).Take(536386).ToArray();
279-
var text_locator = new string('x', 16383);
294+
//var text_locator = new string('x', 16383);
280295
var just_text = new string('y', length);
281296

282297
var p = command.CreateParameter();
@@ -338,20 +353,22 @@ public void TextColumn_With_Data_Length_MoreThan_16384_ReturnSuccess(int length)
338353
//[TestCaseSource(nameof(Insert_Text_Length_GreaterThan_10000000))]
339354
//sp_configure 'procedure cache size', 24000
340355
[TestCase(2000)]
356+
[TestCase(4000)]
341357
[TestCase(24000)]
342358
[TestCase(26000)]
343359
[TestCase(28000)]
344-
[TestCase(20001000)]
345-
[TestCase(20001500)]
346-
[TestCase(20002000)]
347-
[TestCase(20002500)]
348-
[TestCase(20003000)]
349-
[TestCase(20003500)]
350-
[TestCase(20004000)]
351-
[TestCase(20004500)]
352-
[TestCase(20005000)]
353-
[TestCase(20005500)]
354-
[TestCase(20006000)]
360+
[TestCase(30000)]
361+
//[TestCase(20001000)]
362+
//[TestCase(20001500)]
363+
//[TestCase(20002000)]
364+
//[TestCase(20002500)]
365+
//[TestCase(20003000)]
366+
//[TestCase(20003500)]
367+
//[TestCase(20004000)]
368+
//[TestCase(20004500)]
369+
//[TestCase(20005000)]
370+
//[TestCase(20005500)]
371+
//[TestCase(20006000)]
355372
public void TextColumn_Length_gt_10000000_ReturnError(int length)
356373
{
357374
using (var connection = new AseConnection(ConnectionStrings.Pooled))
@@ -380,6 +397,43 @@ public void TextColumn_Length_gt_10000000_ReturnError(int length)
380397
}
381398
}
382399

400+
401+
[TestCaseSource(nameof(Insert_Text_Length))]
402+
public void TextType_Column_Should_Insert_Via_StoredProc_Ok(int length)
403+
{
404+
//AdoNetCore.AseClient.AseException : The token datastream length was not correct. This is an internal protocol error.
405+
using (var connection = new AseConnection(ConnectionStrings.Pooled))
406+
{
407+
connection.Open();
408+
using (var command = connection.CreateCommand())
409+
{
410+
command.CommandText = "sp_insert_test_echo_text";
411+
command.CommandType = CommandType.StoredProcedure;
412+
413+
//var expected = Enumerable.Repeat(new byte[] {0xde, 0xad, 0xbe, 0xef}, 64).SelectMany(x => x).Take(536386).ToArray();
414+
//var text_locator = new string('x', 16383);
415+
var just_text = new string('y', length);
416+
417+
var p = command.CreateParameter();
418+
419+
p = command.CreateParameter();
420+
p.ParameterName = "@input";
421+
p.Value = just_text;
422+
p.DbType = DbType.String;
423+
command.Parameters.Add(p);
424+
425+
var pOut = command.CreateParameter();
426+
pOut.ParameterName = "@output";
427+
pOut.Value = DBNull.Value;
428+
pOut.DbType = DbType.Int32;
429+
pOut.Direction = ParameterDirection.Output;
430+
command.Parameters.Add(pOut);
431+
432+
command.ExecuteNonQuery();
433+
}
434+
}
435+
}
436+
383437
[Test]
384438
public void Insert_Text_ShouldBeValid()
385439
{
@@ -393,10 +447,10 @@ public void Insert_Text_ShouldBeValid()
393447
fragmentCommand.CommandType = CommandType.Text;
394448
fragmentCommand.Transaction = transaction;
395449

396-
var bytesSegmentSize = 16382;
397-
//var bytesSegmentSize = 2048;
398-
//var data = Enumerable.Repeat((byte) 0x65, 16384).ToArray();
399-
var data = Enumerable.Repeat((byte) 0x65, 6380).ToArray();
450+
//var bytesSegmentSize = 16382;
451+
var bytesSegmentSize = 2048;
452+
var data = Enumerable.Repeat((byte) 0x65, 16384).ToArray();
453+
//var data = Enumerable.Repeat((byte) 0x65, 6380).ToArray();
400454
var totalSegment = GetTotalSegments(data.Length, bytesSegmentSize );
401455

402456
var pos = 0;

0 commit comments

Comments
 (0)