persistentstorage/sql/OsLayer/SqliteUtil.h
author hgs
Tue, 06 Jul 2010 11:54:49 +0100
changeset 31 ba1c4f4a893f
permissions -rw-r--r--
201025_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     2
// All rights reserved.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     7
//
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     8
// Initial Contributors:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    10
//
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    11
// Contributors:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    12
//
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    13
// Description:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    14
//
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    15
#ifndef SQLITEUTIL_H
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    16
#define SQLITEUTIL_H
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    17
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    18
#include <e32std.h>
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    19
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    20
/**
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    21
Panic codes - used by asserts in the OS porting layer and the file buffer.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    22
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    23
@see KPanicCategory
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    24
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    25
@internalComponent
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    26
*/
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    27
enum TSqlitePanic
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    28
	{
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    29
	ESqliteOsPanicNullOsLayerDataPtr	= 1,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    30
	ESqliteOsPanicInvalidWAmount 		= 2,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    31
	ESqliteOsPanicOffset64bit 			= 3,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    32
	ESqliteOsPanicInvalidOpType			=11,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    33
	ESqliteOsPanicInvalidFhStr			=12,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    34
	ESqliteOsPanicInvalidFhData			=13,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    35
	ESqliteOsPanicInvalidArg			=14,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    36
	ESqliteOsPanicInvalidRAmount 		=15,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    37
	ESqliteOsPanicOsLayerDataExists		=16,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    38
	ESqliteOsPanicInvalidDrive			=17,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    39
	ESqliteOsPanicInvalidSectorSize		=18,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    40
	ESqliteOsPanicInternalError			=19,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    41
	ESqliteOsPanicNullDbFilePtr			=20,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    42
	ESqliteOsPanicFastCounterFreq		=21,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    43
	//
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    44
	EFBufPanicCapacity					=101,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    45
	EFBufPanicNullBuf					=102,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    46
	EFBufPanicBufLen					=103,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    47
	EFBufPanicFilePos					=104,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    48
	EFBufPanicFileSize					=105,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    49
	EFBufPanicFileHandle				=106,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    50
	EFBufPanicFsHandle					=107,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    51
	EFBufPanicMsgHandle					=108,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    52
	EFBufPanicMsgIndex					=109,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    53
	EFBufPanicFileNameLen				=110,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    54
	EFBufPanicNullThis					=111,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    55
	EFBufPanicDirty						=112,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    56
	EFBufPanicNextReadFilePos			=113,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    57
	EFBufPanicNextReadFilePosHits		=114,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    58
	EFBufPanicFileBlockSize				=115,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    59
	EFBufPanicRwDataLength				=116,
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    60
	};
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    61
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    62
////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    63
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    64
//All macros in this header will have a non-void definition only if the OST_TRACE_COMPILER_IN_USE macro
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    65
//is defined. 
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    66
//In order to get the traces enabled, the OST_TRACE_COMPILER_IN_USE macro has to be defined in
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    67
//OstTraceDefinitions.h file. 
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    68
//After that, the trace output can be redirected by defining _SQL_RDEBUG_PRINT or specific categories
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    69
//of traces can be enabled/disabled.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    70
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    71
//Enable _SQLITE_RDEBUG_PRINT if you want to redirect the OS porting layer and file buffer tracing output via RDebug::Print()
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    72
//#define _SQLITE_RDEBUG_PRINT
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    73
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    74
//Enable _SQLITE_OS_TRACE_ENABLED if you get the OS porting layer traces compiled in the binary
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    75
//#define _SQLITE_OS_TRACE_ENABLED
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    76
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    77
//Enable _SQLITE_FBUF_TRACE_ENABLED if you get the file buffer traces compiled in the binary
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    78
//#define _SQLITE_FBUF_TRACE_ENABLED
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    79
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    80
#ifdef _DEBUG
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    81
	//Enable _SQLITE_PANIC_TRACE_ENABLED if you want to get more detailed output regarding panics
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    82
	//#define _SQLITE_PANIC_TRACE_ENABLED
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    83
#endif
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    84
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    85
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    86
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    87
//Wrap every string (file name, file path, etc.) you want to trace, in a __SQLITEPRNSTR()/__SQLITEPRNSTR8() macro. 
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    88
//There is a difference how RDebug::Print() and OstTraceExt<n>() work.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    89
#if defined _SQLITE_RDEBUG_PRINT
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    90
    const TInt KSqliteMaxPrnStrLen = 512;    
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    91
    #define __SQLITEPRNSTR(des)  &des
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    92
    const TDesC* SqliteDes8to16Ptr(const TDesC8& aDes);
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    93
	#define __SQLITEPRNSTR8(des)  SqliteDes8to16Ptr(des) 
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    94
#else
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    95
    #define __SQLITEPRNSTR(des)  des
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    96
    #define __SQLITEPRNSTR8(des) des
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    97
#endif
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    98
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
    99
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   100
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   101
/**
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   102
Set of useful functions to print diagnostic messages on the console when a panic occurs.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   103
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   104
@internalComponent
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   105
*/
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   106
class TSqliteUtil
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   107
	{
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   108
public:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   109
	static TInt Panic(const TText* aFile, TInt aLine, TInt aPanicCode, TUint aHandle);
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   110
	
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   111
private:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   112
	static TPtrC FileName(const TText* aFile);
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   113
	
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   114
	};
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   115
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   116
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   117
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   118
#define __SQLITESTRING(str) _S(str)
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   119
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   120
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   121
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   122
//__SQLITEPANIC/__SQLITEPANIC2 macro is used for printing out additional information when panic occurs in SQLite OS porting layer and the file buffer:
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   123
//source file name, line number, "this" pointer, panic category.
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   124
#define __SQLITEPANIC(aPanicCode)      TSqliteUtil::Panic(__SQLITESTRING(__FILE__), __LINE__, aPanicCode, (TUint)this)
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   125
#define __SQLITEPANIC2(aPanicCode)     TSqliteUtil::Panic(__SQLITESTRING(__FILE__), __LINE__, aPanicCode, 0)
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   126
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   127
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   128
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   129
#ifdef _SQLITE_OS_TRACE_ENABLED
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   130
    #define SQLITE_TRACE_OS(trace)   trace
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   131
#else
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   132
    #define SQLITE_TRACE_OS(trace)   do {} while(0)
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   133
#endif
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   134
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   135
#ifdef _SQLITE_FBUF_TRACE_ENABLED
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   136
    #define SQLITE_TRACE_FBUF(trace)   trace
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   137
#else
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   138
    #define SQLITE_TRACE_FBUF(trace)   do {} while(0)
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   139
#endif
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   140
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   141
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   142
ba1c4f4a893f 201025_02
hgs
parents:
diff changeset
   143
#endif //SQLITEUTIL_H