0

Ok i thought i had fixed my lawnchair problem but it appears I havent:(

What I am trying to do is the following will post code chunks below 1. Parse XML 2. Check if a certain item (from XML) already exisits in my DB. 3. If it doesnt then add it in to the DB

It appears I am obviously going recklessly wrong with my callback function as ALL the entries get added If i simply save to the DB within my actual XML get method. As soon as i place the save method in my checkExists conditional then I get a get a SQL error :

error in sqlite adaptor! SQLTransaction SQLError) 1. code: 1 2. message: "constraint failed" and only one entry is added.

Code chunk below:

function getEpisodeList(xml) 
            { 
                $(xml).find('episode').each(function(){ 
                    comicObj= new Object(); 
                    var name = $(this).find('comic_name').text(); 
                    comicObj.name = unescape(name) 
                    comicObj.cellTotal = $(this).find('cells').text(); 
                    comicObj.id = $(this).find('comic_id').text(); 
                    comicObj.purchased =  $(this).find('purchased').text() 
                    comicObj.seriesId = $(xml).find('series').attr("id"); 
                    comics.get(comicObj.id, function(r) 
                    { 
                       checkExists(r, comicObj) 
                    } 
                    ) 
 }); // END OF XML FIND 

 function checkExists(record, comicObj) 
            { 
                if(record != null) 
                { 
                console.log("this exists") 
                } else 
                { 
                console.log("this doesnt exist") 
                comics.save({key:comicObj.id, 
purchased:comicObj.purchased}); 
                } 
            } 

Any help on this would be very much appreciated thx in advance ade

user821902
  • 140
  • 1
  • 8

1 Answers1

1

I don't know Lawnchair very well, but could you just use the exists method?

Sam Dutton
  • 14,775
  • 6
  • 54
  • 64