OCIRollback problem

This is a discussion on OCIRollback problem within the PHP Language forums, part of the PHP Programming Forums category; I want to do rollback from insert data into master-details table when there are duplicate ID key in by ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-04-2006
juicy
 
Posts: n/a
Default OCIRollback problem

I want to do rollback from insert data into master-details table when there
are duplicate ID key in by user. The algorithm is like this

1. insert data into master_table
2. loop
3. select count(*) from detail where ID = <ID key in by user>
4. if count(*) > 0{ $dup = true;}//end if
5. insert data into detail_table
6. End loop
7. If $dup = true{OCIRollback($conn);}
else{OCICommit($conn);}

if there are two duplicate row inserted into detail_table, it should
rollback all transaction but I found that it won't work and still insert
on record to it.

Please advise on this problem, thanks.



Reply With Quote
  #2 (permalink)  
Old 03-05-2006
Mladen Gogala
 
Posts: n/a
Default Re: OCIRollback problem

On Fri, 03 Mar 2006 23:14:26 -0500, juicy wrote:

> I want to do rollback from insert data into master-details table when there
> are duplicate ID key in by user. The algorithm is like this
>
> 1. insert data into master_table
> 2. loop
> 3. select count(*) from detail where ID = <ID key in by user>
> 4. if count(*) > 0{ $dup = true;}//end if
> 5. insert data into detail_table
> 6. End loop
> 7. If $dup = true{OCIRollback($conn);}
> else{OCICommit($conn);}
>
> if there are two duplicate row inserted into detail_table, it should
> rollback all transaction but I found that it won't work and still insert
> on record to it.
>
> Please advise on this problem, thanks.



You should have posted the original code snipped that fails,
not just the pseudocode. Nevertheless, my guess is that
your problem is the fact that oci_execute performs a commit if
the statement execution is successful. Here is what the good
book says:

"oci_execute() executes a previously parsed statement (see oci_parse()).
The optional mode allows you to specify the execution mode (default is
OCI_COMMIT_ON_SUCCESS). If you don't want statements to be committed
automatically, you should specify OCI_DEFAULT as your mode."

In addition to that, I feel inclined to ask why are you de-duping data
like that and why don't you create unique constraint and let the database
winnow out duplicates? Oracle supports things like unique constraints, and
primary keys which will eliminate the duplicates without loops.

--
http://www.mgogala.com

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:01 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0