Try showing us your code...sounds like you're doing something wrong if the 
query works elsewhere.
 
Here's my simple example that does something similar to what you describe:
 
#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>0";
        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 a=a+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
 

________________________________

From: sqlite-users-boun...@sqlite.org on behalf of Jim Crafton
Sent: Fri 11/19/2010 2:25 PM
To: sqlite-users@sqlite.org
Subject: EXTERNAL:[sqlite] problem reading a row of data



I'm trying to use a select statement to read a row of data from a DB.
I have created the db myself, using another program that uses sqlite,
and have verified (using a gui SQlite db browser) that the file does
in fact have data in it (2 tables, both about 1.3 million rows, the
file is around 150Mb in size).

The table schema (for the one I'm interested in) looks like so:

CREATE TABLE IF NOT EXISTS RFLogIndex ( idxID INTEGER PRIMARY KEY,
masterSequence INTEGER,  logFileOffset INTEGER );

After opening the db with sqlite3_open() I attempt to execute a select
statement.

The select statement I'm trying to execute is trivial:

select * from RFLogIndex where idxID = 1;

I do this using sqlite3_prepare() and that returns SQLITE_OK

I call sqlite3_step() and get a return code of SQLITE_DONE (101),
implying there's no data! Which is most definitely NOT correct,
because when I run the same query in the GUI browser, I get exactly 1
row back, as expected.

The code is running in a simple command line program, so no extra
threads. I've built sqlite myself (running on Windows XP SP 3 32bit,
Visual Studio 2008), and I'm using it successfully in other programs
and they all query just fine.

I'm doing something wrong, but I just can't see it yet. Any ideas?

Thanks

Jim
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to