diff -r d6ef85bc5971 -r a7ba600cb39d persistentstorage/sql/SRC/Server/SqlSrvStatementUtil.cpp --- a/persistentstorage/sql/SRC/Server/SqlSrvStatementUtil.cpp Fri May 14 17:36:33 2010 +0300 +++ b/persistentstorage/sql/SRC/Server/SqlSrvStatementUtil.cpp Thu May 27 14:29:47 2010 +0300 @@ -203,6 +203,7 @@ static TInt DoSingleStmtExec16(sqlite3 *aDbHandle, const TDesC16& aSql) { __SQLASSERT(aDbHandle != NULL, ESqlPanicInvalidObj); + __SQLASSERT(aSql.Length() > 0 ? (TInt)aSql[aSql.Length() - 1] == 0 : ETrue, ESqlPanicBadArgument); sqlite3_stmt* stmtHandle = NULL; const void* stmtTail = NULL; //sqlite3_prepare16_v2() expects parameter #3 to be one of the following: @@ -223,11 +224,7 @@ __SQLASSERT(err != SQLITE_OK, ESqlPanicInternalError); } } - TInt err2 = sqlite3_finalize(stmtHandle); - if(err == SQLITE_DONE && err2 != SQLITE_OK) - {//return the "sqlite3_finalize" error - err = err2; - } + (void)sqlite3_finalize(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed. } return err; } @@ -423,15 +420,21 @@ // - aHasTail is true (possibly more than one SQL statement, separated with ";"); // - aStmtHandle is NULL; // -static TInt ProcessPrepareError(TInt aSqliteError, TBool aHasTail, sqlite3_stmt* aStmtHandle) +static TInt ProcessPrepareError(TInt aSqliteError, TBool aHasTail, sqlite3_stmt*& aStmtHandle) { if(aSqliteError != SQLITE_OK) { return ::Sql2OsErrCode(aSqliteError, sqlite3SymbianLastOsError()); } else if(aHasTail || !aStmtHandle) - {//More than one SQL statement or the SQL string is "" or ";;;" or "; ;; ;". - //Report it as an error, because there is no statement handle. + {//Case 1: + // More than one SQL statement or the SQL string is "" or ";;;" or "; ;; ;". + // Report it as an error, because there is no statement handle. + //Case 2: + // Non-null aHasTail. In this case the SQL string contains more than one SQL statement. + // The statement handle is not null. The statement has to be finialized before reporting the error. + (void)FinalizeStmtHandle(aStmtHandle); + aStmtHandle = NULL; return KErrArgument; } return KErrNone; @@ -544,12 +547,7 @@ __SQLASSERT(aStmtHandle != NULL, ESqlPanicInvalidObj); (void)sqlite3SymbianLastOsError();//clear last OS error - - if(sqlite3_expired(aStmtHandle)) - { - return KSqlErrStmtExpired; - } - + TInt err; while((err = sqlite3_step(aStmtHandle)) == SQLITE_ROW) { @@ -594,11 +592,6 @@ (void)sqlite3SymbianLastOsError();//clear last OS error - if(sqlite3_expired(aStmtHandle)) - { - return KSqlErrStmtExpired; - } - TInt err = sqlite3_step(aStmtHandle); if(err == SQLITE_ERROR) //It may be "out of memory" problem { @@ -628,11 +621,6 @@ (void)sqlite3SymbianLastOsError();//clear last OS error - if(sqlite3_expired(aStmtHandle)) - { - return KSqlErrStmtExpired; - } - TInt err = sqlite3_reset(aStmtHandle); return ::Sql2OsErrCode(err, sqlite3SymbianLastOsError()); } @@ -711,14 +699,9 @@ if(err == KSqlAtRow) { aPragmaValue = sqlite3_column_int(stmtHandle, 0); - __SQLASSERT(aPragmaValue >= 0, ESqlPanicInternalError); - err = KErrNone; + err = aPragmaValue >= 0 ? KErrNone : KErrCorrupt; } - TInt err2 = FinalizeStmtHandle(stmtHandle); - if(err == KErrNone && err2 != KErrNone) - {//FinalizeStmtHandle() has failed - err = err2; - } + (void)FinalizeStmtHandle(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed. return err; } @@ -752,11 +735,7 @@ aPragmaValue.Copy(ptr); err = KErrNone; } - TInt err2 = FinalizeStmtHandle(stmtHandle); - if(err == KErrNone && err2 != KErrNone) - {//::FinalizeStmtHandle() has failed - err = err2; - } + (void)FinalizeStmtHandle(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed. return err; } @@ -987,11 +966,7 @@ __SQLASSERT(err != SQLITE_OK, ESqlPanicInternalError); } } - TInt err2 = sqlite3_finalize(stmtHandle); - if(err == SQLITE_DONE && err2 != SQLITE_OK) - {//use the "sqlite3_finalize" error - err = err2; - } + (void)sqlite3_finalize(stmtHandle);//sqlite3_finalize() fails only if an invalid statement handle is passed. } err = ::Sql2OsErrCode(err, sqlite3SymbianLastOsError()); if(err == KSqlAtEnd) @@ -1004,6 +979,11 @@ /** Finalizes the statement handle. +Although the function can return an error, it is ok not to check the returned error, +because sqlite3_finalize() fails only if invalid statement handle is passed as an argument. + +@return KErrNone, Operation completed successfully; + Other system-wide error codes or SQL errors of ESqlDbError type. @internalComponent */