1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/OsLayer/SqliteUtil.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,167 @@
1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +#include <e32debug.h>
1.19 +#include "SqliteUtil.h"
1.20 +#include "OstTraceDefinitions.h"
1.21 +#ifdef OST_TRACE_COMPILER_IN_USE
1.22 +#include "SqliteUtilTraces.h"
1.23 +#endif
1.24 +#include "SqliteTraceDef.h"
1.25 +
1.26 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.27 +
1.28 +#define UNUSED_ARG(arg) arg = arg
1.29 +#define UNUSED_DES(arg) arg
1.30 +
1.31 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.32 +
1.33 +#if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_RDEBUG_PRINT
1.34 +
1.35 +/**
1.36 +This class has been added here to avoid the crashes when _SQLITE_RDEBUG_PRINT macro is defined but the
1.37 +data to be printed out is too big and cannot fit into the buffer with size KSqliteMaxPrnStrLen.
1.38 +@internalComponent
1.39 +*/
1.40 +class TSqliteDes16Overflow : public TDes16Overflow
1.41 + {
1.42 +public:
1.43 + virtual void Overflow(TDes16& /*aDes*/)
1.44 + {
1.45 + }
1.46 + };
1.47 +
1.48 +//Replaces:
1.49 +// "%lld" with "%ld"
1.50 +//These are the differences in format specification between RDebig::Print and OST functions.
1.51 +//The new format spec length should be less or equal than the old format spec length.
1.52 +static void ReplaceFmtSpec(TDes& aFormat, const TDesC& aFmtSpec, const TDesC& aNewFmtSpec)
1.53 + {
1.54 + TInt fmtLength = aFormat.Length();
1.55 + const TInt KDiff = aFmtSpec.Length() - aNewFmtSpec.Length();
1.56 + TPtr ptr((TText*)aFormat.Ptr(), fmtLength, fmtLength);
1.57 + TInt pos;
1.58 + while((pos = ptr.Find(aFmtSpec)) >= 0)
1.59 + {
1.60 + ptr.Replace(pos, aFmtSpec.Length(), aNewFmtSpec);
1.61 + fmtLength -= KDiff;
1.62 + ptr.Set(ptr.MidTPtr(pos));
1.63 + }
1.64 + aFormat.SetLength(fmtLength);
1.65 + }
1.66 +
1.67 +void SqlitePrintf(TInt /*aGroupName*/, TInt /*aTraceName*/, const char* aFormat, ...)
1.68 + {
1.69 + VA_LIST list;
1.70 + VA_START(list, aFormat);
1.71 + TBuf<128> format;
1.72 + _LIT(KTraceIdent, "Sqlite3;");
1.73 + format.Copy(TPtrC8((const TUint8*)aFormat));
1.74 + format.Insert(0, KTraceIdent);
1.75 + format.Append(_L("\r\n"));
1.76 + _LIT(KOstI64Fmt, "%lld");
1.77 + _LIT(KDbgPrnI64Fmt, "%ld");
1.78 + ReplaceFmtSpec(format, KOstI64Fmt, KDbgPrnI64Fmt);
1.79 + TBuf<KSqliteMaxPrnStrLen> buf;
1.80 + TSqliteDes16Overflow overflowHandler;
1.81 + buf.AppendFormatList(format, list, &overflowHandler);
1.82 +#ifdef _SQLITE_RDEBUG_PRINT
1.83 + RDebug::RawPrint(buf);
1.84 +#endif
1.85 + }
1.86 +
1.87 +#endif//defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_RDEBUG_PRINT
1.88 +
1.89 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.90 +
1.91 +/**
1.92 +SQLite panic category.
1.93 +
1.94 +@internalComponent
1.95 +*/
1.96 +_LIT(KSqlitePanicCategory, "Sqlite3");
1.97 +
1.98 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.99 +
1.100 +/**
1.101 +Panics the caller with aPanicCode panic code.
1.102 +The call will terminate the thread where it is called from.
1.103 +
1.104 +@param aPanicCode Panic code.
1.105 +
1.106 +@internalComponent
1.107 +*/
1.108 +static void SqlitePanic(TSqlitePanic aPanicCode)
1.109 + {
1.110 + User::Panic(KSqlitePanicCategory, aPanicCode);
1.111 + }
1.112 +
1.113 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.114 +
1.115 +/**
1.116 +The function prints out a "SQLite" panic message to the console and panics the thread where it is called from.
1.117 +It gives a useful information about the found error together with the source file name and line number where
1.118 +it occurred.
1.119 +
1.120 +Note: this function will output information regarding the panic only if _SQLITE_PANIC_TRACE_ENABLED macro is defined
1.121 +
1.122 +@param aFile Source file name
1.123 +@param aLine Source line number
1.124 +@param aPanicCode Panic code
1.125 +@param aHandle Numeric value, uniquely identfying the leaving location (the "this" pointer for example)
1.126 +
1.127 +@return KErrNone
1.128 +
1.129 +@internalComponent
1.130 +*/
1.131 +TInt TSqliteUtil::Panic(const TText* aFile, TInt aLine, TInt aPanicCode, TUint aHandle)
1.132 + {
1.133 +#if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
1.134 + TPtrC fname(FileName(aFile));
1.135 + OstTraceExt5(TRACE_FATAL, TSQLUTIL_PANIC, "Panic;0x%X;%S;%d;%S;%d", aHandle, __SQLITEPRNSTR(fname), aLine, __SQLITEPRNSTR(KSqlitePanicCategory), aPanicCode);
1.136 +#else
1.137 + UNUSED_ARG(aFile);
1.138 + UNUSED_ARG(aLine);
1.139 + UNUSED_ARG(aHandle);
1.140 +#endif
1.141 + ::SqlitePanic(static_cast <TSqlitePanic> (aPanicCode));
1.142 + return KErrNone;
1.143 + }
1.144 +
1.145 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.146 +
1.147 +#if defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
1.148 +
1.149 +/**
1.150 +The function creates and returns TPtrC object which points to aFile parameter.
1.151 +
1.152 +@param aFile File name
1.153 +@return TPtrC object pointing to aFile parameter.
1.154 +
1.155 +@internalComponent
1.156 +*/
1.157 +TPtrC TSqliteUtil::FileName(const TText* aFile)
1.158 + {
1.159 + TPtrC p(aFile);
1.160 + TInt ix = p.LocateReverse('\\');
1.161 + if(ix<0)
1.162 + ix=p.LocateReverse('/');
1.163 + if(ix>=0)
1.164 + p.Set(p.Mid(1+ix));
1.165 + return p;
1.166 + }
1.167 +
1.168 +#endif //defined OST_TRACE_COMPILER_IN_USE && defined _SQLITE_PANIC_TRACE_ENABLED
1.169 +
1.170 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////