I have to evaluate your components for a company I'm currently working for, and while doing so ... i am encountering a few probles ... which I hope someone could help me with.
All problems can be simulated using a simple table (yes I'm evaluating dbExpress and a few other Component Sets too) :
Code: Select all
CREATE TABLE [dbo].[tblTestDBExpress](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Naam] [nvarchar](50) NOT NULL,
[Omschrijving] [nvarchar](50) NULL,
[Aantal] [int] NULL,
[CreatedBy] [nvarchar](50) NULL,
[CreatedOn] [datetime] NULL,
[UpdatedBy] [nvarchar](50) NULL,
[UpdatedOn] [datetime] NULL,
CONSTRAINT [PK_tblTestDBExpress] 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]
Stored Procedures with Optional / Default Parameters
I have the following Stored Procedure :
Code: Select all
CREATE PROCEDURE [dbo].[stpTestDBExpress2]
-- Add the parameters for the stored procedure here
@Name NVARCHAR( 50 ),
@Description NVARCHAR( 50 ),
@ID INTEGER OUTPUT,
@Quantity INTEGER = 88
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblTestDBExpress
([Naam]
,[Omschrijving]
,[Aantal] )
VALUES
( @Name
, @Description
, @Quantity)
SET @ID = IDENT_CURRENT( 'tblTestDBExpress' )
END
Now I tried using a TMSStoredProcedure component and the following code :
Code: Select all
MSStp1.StoredProcName := 'stpTestDBExpress2';
MSStp1.PrepareSQL;
MSStp1.ParamByName( 'Name' ).Value := 'Design Name';
MSStp1.ParamByName( 'Description' ).Value := 'Design Description';
MSStp1.ExecProc;
aNewID := MSStp1.ParamByName( 'ID' ).Value;
AddLogMessage( Format( 'dsgn Added test record with ID %d', [ aNewId ] ) );
Using the default ADO / dbGo components the generated SQL looks like :
Using your components, the generated SQL looks like :declare @p3 int
set @p3=124
exec stpTestDBExpress2 N'Design Name',N'Design Description',@p3 output,default
select @p3
Code: Select all
declare @p3 int
set @p3=126
exec stpTestDBExpress2 N'Design Name',N'Design Description',@p3 output,NULL
select @p3The Stored Procedure :
Code: Select all
CREATE PROCEDURE [dbo].[stpTestDBExpress4]
-- Add the parameters for the stored procedure here
@Name NVARCHAR( 50 ),
@Description NVARCHAR( 50 ),
@ID INTEGER OUTPUT,
@Quantity INTEGER = 88
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO tblTestDBExpress
([Naam]
,[Omschrijving]
,[Aantal] )
VALUES
( @Name
, @Description
, @Quantity)
SET @ID = IDENT_CURRENT( 'tblTestDBExpress' )
Return 333
--EXIT 1
SELECT * FROM tblTestDBExpress WHERE Id > 5
ENDCode: Select all
MSStp1.StoredProcName := 'stpTestDBExpress4';
MSStp1.ParamByName( 'Name' ).Value := 'Design Name';
MSStp1.ParamByName( 'Description' ).Value := 'Design Description';
MSStp1.ExecProc;
aNewID := MSStp1.ParamByName( 'ID' ).Value;
aResult := MSStp1.ParamByName('RETURN_VALUE').Value;
AddLogMessage( Format( 'Added test record with ID %d', [ aNewId ] ) );
AddLogMessage( Format( 'RETURN_VALUE was %d', [ aResult ] ) );
AddLogMessage( Format( 'Number of Records Returned %d', [ MSStp1.RecordCount ] ) );
I also tried using .Open instead of ExecProc, but then I receive an Exception saying that the Query should return exactly one resultset and I should use Execute instead.
So, I went ahead and tried the Execute method too, but that seemed to fail as well.
I seem to be unable to get both the Return_Value and a resultset from a stored procedure.
Maybe I am doing something wrong, but I couldn't get those 2 things working the way I would expect them to work.
Any help or info concerning these problems are welcome of course. Maybe it's an option or a setting I need to tweak ...
Regards,
Stefaan