Page 1 of 1

Incorrect TMSSQL.Assign() method

Posted: Wed 09 Jun 2010 12:22
by may
After calling the TMSSQL.Assign() method both instances (source and destination) has an own Params collection, but contents of this collection is the same.

Example:

procedure TForm1.Button1Click;
var
cmd: TMSSQL;
begin
cmd := TMSSQL.Create(Self);


// cmdTemplate here is a TMSSQL Component on my TForm1, it is a Template object, that I'm using in diffrent places.
cmd.Assign(cmdTemplate);

cmd.ParamByName('AParamName').Value := 'AnyValue';

// After that my cmdTemplate's param 'AParamValue' also have value 'AValue'.
if cmd.ParamByName('AParamName').AsString = cmdTemplate.ParamByName('AParamName').AsString then
ShowMessage('AssigneError');


end;


So that I must to set values for all params in TMSSQL each time I using it, because I don't now who was used my cmdTemplate early.

Posted: Wed 09 Jun 2010 13:34
by Dimon
I can not reproduce the problem.
Please, try to download the latest SDAC build (4.80.0.58) and check if this problem still exists.

Posted: Thu 10 Jun 2010 12:09
by may
The Parameter DataType specified in TMSSQLEditor must be "Memo" or "Blob" :!: . For other datatypes method works correctly.

Sorry for incomplete explanation in the first message.

I'm using version 4.7 and try to download last version, nothing to happen with it.

Posted: Fri 11 Jun 2010 08:55
by Dimon
On assigning blob parameters only reference to Blob object is copied. It's done to prevent copying of large memory amounts for blob objects.
To create new objects for blob parameters you can use the following code:

Code: Select all

  MSSQL2.Assign(MSSQL1);
  for i := 0 to MSSQL2.Params.Count - 1 do begin
    if MSSQL2.Params[i].DataType in [ftMemo{$IFDEF VER10P}, ftWideMemo{$ENDIF}, ftBlob] then begin
      MSSQL2.Params[i].DataType := ftUnknown;
      MSSQL2.Params[i].DataType := MSSQL1.Params[i].DataType;
      MSSQL2.Params[i].Value := MSSQL1.Params[i].Value;
    end;
  end;

Posted: Fri 11 Jun 2010 11:01
by may
Thanks for advice. I must to guess myself :? , the source is open...

So you find such behavior of the Assign() necessary. However it's a news for me.

Posted: Fri 11 Jun 2010 14:43
by Dimon
If there is anything else I can help you with, please contact me.

Posted: Wed 16 Jun 2010 05:37
by may
Dimon wrote:If there is anything else I can help you with, please contact me.
Ok :wink:
(Imho) Since TPersistemt.Assign() overriden by TDAParam.Assign() with a specific behavior, it will be wanted to read about in SDAC's Help.

Posted: Wed 16 Jun 2010 08:25
by Dimon
Thank you for your inquiry. We will investigate the possibility of adding this inforamation in the near future.