A non-simple Insert

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 24-Oct-2005 23:49:46   

Hi,

Lets say I have a table where each row has an integer value which indicates its ordering position relative to all the other rows.

If I insert a new row somewhere in the middle of the table then all the rows after the new row need to have their position incremented by one.

Is LLBLGen capable of doing these updates upon an insert or should I add a trigger to the table?

Cheers, I.

Drewes
User
Posts: 67
Joined: 18-Aug-2003
# Posted on: 25-Oct-2005 02:36:53   

LLBLgen is not capable of doing that type of processing, that is something probably better left to trigger. However, doing that type of logic can put quite a strain on the database especially if you have a lot of rows. I would suggest incrementing in multiples of 10 or 100, that way if you need to insert a row you do not need to update every time all rows, you can give the row to insert a number in between, and you only need to do this occasionally.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 10:03:35   

You could do it though. simple_smile

In a single transaction, first save the entity, then call UpdateMulti() (selfservicing) or UpdateEntitiesDirectly (adapter) and with that call you update the indexes of all entities on the slots after the newly inserted entity.

Keep in mind though that this can be unsafe, e.g.: multiple threads can update the indexes simulaniously which thus gives incorrect indexes.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 26-Oct-2005 15:07:19   

Keep in mind though that this can be unsafe, e.g.: multiple threads can update the indexes simulaniously which thus gives incorrect indexes.

Sure. I'd use a transaction and have concurrency control.