Your code is chopped off and I suspect the problem is on the remainder of this line: sprintf(SqlString, "SELECT SrcIp, DstIp, TimeStamp, SrcPort, DstPort, SeqNum
For example, did you put single quotes around the ? parameter? Michael D. Black Senior Scientist Advanced Analytics Directorate Northrop Grumman Information Systems ________________________________ From: sqlite-users-boun...@sqlite.org on behalf of Hemant Shah Sent: Mon 9/27/2010 2:22 PM To: General Discussion of SQLite Database Subject: EXTERNAL:Re: [sqlite] sqlite cannot find the row 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
_______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users