Simple Update statement

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Simple Update statement

Post by nclark » Mon 25 Feb 2008 11:59

Hi

I would like to know how to issue 3 simple UPDATE statements to the database.

For example:

If the use has checked a checkbox then
begin

UPDATE set OK_TO_USE_FLAG = 'Y'
where key like '3142%';

UPDATE set OK_TO_USE_FLAG = 'Y'
where key like '3142%';

UPDATE set OK_TO_USE_FLAG = 'Y'
where key like '3142%';

commit;

end;

There is no matching select so I am not sure if TORAQUERY is correct.

Can you please give step by step statements in your response.


Thank you!

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 26 Feb 2008 08:04

You can use a code like the following:

Code: Select all

  OraQuery.AutoCommit := False;

  OraQuery.SQL.Text := 'UPDATE  set OK_TO_USE_FLAG = ''Y'' where key like ''3142%''';
  OraQuery.Execute;
  OraQuery.SQL.Text := 'UPDATE  set OK_TO_USE_FLAG = ''Y'' where key like ''3142%''';
  OraQuery.Execute;
  OraQuery.SQL.Text := 'UPDATE  set OK_TO_USE_FLAG = ''Y'' where key like ''3142%''';
  OraQuery.Execute;

  OraSession.Commit;

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Post by nclark » Tue 26 Feb 2008 12:37

Thank you for the response.

I received an error
"Cannot perform this operation on a closed dataset"

When I added that which I thought natural ie
OraQ.Open;

Then I received an error
"Sql statment does not return any rows"

Intuitively I feel that OraQ.Sql.Text is for queries (which the error appears to confirm). What is Oraq.SQLUpdate used for? .. and how can I solve the "Cannot perform this operation on a closed dataset"
problem?

Thanks again

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 27 Feb 2008 08:35

You can assign an UPDATE statement to SQL property of TOraQuery. In that case you should call Execute method instead of Open to execute the statement. The code from my previous post should not raise the error "Cannot perform this operation on a closed dataset".

You should debug your code to detect what line of the code raises this error.

SQLUpdate property is used when editing a result SELECT statement.

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Post by nclark » Wed 27 Feb 2008 10:07

Thank you. It was a bug. I was calling OraQuery.CommitUpdates instead on Session.Commit;

Post Reply