Well , since I do need to avoid a case where duplicated tags are inserted ,I 
have added a treatment to the case of SQLITE_CONSTRAINT.
 I am just curious whether I need to call sqlite3_finalize(Statement)  after 
sqlite3_step(Statement) returns SQLITE_CONSTRAINT 
so that the memory that was allocated at sqlite3_mprintf  be released ? 
 
  
Here are the table defenitions :
CREATE TABLE 'Inventory' (
'TagIndex' integer PRIMARY KEY,
'Tag' varchar(12) NOT NULL,
) ;
CREATE UNIQUE INDEX InventoryIndex ON Inventory (Tag);

My code looks like this:

query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)");
rc=sqlite3_prepare_v2(DB,query ,-1,&Statement,NULL);
if (rc!=SQLITE_OK)
    error_print();

sqlite3_exec(db,"BEGIN;",NULL,NULL,&err);
for (i=1;i<500;i ++)
{
    rc=sqlite3_bind_text(Statement,1,list[i],-1,NULL);
    if (rc!=SQLITE_OK)
        error_print();
    rc=sqlite3_step(Statement);
    if (rc!=SQLITE_DONE)
    {
         if (rc==SQLITE_CONSTRAINT )  
        {
              query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)");
              rc=sqlite3_prepare_v2(DB,query ,-1,&Statement,NULL);
              if (rc!=SQLITE_OK)
                error_print();
        }
        error_print();
    }            
    sqlite3_reset(Statement) ;
}
sqlite3_finalize(Statement) ;

sqlite3_exec(db,"END;",NULL,NULL,&err) ;

 
 
 
 
 
 
 
 
 


 
----- Original Message ----
From: Dennis Cote <[EMAIL PROTECTED]>
To: General Discussion of SQLite Database <[email protected]>
Sent: Monday, March 17, 2008 11:10:35 PM
Subject: Re: [sqlite] SQLITE_CONSTRAINT error after sqlite3_step

Vincent Vega wrote:
> Thanks a lot . Your explantion does make sence.
> I'll remove the UNIQUE index and see if it helps.
> 

You probably shouldn't remove the index, just remove the unique keyword 
from the create index statement.

create index InventoryIndex on Inventory (Tag);

If you have an existing database you can drop the old index and create 
the new index without losing any data.

HTH
Dennis Cote
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to