Watch, Follow, &
Connect with Us

Please visit our new home

Public Report
Report From: Delphi-BCB/Database/DBExpress    [ Add a report in this area ]  
Report #:  103567   Status: Reported
Automatic parameter creation..
Project:  Delphi Build #:  16.0.4358.45540
Version:    16.3 Submitted By:   Tugrul HELVACI
Report Type:  Suggestion / Enhancement Request Date Reported:  2/21/2012 12:43:42 AM
Severity:    Commonly encountered problem Last Updated:
Platform:    All platforms Internal Tracking #:  
Resolution: None  Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: None
When i want to use SQL Server stored procedure via DBX framework i have to create many TDBXParameter objects and process that parameters. It is not an easy.. I think we can call some method to create automatic parameters like TADOStoredProc.Parameters.Refresh.

I think you can add some helper function to creating parameters automatically. My solution like this;

  TDBXCommandEx = class(TDBXMorphicCommand)
    procedure SetText(const Value: UnicodeString); override;

procedure TDBXCommandEx.SetText(const Value: UnicodeString);
  procedure DeleteListObjects(const AList : TList);
    while AList.Count > 0 do
  ParentConnection : TPersistent; // TSQLConnection
  ParamList        : TList;
  Param            : SPParamDesc;
  iCounter         : Integer;
  DBXParam         : TDBXParameter;

  if Self.CommandType <> TDBXCommandTypes.DbxStoredProcedure then Exit;
  if Trim(Self.Text) = '' then Exit;

  ParentConnection := nil;

  if FConnection <> nil then
    if FConnection.ConnectionProperties <> nil then
      ParentConnection := FConnection.ConnectionProperties.GetOwner;
      if ParentConnection <> nil then
        if ParentConnection is TSQLConnection then
          ParamList := TList.Create;
            TSQLConnection(ParentConnection).GetProcedureParams( Self.Text, ParamList );

            for iCounter := 0 to ParamList.Count - 1 do
              if ParamList.Items[iCounter] <> nil then
                if TObject(ParamList.Items[iCounter]) is SPParamDesc then
                  Param := SPParamDesc(ParamList.Items[iCounter]);

                  DBXParam := Self.CreateParameter;

                  // Direction
                  case Param.iArgType of
                    ptUnknown         : DBXParam.ParameterDirection := TDBXParameterDirections.Unknown;
                    ptInput           : DBXParam.ParameterDirection := TDBXParameterDirections.InParameter;
                    ptOutput          : DBXParam.ParameterDirection := TDBXParameterDirections.OutParameter;
                    ptInputOutput     : DBXParam.ParameterDirection := TDBXParameterDirections.InOutParameter;
                    ptResult          : DBXParam.ParameterDirection := TDBXParameterDirections.ReturnParameter;

                  // Data type
                  DBXParam.DataType := FldTypeMap[Param.iDataType];

                  // Name
                  DBXParam.Name := Param.szName;

                  if Param.iArgType <> ptResult then

                  Parameters.AddParameter( DBXParam );
                end; // if TObject(ParamList.Items[iCounter]) is SPParamDesc then
            end; // for iCounter := 0 to ParamList.Count - 1 do
          end; // try/finally
        end; // if ParentConnection is TSQLConnection then
    end; // if FConnection.ConnectionProperties <> nil then
Steps to Reproduce:


Server Response from: ETNACODE01