FireDAC – MSSQL – Stored Proc context details?

FireDAC – MSSQL – Stored Proc context details?

Without adding parameters to the stored procedure, is it possible to pass / push more process context info than what MSSQL already has in sp_who? http://msdn.microsoft.com/en-us/library/ms174313.aspx

In particular: client app processid and thread id

Any optional connection parameter or similar?

   

Delphi – Database persistence, consistency and change resilience.

Delphi – Database persistence, consistency and change resilience.

We are looking at creating a unified audit trail log system, and in that respect, we have a challenge.

We want to log ObjectTypeId, ObjectInstanceId, Context, Verb (+time/user/app/comment/etc)

Here is the challenge.  How to ensure that the ObjectTypeId is the same in all databases, remains the same over time (as types come and go), is source code name change resilient, and has a minimum of in-code-maintenance overhead.

– Can’t hash the class name, as it may change.

– Can’t use only a factory, as the number of, and order of items may change.

Current two options…

1. A virtual abstract function in the base class, and overrides for each class – which still also requires a constant, but a certain risk for forgetting to change the value, and we have a LOT of classes

2. RegisterObjectTypeID(const_SomeTypeId: Cardinal; TSomeType: TClassOfBaseType);

But – this also requires creating a new constant every time, and ensuring that you actually call RegisterObjectTypeID for each type.

Currently leaning towards one – and only override for classes that will be using the audit system.

Are there other patterns that may apply to this?

FireDAC and bi-directional stored procedure parameters in SQL Server.

FireDAC and bi-directional stored procedure parameters in SQL Server.  I am diving into FireDAC, from a ADO starting point, and there are differences.

The SQL Server stored procedure below has two bidirectional parameters Error and Id. Description is input only, and the the procedure returns an int (0 = success, non-0 = check Error)

Error may be set, and Id is either a value > 0 which will be used as key, or if it is 0 or NULL, an auto-incremented value is returned through Id.

My ADO code which so far has translated easily for queries, etc – is barfing on invalid parameters for the stored proc.

How do you properly set up the bidirectional parameters?

How do you retrieve the output parameter values?

How do you retrieve the result value?

A simple code example would be appreciated, as the docs for TFDParams and Stored Procedures are Carefully Refined Awesome Prose.

{code}

CREATE PROCEDURE [dbo].[p_upsert_Description]

   @ErrorMsg varchar(1000) output,

   @Id int output,

   @Description varchar(100)

AS

BEGIN

    DECLARE @aId int;

    SET @ErrorMsg= ”;

    SET @aId= 0;

    BEGIN TRY

        SELECT @aId= Id FROM t_descriptions WHERE Id=@Id;

        IF @aId> 0

        BEGIN

            UPDATE t_descriptions

            SET Description=@Description

            WHERE Id =@aId;

            SELECT @Id=@aId;

        END

        ELSE

        BEGIN

            DECLARE @TmpIdTable table(ID int)

            INSERT INTO t_descriptions (

                CreatedTime,

                Description

            )  OUTPUT inserted.ID into @TmpIdTable

            VALUES (

                SYSDATETIME(),

               @Description

            );

            SELECT TOP 1 @Id= ID  FROM @TmpIdTable

        END

    END TRY

    BEGIN CATCH

        SELECT @ErrorMsg= ERROR_MESSAGE();

        RETURN SELECT ERROR_NUMBER();

    END CATCH

    RETURN 0;

END

{code}

Post “moved” from Delphi Component Directory

Post “moved” from Delphi Component Directory

Originally shared by Frank Duchna

Hello everbody.

Could someone help me on how i can store a password in an SQL database?

Other Option would be to find out which user is connected to the database.

I want to set up a rights-management within my Software to control which parts are used and to filter data from the database.

Thanks in advance.

Frank

Generics and incompatible types.

Generics and incompatible types.

I’ve been buggered with an error that has me tearing the little I have left of hair out.  

[dcc32 Error] DUnitX_PSDCarrierTypes.pas(75): E2010 Incompatible types: ‘TPSDCarrierType’ and ‘TPSDBase’

The problem is that DUnitX_PSDCarrierTypes.pas only has 73 lines.

Has anyone seen this before?  Can you remember what the underlying cause was at the time?  Property or method visibility?  Missing unit inclusion? Abstract methods?

Let me introduce the classes

In PSDBase,

  TPSDBase = class (TLockableObject, ILogInterface)

    …

   end;

and

  TTestBaseClass = class

  private

    FInstance: T;

    function GetInstance: TPSDBase;

  protected

    property Instance: TPSDBase read GetInstance;

   …

end;

In PSDCarrierTypes,

  TPSDCarrierType = class(TPSDBase)

 …

  end;

 

unit DUnitX_PSDBase;

interface

uses

  PSDBase, PSDConstants,

  DUnitX.TestFramework;

type

  ///

Basis generic test class for TPSDBase descendants

  TTestClass = class(TTestBaseClass)

  …

end;

and 

[TestFixture]

TestTPSDBase = class(TTestClass)

  …

end;

 

unit DUnitX_PSDCarrierTypes;

interface

uses

  DUnitX.TestFramework,

  PSDConstants, PSDBase, DUnitX_PSDBase, PSDCarrierTypes;

type

  [TestFixture]

  TestTPSDCarrierType= class(TTestClass)

  …

  end;

 

The main app looks has the following uses

program DUnitX_PSD_BasicUnitTests;

uses

  EMemLeaks,

  EResLeaks,

  EDialogWinAPIEurekaLogDetailed,

  EDialogWinAPIStepsToReproduce,

  EDebugExports,

  EFixSafeCallException,

  EMapWin32,

  EAppVCL,

  ExceptionLog7,

  SysUtils,

  DUnitX.AutoDetect.Console,

  DUnitX.Loggers.Console,

  DUnitX.Loggers.Xml.NUnit,

  DUnitX.TestRunner,

  DUnitX.TestFramework,

  PSDBase in ‘..PSDCommonPSDBase.pas’,

  PSDCarrierTypes in ‘..PSDCommonPSDCarrierTypes.pas’,

  DUnitX_PSDBase in ‘DUnitX_PSDBase.pas’,

  DUnitX_PSDCarrierTypes in ‘DUnitX_PSDCarrierTypes.pas’;

At first, I thought there was something weird about the order of compilation, but no – it looks normal.

14:54:39,1355491 DUnitX.ConsoleWriter.Base.dcu

14:54:39,2945261 DUnitX.Utils.dcu

14:54:39,3847109 DUnitX.IoC.dcu

14:54:39,4146560 DUnitX.Windows.Console.dcu

14:54:39,4222502 DUnitX.AutoDetect.Console.dcu

14:54:39,4371663 DUnitX.Generics.dcu

14:54:39,4582339 DUnitX.Extensibility.dcu

14:54:39,5233700 DUnitX.InternalInterfaces.dcu

14:54:39,5430712 DUnitX.WeakReference.dcu

14:54:39,5612627 DUnitX.Test.dcu

14:54:39,5751848 DUnitX.TestFixture.dcu

14:54:39,6043794 DUnitX.RunResults.dcu

14:54:39,6422193 DUnitX.TestResult.dcu

14:54:39,6714326 DUnitX.FixtureResult.dcu

14:54:39,7038809 DUnitX.Extensibility.PluginManager.dcu

14:54:39,8034689 DUnitX.TestRunner.dcu

14:54:39,8136915 DUnitX.CommandLine.dcu

14:54:39,8669545 DUnitX.MemoryLeakMonitor.Default.dcu

14:54:39,9958192 DUnitX.FixtureProviderPlugin.dcu

14:54:40,1629623 DUnitX.TestFramework.dcu

14:54:40,2033539 DUnitX.Loggers.Console.dcu

14:54:40,2217283 DUnitX.Loggers.Null.dcu

14:54:40,2732231 DUnitX.Loggers.XML.NUnit.dcu

14:54:40,3435106 StringFunctions.dcu

14:54:40,3692211 CustomDebugOut.dcu

14:54:40,3768381 Functions.dcu

14:54:40,7058753 FileFunctions.dcu

14:54:40,7107884 TINEFunctions.dcu

14:54:40,7191973 TineInterfaces.dcu

14:54:40,7319419 PSDConstants.dcu

14:54:40,7487508 TineClasses.dcu

14:54:40,7766713 PSDXMLLog.dcu

14:54:40,7834018 PSDLogEvent.dcu

14:54:40,7919438 PSDLogExceptionManager.dcu

14:54:40,8042575 PSDLogDrivers.dcu

14:54:40,8155411 tiConsts.dcu

14:54:40,8266076 PSDResourcePool.dcu

14:54:40,8517546 PSDConnectivityStatus.dcu

14:54:40,8632446 PSD_Db_Abstract.dcu

14:54:40,8960845 PSD_TCPTelegramBase.dcu

14:54:40,9079624 PSD_TCP_Types.dcu

14:54:40,9199220 PSD_TCPTelegrams.dcu

14:54:41,0200024 PSDBase.dcu

14:54:41,1065126 PSDCarrierTypes.dcu

14:54:41,1135979 DUnitX_PSDBase.dcu

…then the compilation fails for unit DUnitX_PSDCarrierType, 2 lines beyond end of unit.