Search Postgresql Archives

How do I save data and then raise an exception?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings!
 
The people who originally wrote the system I'm trying to work with did not know as much as they should have about working with databases, so I'm stuck with the following situation:
 
The applicaton is written in C++ (MS Visual C++ 6, Windows XP, in case it matters).  At one point, a required check was not performed before data was saved.  I cannot change this part of the C++ code, so I have to perform the check in the database, and the insert query has to fail so that the application will see that something bad happened.  However, there's another query that gets performed before the one I have to check.  If the check fails, the earlier query has to be undone.  The only way I know to intentionally fail a query is to raise an exception.  However, raising an exception causes all earlier database changes to be undone.  How can I avoid that?
 
Here's what I need to do:
 
IF query_check_fails THEN
    UPDATE some_table SET some_value = 0 WHERE some_condition_is_true;
    RAISE EXCEPTION 'Look, you idiot, do it right next time!'; 
END;
 
I need the update to work, but I need to raise the exception so the C++ code recognizes the error.  How can I do both?
 
Thanks very much!
 
RobR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux