[sqlite] Update problem in use C/C++ interface
Hi, I meet a problem in use c/c++ API to update a row in table. all return value means the operate is successful, But the row have no change at all. and the INSERT , SELECT operation is OK. I think maybe I'm not first one meet this problem.But I can't visit the archive. So if anyone here know about this problem,please help me. the main code al follow: wstring sql = LUPDATE Mail SET [Content] = ?1 [CurrentSize] = ?2 WHERE [MailID] = ?3;; sqlite3_stmt *pstmt = NULL; const char *pzTail = 0; int nRes = SQLITE_OK; nRes = sqlite3_prepare16_v2((sqlite3*)pDB, (void**)sql.c_str(), sizeof(wchar_t) * sql.length(), pstmt, 0); if (0 != nRes) { return -1; } do { int len = 0; void* pdata = NULL; //Content pdata = (void*)pMail-m_content.c_str(); len = sizeof(wchar_t) * pMail-m_content.length(); if( SQLITE_OK != (nRes = sqlite3_bind_text16(pstmt, 1, pdata, len, SQLITE_TRANSIENT)) )break; //CurrentSize if( SQLITE_OK != (nRes = sqlite3_bind_int(pstmt, 2, pMail-m_curSize)) )break; if( SQLITE_OK != (nRes = sqlite3_bind_int(pstmt, 3, pMail-GetID())) )break; if ( SQLITE_DONE != (nRes = sqlite3_step(pstmt)) ) break; }while (0); sqlite3_finalize(pstmt); if(SQLITE_OK != nRes SQLITE_DONE != nRes) { return -1; } else { return 0; } -- -- Thanks! 王志刚 --- 电话:021-62672000-2852 上海圣诺网络技术有限公司 --- ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Update problem in use C/C++ interface
??? wrote: Hi, I meet a problem in use c/c++ API to update a row in table. all return value means the operate is successful, But the row have no change at all. How do you determine this? the main code al follow: wstring sql = LUPDATE Mail SET [Content] = ?1 [CurrentSize] = ?2 WHERE [MailID] = ?3;; There should be a comma after ?1. Are you sure there actually exists a record with the ID you bind for the third parameter? Note that, if there isn't, you won't get any errors - the statement simply won't update any rows. sqlite3_stmt *pstmt = NULL; const char *pzTail = 0; int nRes = SQLITE_OK; nRes = sqlite3_prepare16_v2((sqlite3*)pDB, (void**)sql.c_str(), sizeof(wchar_t) * sql.length(), pstmt, 0); Why do you need to cast pDB? What type is it declared with? The second parameter of sqlite3_prepare16_v2 is const void*, not void**. Your cast looks strange, though harmless. You shouldn't need any cast at all. -- Igor Tandetnik about the comma after ?1. is a mistake when i paste code into mail. I simplify some code, so miss the comma. and i'm sure there is a record with the ID bind for the third parameter. and the cast pDB,it's no matter.our interface declear is as void*. -- Thanks! 王志刚 --- 电话:021-62672000-2852 上海圣诺网络技术有限公司 --- ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users