You don't provide enough into to tell what the problem is.
 
This works for me...so what did you do different?  Simplify your problem to a 
complete example like this and we can help better...
 
 
#include <stdio.h>
#include "sqlite3.h"
int main()
{
 int rc;
 char *md5sum="dd5b8911bf377682d8963a859b8c2055";
 sqlite3 *db;
 sqlite3_stmt *stmt;
 remove("test.db");
 sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
 sqlite3_prepare(db, "CREATE TABLE t (md5sum varchar)", -1,&stmt, 0);
 rc = sqlite3_step(stmt);
 if (rc != SQLITE_DONE) printf("CREATE %d %s\n",rc,sqlite3_errmsg(db));
 sqlite3_prepare(db,"INSERT INTO t VALUES(?)",-1,&stmt, 0);
 sqlite3_bind_text(stmt,1,md5sum,-1,SQLITE_TRANSIENT);
 rc = sqlite3_step(stmt);
 if (rc != SQLITE_DONE) printf("INSERT: %d %s\n",rc,sqlite3_errmsg(db));
 sqlite3_prepare(db,"SELECT * FROM t WHERE md5sum=?",-1,&stmt, 0);
 sqlite3_bind_text(stmt,1,md5sum,-1,SQLITE_TRANSIENT);
 rc = sqlite3_step(stmt);
 if (rc==SQLITE_ROW) {
  const char *s=sqlite3_column_text(stmt,0);
  printf("%s\n",s);  
 }
 else {
  printf("SELECT %d %s\n",rc,sqlite3_errmsg(db));
 }
 sqlite3_close(db);
 return 0;
}
 
Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Northrop Grumman Information Systems
 

________________________________

From: sqlite-users-boun...@sqlite.org on behalf of Hemant Shah
Sent: Sat 9/25/2010 8:53 PM
To: General Discussion of SQLite Database
Subject: EXTERNAL:[sqlite] sqlite cannot find the row



Folks

I have a C program that creates in-memory database with unique column.
My code basically inserts row in database and if it gets duplicate row it 
selects the duplicate row from database and prints information.

The problem is that when I select the row it says row not found.

I simplified the code as follows:

sqlite3_prepare("insert statement")
sqlite3_bind columns
sqlite3_step
sqlite3_finalize
sqlite3_exec COMMIT

When I insert the row I get following error message:

column MD5Sum is not unique

So I immediately do a select as follows:

sqlite3_prepare("select statement")
sqlite3_bind column
sqlite3_step
sqlite3_finalize


But I do not get SQLITE_ROW return code. Here is my code.

sqlite3_prepare(select statement)
sqlite3_bind_text(SelectStmtHandle, 1, MD5Sum, strlen(MD5Sum), 
SQLITE_TRANSIENT);
ReturnCode = sqlite3_step(SelectStmtHandle);
if (ReturnCode != SQLITE_ROW)
{
   sqlite3_reset(SelectStmtHandle);
   printf("Row not found. %s\n", sqlite3_errmsg(DbHandle));
   return(2);
}

Here is the message it prints:

Row not found. not an error

I am new to sqlite, what am I doing wrong?
What return code should I get if there is only one row in result set?

I print the columns before I do insert and I can see that I have duplicate row. 
Sixth column (MD5SUM) is the unique column.

1219   10.136.28.112    44376  239.56.112.112     8146 
dd5b8911bf377682d8963a859b8c2055 2010-09-24 14.11.07.545436
1219   10.136.28.112    44376  239.56.112.112     8146 
dd5b8911bf377682d8963a859b8c2055 2010-09-24 14.11.07.545855





Hemant Shah
E-mail: hj...@yahoo.com


     
_______________________________________________
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