Octavian Rasnita wrote:
> 
> I have an SQLite database that has a field with a unique constraint and I 
> want to be able to insert records as fast as possible.
> 
> The program works fine if I use
> 
> insert or ignore into table_name...
> 
> 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.
> 
> So I have also tried using
> 
> eval {
> ... the query...
> };
> 
> But the perl interpreter crashes and it appears an error window if the query 
> gives an error.
> 
> I think that it would take too much time to verify each record if exists in 
> the database before inserting it...
> 
> Do you have a recommendation for the best way of doing this?

Since this is a Perl forum it is helpful to use the /full syntax/ of any SQL
that your Perl is using. (I assume you actually have some Perl behind all
this?) And in particular you should avoid abbreviating non-standard SQL, so
that at least we have s chance of looking it up.

Also this sentence

> 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.

is long and badly expressed.

So what I think you're saying is that you have an SQLite database table whihc
has a field with the attribute

  INTEGER PRIMARY KEY AUTOINCREMENT

(By the way, I think the autoincrement is misleading, if this answer is 
correct.)

and you have found that

  INSERT ON CONFLICT IGNORE

works quickly enough, but some records with duplicate keys are left unchanged
when you want to replace them.

The short answer to that is that I think you want

  INSERT ON CONFLICT REPLACE

and everything will be fine. But I am still unsure of your question, so please
come back and correct me.

Also I'm confused about why you think eval() should help. It is intended to
allow you to handle errors at run time that would otherwise crash the Perl
program, and I don't think that is what is happening here.

I'm especially concerned to hear that it crashed Perl when you tried it. Can you
post the code that did that please, or diagnose the source of the problem
yourself and report it as a bug.

HTH,

Rob

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


Reply via email to