SDAC. Identity.

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
AnDewil
Posts: 1
Joined: Thu 10 May 2012 16:18

SDAC. Identity.

Post by AnDewil » Thu 10 May 2012 16:30

SDAC 6.1.6.

There is stored procedure for insert

Code: Select all

create procedure meta.pf_obj_addformselectorvalue
	@p_id_obj_form_selector int output,
	@p_id_obj varchar(128),
	@p_order_no int,
	@p_ty_executor varchar(128),
	@p_id_form varchar(128),
	@p_table_name varchar(128),
	@p_f1 varchar(128),
	@p_v1 varchar(128),
	@p_f2 varchar(128) = null,
	@p_v2 varchar(128) = null,
	@p_f3 varchar(128) = null,
	@p_v3 varchar(128) = null,
	@p_f4 varchar(128) = null,
	@p_v4 varchar(128) = null,
	@p_f5 varchar(128) = null,
	@p_v5 varchar(128) = null
as...
There is TMSQuery.
StrictUpdate=False
QueryIdentity=True
CachedUpdates=True

Select:

Code: Select all

select *
from meta.st_obj_form_selector
Insert

Code: Select all

exec meta.pf_obj_addformselectorvalue
 :id_obj_form_selector,
 :id_obj,
 :order_no,
 :ty_executor,
 :id_form,
 :table_name,
 :f1,
 :v1,
 :f2,
 :v2,
 :f3,
 :v3,
 :f4,
 :v4,
 :f5,
 :v5
Param :id_obj_form_selector returns ID created record (used SCOPE_IDENTITY), which declared as IDENTITY. If I try insert record in my application, field id_obj_form_selector continues be empty.
How update this field automaticly?

AndreyZ

Re: SDAC. Identity.

Post by AndreyZ » Fri 11 May 2012 08:47

Hello,

To solve the problem, you should set the TMSQuery.Options.ReturnParams property to True. Also, you should use the BeforeUpdateExecute event handler to set the ParamType property of a corresponding parameter to ptInputOutput. For example:

Code: Select all

procedure TMainForm.MSQueryBeforeUpdateExecute(Sender: TCustomMSDataSet;
  StatementTypes: TStatementTypes; Params: TMSParams);
begin
  if stInsert in StatementTypes then
    Params.ParamByName('paramname').ParamType := ptInputOutput;
end;

Post Reply