ExecSql result count in case of using begin end;

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ahijazi
Posts: 47
Joined: Mon 01 Oct 2007 11:13

ExecSql result count in case of using begin end;

Post by ahijazi » Sat 28 May 2011 15:36

Dear Devart;

Code: Select all

  sqlCmd.SQL.Text := '';
  sqlCmd.SQL.Text := 'begin update demo set oid = 202 where oid = -1;       
                                  commit; end;'

   sqlCmd.Execute;

how to get the correct Rows Affected ???

always get 1

best regards ....

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 30 May 2011 08:58

Hello,


With the help of the RowsAffected property you can receive the number of rows from pure SQL. If you are using PL/SQL block, you should use variables to return the number of modified/inserted/deleted rows, for example:

Code: Select all

OraQuery1.SQL.Text:= 'begin '+#13+
                      'update demo set oid = 202 where oid = -1; '+#13+
                      ':cnt := SQL%ROWCOUNT; '+#13+
                      'commit; '+#13+
                      'end;';
OraQuery1.ParamByName('cnt').ParamType:= ptOutput;
OraQuery1.ParamByName('cnt').DataType:= ftInteger;
OraQuery1.Execute;
ShowMessage(OraQuery1.ParamByName('cnt').AsString);

ahijazi
Posts: 47
Joined: Mon 01 Oct 2007 11:13

Post by ahijazi » Tue 31 May 2011 07:26

Dear Devart;

thank a lot.. but I have another question, in case of using the TOraSession.ExecSql with simple update statement (without begin end;) how can I get the RowsAffected ??? only available in TOraSQL !!
Best Regards,

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 31 May 2011 08:44

Hello,

To get the number of records that were changed using the TOraSession.ExecSQL method, you can use the following code:

Code: Select all

OraSession1.ExecSQL('update demo set oid = 202 where oid = -1',[]);
ShowMessage(IntToStr(OraSession1.SQL.RowsAffected));

ahijazi
Posts: 47
Joined: Mon 01 Oct 2007 11:13

Post by ahijazi » Tue 31 May 2011 09:18

Dear Devart;


Thanks again ....


Best Regards,

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 31 May 2011 10:24

Hello,

If you have any other questions, feel free to contact us

Post Reply