Here is the snippet of code:

int GetMessageFromDB(char *MD5Sum, struct ReceiveNode *FromDb)
{
   int ReturnCode;
   sqlite3_stmt *SelectStmtHandle;

   sprintf(SqlString, "SELECT SrcIp, DstIp, TimeStamp, SrcPort, DstPort, SeqNum
   ReturnCode = sqlite3_prepare(DbHandle, SqlString, -1, &SelectStmtHandle, NULL
   if (ReturnCode != SQLITE_OK || SelectStmtHandle == NULL)
   {
      sqlite3_reset(SelectStmtHandle);
      printf("Cannot prepare select statement. %s\n", sqlite3_errmsg(DbHandle));
      return(2);
   }

   sqlite3_bind_text(SelectStmtHandle, 1, MD5Sum, strlen(MD5Sum), SQLITE_TRANSIE
   ReturnCode = sqlite3_step(SelectStmtHandle);
   if (ReturnCode != SQLITE_ROW)
   {
      sqlite3_reset(SelectStmtHandle);
      printf("Row not found. ReturnCode: %d, Error Message:%s, Error Code: %d\n"
             ReturnCode, sqlite3_errmsg(DbHandle), sqlite3_errcode(DbHandle));
      return(2);
   }

   strcpy(FromDb->SourceIP, sqlite3_column_text(SelectStmtHandle, 0));
   strcpy(FromDb->DestIP, sqlite3_column_text(SelectStmtHandle, 1));
   strcpy(FromDb->TimeStamp, sqlite3_column_text(SelectStmtHandle, 2));
   FromDb->SourcePort = sqlite3_column_int(SelectStmtHandle, 3);
   FromDb->DestPort = sqlite3_column_int(SelectStmtHandle, 4);
   FromDb->SeqNum = sqlite3_column_int(SelectStmtHandle, 5);
   strncpy(FromDb->MD5Sum, MD5Sum, MD5SUMLEN);
   sqlite3_finalize(SelectStmtHandle);
   return(1);
}

int GetMessageFromDB(char *MD5Sum, struct ReceiveNode *FromDb)
{
   int ReturnCode;
   sqlite3_stmt *SelectStmtHandle;

   sprintf(SqlString, "SELECT SrcIp, DstIp, TimeStamp, SrcPort, DstPort, SeqNum
   ReturnCode = sqlite3_prepare(DbHandle, SqlString, -1, &SelectStmtHandle, NULL
   if (ReturnCode != SQLITE_OK || SelectStmtHandle == NULL)
   {
      sqlite3_reset(SelectStmtHandle);
      printf("Cannot prepare select statement. %s\n", sqlite3_errmsg(DbHandle));
      return(2);
   }

   sqlite3_bind_text(SelectStmtHandle, 1, MD5Sum, strlen(MD5Sum), SQLITE_TRANSIE
   ReturnCode = sqlite3_step(SelectStmtHandle);
   if (ReturnCode != SQLITE_ROW)
   {
      sqlite3_reset(SelectStmtHandle);
      printf("Row not found. ReturnCode: %d, Error Message:%s, Error Code: %d\n"
             ReturnCode, sqlite3_errmsg(DbHandle), sqlite3_errcode(DbHandle));
      return(2);
   }

   strcpy(FromDb->SourceIP, sqlite3_column_text(SelectStmtHandle, 0));
   strcpy(FromDb->DestIP, sqlite3_column_text(SelectStmtHandle, 1));
   strcpy(FromDb->TimeStamp, sqlite3_column_text(SelectStmtHandle, 2));
   FromDb->SourcePort = sqlite3_column_int(SelectStmtHandle, 3);
   FromDb->DestPort = sqlite3_column_int(SelectStmtHandle, 4);
   FromDb->SeqNum = sqlite3_column_int(SelectStmtHandle, 5);
   strncpy(FromDb->MD5Sum, MD5Sum, MD5SUMLEN);
   sqlite3_finalize(SelectStmtHandle);
   return(1);
}

if (FindDuplicateMessage(ReceiveBuf) == 1)
{
    GetMessageFromDB(ReceiveBuf.MD5Sum, &FromDb);
}



When I execute this functions I get following output.


Cannot insert into database. column MD5Sum is not unique
error code = SQLITE_CONSTRAINT
Row not found. ReturnCode: 101, Error Message:not an error, Error Code: 0


101 is SQLITE_DONE. So I get SQLITE_DONE instead of SQLITE_ROW.



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


--- On Sun, 9/26/10, Black, Michael (IS) <michael.bla...@ngc.com> wrote:

> From: Black, Michael (IS) <michael.bla...@ngc.com>
> Subject: Re: [sqlite] sqlite cannot find the row
> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org>
> Date: Sunday, September 26, 2010, 8:14 AM
> 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
> 
> 
> 
> -----Inline Attachment Follows-----
> 
> _______________________________________________
> 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