Connecting Tech Pros Worldwide Help | Site Map

OCIRollback problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 4th, 2006, 03:25 AM
juicy
Guest
 
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.




  #2  
Old March 4th, 2006, 11:55 PM
Mladen Gogala
Guest
 
Posts: n/a
Default Re: OCIRollback problem

On Fri, 03 Mar 2006 23:14:26 -0500, juicy wrote:
[color=blue]
> 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.[/color]


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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.