dimanche 4 février 2018

Duplicate Oracle Sequence

I have a problem about using oracle sequence with yajra/laravel-oci8 library (v.5.1) in Laravel 5.1.

My scenario are:

  1. I have a column named trailer_id in table A.
  2. That column contain ID that generated using sequence named trailed_id_seq. Code:

    function postCreate(Request $request) {
        $id = $request->input('id');
    
        DB::beginTransaction();
    
        ....
    
        $running_no_seq = DB::getSequence();
        $trailer_id = $running_no_seq->nextValue('trailer_id_seq')."";
    
        for($i=0; $i < $counter; $i++) {
           // Some process, it can take a while here...
        }
    
        DB::table('A')->where('id',$id)->update([
           'trailer_id' => $trailer_id
        ]);
    
        DB::commit();
    }
    
    

    The property of trailer_id_seq sequence (captured in Navicat apps): enter image description here

  3. This function can be called by many users.

The problem is:

Why the trailer_id column can be duplicate when accessed by different user in different time?

Here some example: (created_by is user ID) enter image description here

My question: How is this possible? How can i fixed it? (I can't make trailer_id column to unique)

I've read yajra oci docs: https://yajrabox.com/docs/laravel-oci8/master/sequence , is the code DB::getSequence()->nextValue('seq_name'); ONLY return next value and not updated the sequence?

Because in oracle docs, nextval is increments the sequence and returns the next value (https://docs.oracle.com/cd/A84870_01/doc/server.816/a76989/ch26.htm#4062).

Please help me. Thank you for any answer!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire