First public contribution.
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "SqliteUtil.h"
17 #include "OstTraceDefinitions.h"
18 #ifdef OST_TRACE_COMPILER_IN_USE
19 #include "SqliteUtilTraces.h"
21 #include "SqliteTraceDef.h"
23 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25 #define UNUSED_ARG(arg) arg = arg
26 #define UNUSED_DES(arg) arg
28 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30 #if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_RDEBUG_PRINT
33 This class has been added here to avoid the crashes when _SQLITE_RDEBUG_PRINT macro is defined but the
34 data to be printed out is too big and cannot fit into the buffer with size KSqliteMaxPrnStrLen.
37 class TSqliteDes16Overflow : public TDes16Overflow
40 virtual void Overflow(TDes16& /*aDes*/)
47 //These are the differences in format specification between RDebig::Print and OST functions.
48 //The new format spec length should be less or equal than the old format spec length.
49 static void ReplaceFmtSpec(TDes& aFormat, const TDesC& aFmtSpec, const TDesC& aNewFmtSpec)
51 TInt fmtLength = aFormat.Length();
52 const TInt KDiff = aFmtSpec.Length() - aNewFmtSpec.Length();
53 TPtr ptr((TText*)aFormat.Ptr(), fmtLength, fmtLength);
55 while((pos = ptr.Find(aFmtSpec)) >= 0)
57 ptr.Replace(pos, aFmtSpec.Length(), aNewFmtSpec);
59 ptr.Set(ptr.MidTPtr(pos));
61 aFormat.SetLength(fmtLength);
64 void SqlitePrintf(TInt /*aGroupName*/, TInt /*aTraceName*/, const char* aFormat, ...)
67 VA_START(list, aFormat);
69 _LIT(KTraceIdent, "Sqlite3;");
70 format.Copy(TPtrC8((const TUint8*)aFormat));
71 format.Insert(0, KTraceIdent);
72 format.Append(_L("\r\n"));
73 _LIT(KOstI64Fmt, "%lld");
74 _LIT(KDbgPrnI64Fmt, "%ld");
75 ReplaceFmtSpec(format, KOstI64Fmt, KDbgPrnI64Fmt);
76 TBuf<KSqliteMaxPrnStrLen> buf;
77 TSqliteDes16Overflow overflowHandler;
78 buf.AppendFormatList(format, list, &overflowHandler);
79 #ifdef _SQLITE_RDEBUG_PRINT
80 RDebug::RawPrint(buf);
84 #endif//defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_RDEBUG_PRINT
86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89 SQLite panic category.
93 _LIT(KSqlitePanicCategory, "Sqlite3");
95 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98 Panics the caller with aPanicCode panic code.
99 The call will terminate the thread where it is called from.
101 @param aPanicCode Panic code.
105 static void SqlitePanic(TSqlitePanic aPanicCode)
107 User::Panic(KSqlitePanicCategory, aPanicCode);
110 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 The function prints out a "SQLite" panic message to the console and panics the thread where it is called from.
114 It gives a useful information about the found error together with the source file name and line number where
117 Note: this function will output information regarding the panic only if _SQLITE_PANIC_TRACE_ENABLED macro is defined
119 @param aFile Source file name
120 @param aLine Source line number
121 @param aPanicCode Panic code
122 @param aHandle Numeric value, uniquely identfying the leaving location (the "this" pointer for example)
128 TInt TSqliteUtil::Panic(const TText* aFile, TInt aLine, TInt aPanicCode, TUint aHandle)
130 #if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
131 TPtrC fname(FileName(aFile));
132 OstTraceExt5(TRACE_FATAL, TSQLUTIL_PANIC, "Panic;0x%X;%S;%d;%S;%d", aHandle, __SQLITEPRNSTR(fname), aLine, __SQLITEPRNSTR(KSqlitePanicCategory), aPanicCode);
138 ::SqlitePanic(static_cast <TSqlitePanic> (aPanicCode));
142 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144 #if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
147 The function creates and returns TPtrC object which points to aFile parameter.
149 @param aFile File name
150 @return TPtrC object pointing to aFile parameter.
154 TPtrC TSqliteUtil::FileName(const TText* aFile)
157 TInt ix = p.LocateReverse('\\');
159 ix=p.LocateReverse('/');
165 #endif //defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
167 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////