"Octavian Rasnita" schreef:
> Dr.Ruud:
>> Octavian Rasnita:

>>> but the problem is that the primary key field which has
>>> autoincrement option skips the ID of each record which is not
>>> inserted because it is already in the database, and I don't want
>>> that.
>>
>> This skip is normal in a multi-connection environment. You allocate
>> the next value, and there is just no safe and easy way to unallocate
>> it. Maybe SQLite has a single-connection mode that behaves
>> differently, but I don't think so.
>>
>> So just do a SELECT yourself, before INSERTing. Preferrably in a
>> batch.
>
> I finally made the program to create a hash with the unique field as
> a key, and if the record with that field is in the hash, the program
> doesn't need to query the database.
>
> If the record with the field that should be unique is not found in
> that hash, the program searches it in the DB and only if it was not
> found it is inserted.
>
> This way it works fine.

Unless another process can insert concurrently, in between your SELECT
and INSERT.

And don't forget to add your newly inserted key to the hash. :)

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to