BatchExecute issues since 9.4.X

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
OlliWW
Posts: 25
Joined: Mon 25 Mar 2013 17:03

BatchExecute issues since 9.4.X

Post by OlliWW » Tue 25 Jan 2022 09:44

Hi,

We are using SDAC 9.3.x at the moment. We testes 9.4.x and 10.x but we have some issues with batch executes:

We are using a procedure to add insert statements dynamicly to a batch execute.

We do this the following way:

Code: Select all

procedure BatchExec.prcSetAsString(const _sParam: String; _iRow: Integer; const _sValue: String);
var
  objParam: TMSParam;
begin
  qry.Parameters.ValueCount := iRowCount + 1;
  Inc(iRowCount);

  objParam := qry.ParamByName(_sParam);
  objParam.DataType := ftMemo;
  objParam.Values[_iRow].Value := _sValue;
end;
The problem is the first line:
If you increase the ValueCout Value String parameters are resetted. (Only string fields, other fields work just fine). In 9.3.x and lower there is no issue with this code. Since this issue only exists with string fields i think this is a bug.

Could you assist me, to resolve this issue?

Greetings from Germany

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: BatchExecute issues since 9.4.X

Post by Stellar » Fri 28 Jan 2022 14:13

Hi,

Unfortunately, we couldn't reproduce the issue. To investigate this behavior of UniDAC, please compose a small sample demonstrating the issue and send it to us, including database objects creating scripts.
You can send the sample using the contact form at our site: devart.com/company/contactform.html

Best regards,
Sergey,
Devart Support Team

OlliWW
Posts: 25
Joined: Mon 25 Mar 2013 17:03

Re: BatchExecute issues since 9.4.X

Post by OlliWW » Sat 29 Jan 2022 11:52

Here is a sample code, read the comments in the code, i'll send it to you via contact form as well.

This code works up to 9.3.x. After 9.3. not.

Code: Select all

unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DBAccess, SdacVcl, Data.DB, MSAccess;

type
  TForm3 = class(TForm)
    MSConnection1: TMSConnection;
    MSConnectDialog1: TMSConnectDialog;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

const
  cTempTableName = '#BatchTemp';

procedure TForm3.FormCreate(Sender: TObject);
var
  qryExec: TMSQuery;
  objParam: TMSParam;
begin
  MSConnection1.Connect;

  // Create Temp Table
  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    qryExec.SQL.Text :=
      'create table ' + cTempTableName + ' ( ' +
        '_GEN INT IDENTITY(1, 1) primary key , ' +
        '_COL_STRING varchar(max) ' +
      ')';
    qryExec.Execute;
  finally
    FreeAndNil(qryExec);
  end;


  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    //#####################
    // This Part is normally a procedure to dynamiclly add Values
    // For simplification i replicated the code 3 times

    qryExec.SQL.Text := 'insert into ' + cTempTableName + ' (_COL_STRING) values (:STRING) ';

    qryExec.Params.ValueCount := 1;
    objParam := qryExec.ParamByName('STRING');
    objParam.DataType := ftMemo;
    objParam.Values[0].Value := 'Hello';

    qryExec.Params.ValueCount := 2;
    objParam := qryExec.ParamByName('STRING');
    objParam.DataType := ftMemo;
    objParam.Values[1].Value := 'World';

    // Set a Breakpoint BEFORE here
    // Watch the values: objParam.Values[1].Value AND objParam.Values[0].Value
    // 0 contains "Hello" and 1 contains "World"
    // After the next row 0 and 1 are "not set", it happens wenn you execute this row:
    qryExec.Params.ValueCount := 3;
    objParam := qryExec.ParamByName('STRING');
    objParam.DataType := ftMemo;
    objParam.Values[2].Value := 'Foobar';

    // No need to execute the BatchExecute because the values are already wrong...

    //#####################
  finally
    FreeAndNil(qryExec);
  end;


  // Drop Temp Table
  qryExec := TMSQuery.Create(nil);
  qryExec.Connection := MSConnection1;
  try
    qryExec.SQL.Text := 'drop table ' + cTempTableName;
    qryExec.Execute;
  finally
    FreeAndNil(qryExec);
  end;
end;

end.

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: BatchExecute issues since 9.4.X

Post by Stellar » Mon 31 Jan 2022 15:31

Hi,

Thank you for the information.
We have fixed the issue, and the fix will be included in the next SDAC build.

Best regards,
Sergey

Post Reply