I have a Delphi 2007 application using SDAC 4.80.0.60 with SQL Server 2008 SP3 Standard Edition.
Everything is working well, but there's a memory leak when using TMSQuery with output parameters to get the id for the recently created entry.
Here's the delpi code:
Code: Select all
Query := TMSQuery.Create(nil);
try
Query.Connection := Connection;
Query.SQL.Add('Insert into Test (Name, Timestamp) values (:NAME, :Timestamp)');
Query.ParamByName('Name').asString := 'Versuch';
Query.ParamByName('Timestamp').AsDateTime := now;
Query.SQL.Add('; SET :PK = SCOPE_IDENTITY() ');
Query.ParamByName('PK').ParamType := ptInputOutput;
Query.Execute;
id := Query.ParamByName('PK').AsInteger;
label1.caption := 'ID : ' + IntToStr(id);
finally
Query.Close;
FreeAndNil(Query);
end;
Code: Select all
CREATE TABLE [dbo].[Test](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Timestamp] [datetime] NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Edit:
Problem solved by adding this line:
Code: Select all
Query.ParamByName('PK').DataType := ftInteger;