diff -r 28839de615b4 -r 26645d81f48d persistentstorage/sql/SRC/Server/SqlSrvStatement.cpp --- a/persistentstorage/sql/SRC/Server/SqlSrvStatement.cpp Thu Aug 19 11:36:21 2010 +0300 +++ b/persistentstorage/sql/SRC/Server/SqlSrvStatement.cpp Tue Aug 31 16:57:14 2010 +0300 @@ -9,7 +9,7 @@ // Nokia Corporation - initial contribution. // // Contributors: -// NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings" +// NTT DOCOMO, INC - Fix for defect 1915 "SQL server panics when using long column type strings" // // Description: // @@ -21,7 +21,12 @@ #include "SqlSrvStatement.h" #include "SqlBufIterator.h" //TSqlBufRIterator #include "SqlSrvResourceProfiler.h" -#include "UTraceSql.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "SqlSrvStatementTraces.h" +#endif +#include "SqlTraceDef.h" + ////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// local const data //////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -137,14 +142,16 @@ */ CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC16& aSqlStmt, TInt& aColumnCount, TInt& aParamCount) { - __SQLASSERT(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, ESqlPanicBadArgument); + __SQLTRACE_INTERNALSEXPR(TPtrC sqlprnptr(aSqlStmt.Left(aSqlStmt.Length() - 1))); + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_ENTRY, "Entry;0;CSqlSrvStatement::NewLC-16;aDbHandle=0x%X;aSqlStmt=%S", (TUint)aDbHandle, __SQLPRNSTR(sqlprnptr))); + __ASSERT_DEBUG(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, __SQLPANIC2(ESqlPanicBadArgument)); CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement; CleanupStack::PushL(self); self->ConstructL(aDbHandle, aSqlStmt); - SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtCreated, self)); aColumnCount = self->iColumnCount; aParamCount = self->iParamCount; + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_EXIT, "Exit;0x%X;CSqlSrvStatement::NewLC-16;iStmtHandle=0x%X;aColumnCount=%d;aParamCount=%d", (TUint)self, (TUint)self->iStmtHandle, aColumnCount, aParamCount)); return self; } @@ -169,14 +176,17 @@ */ CSqlSrvStatement* CSqlSrvStatement::NewLC(sqlite3* aDbHandle, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount) { - __SQLASSERT(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, ESqlPanicBadArgument); + __SQLTRACE_INTERNALSEXPR(TPtrC8 sqlprnptr(aSqlStmt.Left(aSqlStmt.Length() - 1))); + __SQLTRACE_INTERNALSVAR(TBuf<100> des16prnbuf); + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_ENTRY2, "Entry;0;CSqlSrvStatement::NewLC-8;aDbHandle=0x%X;aSqlStmt=%s", (TUint)aDbHandle, __SQLPRNSTR8(sqlprnptr, des16prnbuf))); + __ASSERT_DEBUG(aSqlStmt.Length() > 0 ? (TInt)aSqlStmt[aSqlStmt.Length() - 1] == 0 : ETrue, __SQLPANIC2(ESqlPanicBadArgument)); CSqlSrvStatement* self = new (ELeave) CSqlSrvStatement; CleanupStack::PushL(self); self->ConstructL(aDbHandle, aSqlStmt); - SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtCreated, self)); aColumnCount = self->iColumnCount; aParamCount = self->iParamCount; + SQL_TRACE_INTERNALS(OstTraceExt4(TRACE_INTERNALS, CSQLSRVSTATEMENT_NEWLC_EXIT2, "Exit;0x%X;CSqlSrvStatement::NewLC-8;iStmtHandle=0x%X;aColumnCount=%d;aParamCount=%d", (TUint)self, (TUint)self->iStmtHandle, aColumnCount, aParamCount)); return self; } @@ -185,17 +195,19 @@ */ CSqlSrvStatement::~CSqlSrvStatement() { + SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2_ENTRY, "Entry;0x%X;CSqlSrvStatement::~CSqlSrvStatement;iStmtHandle=0x%X", (TUint)this, (TUint)iStmtHandle)); DestroyParamBufArray(); iBufFlat.Close(); if(iStmtHandle) { -#ifdef SYMBIAN_TRACE_SQL_EVENTS - TInt scanCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_FULLSCAN_STEP, ETrue); - TInt sortCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_SORT, ETrue); - SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KSrvStmtStatus, this, scanCount, sortCount)); -#endif +#ifdef SYMBIAN_USE_SQLITE_VERSION_3_6_4 + __SQLTRACE_INTERNALSEXPR(TInt scanCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_FULLSCAN_STEP, ETrue)); + __SQLTRACE_INTERNALSEXPR(TInt sortCount = sqlite3_stmt_status(iStmtHandle, SQLITE_STMTSTATUS_SORT, ETrue)); + SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2, "0x%X;CSqlSrvStatement::~CSqlSrvStatement;scan count=%d;sort count=%d", (TUint)this, scanCount, sortCount)); +#endif (void)sqlite3_finalize(iStmtHandle); } + SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSRVSTATEMENT_CSQLSRVSTATEMENT2_EXIT, "Exit;0x%X;CSqlSrvStatement::~CSqlSrvStatement", (TUint)this)); } /** @@ -214,7 +226,7 @@ */ void CSqlSrvStatement::BindL(const RSqlBufFlat& aParamBuf) { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); (void)sqlite3SymbianLastOsError();//clear last OS error @@ -282,7 +294,7 @@ */ const RSqlBufFlat& CSqlSrvStatement::ColumnNamesL() { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); iBufFlatType = static_cast (-1); __SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount)); TSqlBufWIterator it; @@ -311,7 +323,7 @@ */ const RSqlBufFlat& CSqlSrvStatement::ParamNamesL() { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); iBufFlatType = static_cast (-1); __SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iParamCount)); TSqlBufWIterator it; @@ -353,7 +365,7 @@ */ const RSqlBufFlat& CSqlSrvStatement::ColumnValuesL() { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); iBufFlatType = static_cast (-1); iBufFlat.SetCount(iColumnCount); @@ -393,7 +405,7 @@ {//sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed. const TUint16* text = reinterpret_cast (sqlite3_column_text16(iStmtHandle, colIdx)); - __SQLASSERT(text != NULL, ESqlPanicInternalError); + __ASSERT_DEBUG(text != NULL, __SQLPANIC(ESqlPanicInternalError)); __SQLLEAVE_IF_ERROR(it.SetText(TPtrC16(text, charLength))); } } @@ -415,7 +427,7 @@ it.SetNull(); break; default: - __SQLASSERT(EFalse, ESqlPanicInternalError); + __ASSERT_DEBUG(EFalse, __SQLPANIC(ESqlPanicInternalError)); break; }//end of switch(...) }//end of - while(it.Next()) @@ -437,15 +449,15 @@ */ TInt CSqlSrvStatement::ColumnSource(TInt aColumnIndex, TPtrC8& aColumnSource) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); TInt colType = sqlite3_column_type(iStmtHandle, aColumnIndex); if(colType == SQLITE_TEXT) {//Since the first called function after the Next() operation is always CSqlSrvStatement::ColumnValuesL(), then //sqlite3_column_bytes16() (called from ColumnValuesL()) already allocated the needed memory if a UTF8->UTF16 //conversion had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed. const void* text = sqlite3_column_text16(iStmtHandle, aColumnIndex); - __SQLASSERT(text != NULL, ESqlPanicInternalError); - TInt length = sqlite3_column_bytes16(iStmtHandle, aColumnIndex); + __ASSERT_DEBUG(text != NULL, __SQLPANIC2(ESqlPanicInternalError)); + TInt length = sqlite3_column_bytes16(iStmtHandle, aColumnIndex); aColumnSource.Set(reinterpret_cast (text), length); } else if(colType == SQLITE_BLOB) @@ -468,7 +480,7 @@ */ void CSqlSrvStatement::DoCommonConstructL() { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); iColumnCount = sqlite3_column_count(iStmtHandle); iParamCount = sqlite3_bind_parameter_count(iStmtHandle); __SQLLEAVE_IF_ERROR(iBufFlat.SetCount(Max(iColumnCount, iParamCount))); @@ -507,10 +519,10 @@ */ void CSqlSrvStatement::BindParamBufL(TInt aParamIndex) { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument); - __SQLASSERT(aParamIndex < iParamBufArray.Count(), ESqlPanicBadArgument); - __SQLASSERT(iParamBufArray[aParamIndex] != NULL, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument)); + __ASSERT_DEBUG(aParamIndex < iParamBufArray.Count(), __SQLPANIC(ESqlPanicBadArgument)); + __ASSERT_DEBUG(iParamBufArray[aParamIndex] != NULL, __SQLPANIC(ESqlPanicBadArgument)); (void)sqlite3SymbianLastOsError();//clear last OS error //Bind the parameter value. //SQLITE_STATIC is used as an argument, because the text/blob data will be kept and can be used by the next bind call @@ -546,8 +558,8 @@ */ TInt CSqlSrvStatement::ColumnInt(TInt aColIdx) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument)); TInt colType = sqlite3_column_type(iStmtHandle, aColIdx); switch(colType) { @@ -586,8 +598,8 @@ */ TInt64 CSqlSrvStatement::ColumnInt64(TInt aColIdx) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument)); TInt colType = sqlite3_column_type(iStmtHandle, aColIdx); switch(colType) { @@ -623,8 +635,8 @@ */ TReal CSqlSrvStatement::ColumnReal(TInt aColIdx) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument)); TInt colType = sqlite3_column_type(iStmtHandle, aColIdx); switch(colType) { @@ -657,8 +669,8 @@ */ TPtrC CSqlSrvStatement::ColumnTextL(TInt aColIdx) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument)); TPtrC res; TInt colType = sqlite3_column_type(iStmtHandle, aColIdx); if(colType == SQLITE_TEXT) @@ -673,8 +685,8 @@ //sqlite3_column_bytes16() already allocated the needed memory if a UTF8->UTF16 conversion //had to be performed. The sqlite3_column_text16() on the next line is guaranteed to succeed. const TUint16* text = reinterpret_cast (sqlite3_column_text16(iStmtHandle, aColIdx)); - __SQLASSERT(text != NULL, ESqlPanicInternalError); - res.Set(text, charLength); + __ASSERT_DEBUG(text != NULL, __SQLPANIC(ESqlPanicInternalError)); + res.Set(text, charLength); } return res; } @@ -692,8 +704,8 @@ */ TPtrC8 CSqlSrvStatement::ColumnBinary(TInt aColIdx) const { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT((TUint)aColIdx < iColumnCount, ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG((TUint)aColIdx < iColumnCount, __SQLPANIC(ESqlPanicBadArgument)); TPtrC8 res; TInt colType = sqlite3_column_type(iStmtHandle, aColIdx); if(colType == SQLITE_BLOB) @@ -716,8 +728,8 @@ */ const RSqlBufFlat& CSqlSrvStatement::GetDeclColumnTypesL() { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - iBufFlatType = static_cast (-1); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + iBufFlatType = static_cast (-1); __SQLLEAVE_IF_ERROR(iBufFlat.SetCount(iColumnCount)); TSqlBufWIterator it; it.Set(iBufFlat); @@ -761,12 +773,12 @@ HSqlSrvStmtParamBuf* CSqlSrvStatement::GetParamBufL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, HSqlSrvStmtParamBuf::TBufType aBufType) { - __SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument); + __ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument)); ExtendParamBufArrayL(aParamIndex); HSqlSrvStmtParamBuf*& paramBuf = iParamBufArray[aParamIndex]; if(paramBuf) {//Reset and reuse the existing buffer - __SQLASSERT(paramBuf->ParamIndex() == aParamIndex, ESqlPanicInternalError); + __ASSERT_DEBUG(paramBuf->ParamIndex() == aParamIndex, __SQLPANIC(ESqlPanicInternalError)); paramBuf->Reset(aDataType, aBufType); } else @@ -789,8 +801,8 @@ */ void CSqlSrvStatement::ExtendParamBufArrayL(TInt aParamIndex) { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument)); TInt ext = aParamIndex - iParamBufArray.Count() + 1; while(ext-- > 0) { @@ -815,8 +827,8 @@ */ TPtrC8 CSqlSrvStatement::CopyAndStoreParamL(TInt aParamIndex, HSqlSrvStmtParamBuf::TDataType aDataType, const TDesC8& aParamValue) { - __SQLASSERT(iStmtHandle != NULL, ESqlPanicInvalidObj); - __SQLASSERT(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), ESqlPanicBadArgument); + __ASSERT_DEBUG(iStmtHandle != NULL, __SQLPANIC(ESqlPanicInvalidObj)); + __ASSERT_DEBUG(aParamIndex >= 0 && aParamIndex < sqlite3_bind_parameter_count(iStmtHandle), __SQLPANIC(ESqlPanicBadArgument)); HSqlSrvStmtParamBuf* paramBuf = GetParamBufL(aParamIndex, aDataType, HSqlSrvStmtParamBuf::EBufSimpleBind); return paramBuf->SetDataL(aParamValue); }