Page 1 of 1

Simple Update statement

Posted: Mon 25 Feb 2008 11:59
by nclark
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!

Posted: Tue 26 Feb 2008 08:04
by Plash
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;

Posted: Tue 26 Feb 2008 12:37
by nclark
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

Posted: Wed 27 Feb 2008 08:35
by Plash
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.

Posted: Wed 27 Feb 2008 10:07
by nclark
Thank you. It was a bug. I was calling OraQuery.CommitUpdates instead on Session.Commit;