Mike I also was not able to reproduce this behavior with a small sample program and am puzzled by this behavior in my main application. What puzzled me is 1. Select has criteria a=?, b=?, c=? (prepare statement) - step through it 2. Get the value of d from database based on the above criteria 3. Update the value of d 4. The value of d has now been but the entire module within the step module is being re-run.
I have been able to get around this by calling sqlite3_clear_bindings and sqlite3_reset within the step. Black, Michael (IS) wrote: > > I think the quick answer is to use a different database handle for your > update. I think you may also be able to do this with WAL mode. > http://www.sqlite.org/draft/wal.html > I did some searching and couldn't find a definitive answer for doing an > update inside a select loop (though I'm sure I've seen it on this list > before). > > I was unable to duplicate your problem...perhaps you can modify this to > show it > > #include <stdio.h> > #include "sqlite3.h" > main() > { > sqlite3 *db; > sqlite3_stmt *stmt; > char *errmsg=NULL; > char *sql; > remove("update.db"); > sqlite3_open("update.db",&db); > sqlite3_exec(db,"CREATE TABLE t (a int, b int)",NULL,NULL,&errmsg); > sqlite3_exec(db,"insert into t values(1,1)",NULL,NULL,&errmsg); > sqlite3_exec(db,"insert into t values(1,2)",NULL,NULL,&errmsg); > sql = "SELECT * FROM t where a=1"; > sqlite3_prepare_v2(db,sql,strlen(sql),&stmt,NULL); > while(sqlite3_step(stmt)==SQLITE_ROW) { > char sqlbuf[4096]; > int ref; > ref = sqlite3_column_int(stmt,1); > printf("Before %d\n",ref); > sprintf(sqlbuf,"UPDATE t set b=b+1 where a=%d",ref); > puts(sqlbuf); > > sqlite3_exec(db,sqlbuf,NULL,NULL,&errmsg); > } > sqlite3_finalize(stmt); > sqlite3_close(db); > > } > > Michael D. Black > Senior Scientist > Advanced Analytics Directorate > Northrop Grumman Information Systems > > > > > -- View this message in context: http://old.nabble.com/sqlite3_step-to-select-and-update-the-same-table-tp30152284p30156751.html Sent from the SQLite mailing list archive at Nabble.com. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users