--- On Wed, 9/30/09, Scott Hess <sh...@google.com> wrote: > From: Scott Hess <sh...@google.com> > Subject: Re: [sqlite] multiple prepare statements > To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org> > Date: Wednesday, September 30, 2009, 9:02 AM > Since SQLite is an embedded database, > it generally does not pay to > count statements, unless they add additional disk > I/O. You can code > like this: > > BEGIN > SELECT ... > if (select results A) > INSERT ... > else > UPDATE ... > END > > and it will be about as fast as either the INSERT or the > UPDATE run > independently. This is because the INSERT or the > UPDATE will have to > read in all the pages the SELECT would have read in, so the > SELECT is > essentially free (just a small cost in CPU). Well, > assuming that your > SELECT is selecting the rows you mean to UPDATE or INSERT > ... > > -scott >
Depending upon your system and your data. Say you have some type of Primary Key or unique index. For the case where updates happen infrequently code this way. Begin Insert into .. IF PK failure Update Commit If you tend to load up the data then have more updates. Begin Update IF No data Found (0 rows updated) Insert Commit _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users