os/persistentdata/persistentstorage/sql/SRC/Common/SqlUtil.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
// NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings"
sl@0
    13
//
sl@0
    14
// Description:
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef __SQLUTIL_H__
sl@0
    18
#define __SQLUTIL_H__
sl@0
    19
sl@0
    20
#include <e32std.h>			//TInt
sl@0
    21
sl@0
    22
/**
sl@0
    23
Defines the maximum length of text or binary data that can be transferred
sl@0
    24
from the SQL server to the SQL client in a single IPC call.
sl@0
    25
sl@0
    26
This constant affects the behaviour of a number of functions, specifically:
sl@0
    27
- RSqlStatement::ColumnBinaryL()
sl@0
    28
- RSqlStatement::ColumnTextL()
sl@0
    29
.
sl@0
    30
It also affects the behaviour of member functions of the classes:
sl@0
    31
- RSqlParamWriteStream
sl@0
    32
- RSqlColumnReadStream
sl@0
    33
sl@0
    34
@see RSqlStatement::ColumnBinaryL()
sl@0
    35
@see RSqlStatement::ColumnTextL()
sl@0
    36
@see RSqlParamWriteStream
sl@0
    37
@see RSqlColumnReadStream
sl@0
    38
sl@0
    39
@internalComponent
sl@0
    40
*/
sl@0
    41
#ifdef _DEBUG
sl@0
    42
const TInt KSqlMaxDesLen = 8;
sl@0
    43
#else
sl@0
    44
const TInt KSqlMaxDesLen = 256;
sl@0
    45
#endif
sl@0
    46
sl@0
    47
/**
sl@0
    48
Used internally for making sure config manipulation buffers
sl@0
    49
are not exceeded
sl@0
    50
@internalComponent
sl@0
    51
*/
sl@0
    52
const TInt KSqlSrvMaxConfigStrLen = 256;
sl@0
    53
sl@0
    54
/**
sl@0
    55
If some server function retuns a non-negative error, which value is bigger than KSqlClientBufOverflowCode,
sl@0
    56
then it means the server wanted to send a data buffer to the client but the client's 
sl@0
    57
buffer is not big enough. The client must increase the buffer size and try to retrieve the data only.
sl@0
    58
@internalComponent
sl@0
    59
*/
sl@0
    60
const TInt KSqlClientBufOverflowCode = 0x1000;
sl@0
    61
sl@0
    62
/**
sl@0
    63
@internalComponent
sl@0
    64
*/
sl@0
    65
enum TSqlBufFlatType 
sl@0
    66
	{
sl@0
    67
	ESqlColumnNamesBuf, 
sl@0
    68
	ESqlParamNamesBuf, 
sl@0
    69
	ESqlColumnValuesBuf,
sl@0
    70
	ESqlDeclColumnTypesBuf
sl@0
    71
	};
sl@0
    72
sl@0
    73
/**
sl@0
    74
This structure is used for IPC data transfers
sl@0
    75
@internalComponent
sl@0
    76
*/
sl@0
    77
NONSHARABLE_STRUCT(TSqlIpcData)
sl@0
    78
	{
sl@0
    79
	inline TSqlIpcData() :
sl@0
    80
		iPrm1(0),
sl@0
    81
		iPrm2(0)
sl@0
    82
		{
sl@0
    83
		}
sl@0
    84
	TUint32 iPrm1;
sl@0
    85
	TUint32 iPrm2;
sl@0
    86
	};
sl@0
    87
sl@0
    88
/**
sl@0
    89
IPC function codes used for communication between SqlDb.dll and SqlSrv.exe.
sl@0
    90
sl@0
    91
The max function code allowed is 0xFF - see KSqlSrvFunctionMask declaration in the same file.
sl@0
    92
sl@0
    93
The 32-bit RMessage2 function code format, which is used by the SQL client and server, is:
sl@0
    94
sl@0
    95
@code
sl@0
    96
Bits: 31................................0
sl@0
    97
Bytes:       0        1        2        3
sl@0
    98
      XXXXXXTT HHHHHHHH HHHHHHHH FFFFFFFF
sl@0
    99
sl@0
   100
Where:
sl@0
   101
- "X" - unused bits;
sl@0
   102
- "T" - handle type: 0 - statement handle, 1 - stream handle, 2 - no handle;
sl@0
   103
- "H" - statement or stream handle, 16 bits;
sl@0
   104
- "F" - function code, 8 bits (see KSqlSrvFunctionMask);
sl@0
   105
@endcode
sl@0
   106
sl@0
   107
@see RMessage2
sl@0
   108
@see KSqlSrvFunctionMask
sl@0
   109
@see KSqlSrvHandleMask
sl@0
   110
@see KSqlSrvHandleTypeMask
sl@0
   111
@see KSqlSrvHandleShiftBits
sl@0
   112
@see CSqlSrvSession
sl@0
   113
@see CSqlSrvSession::ServiceL()
sl@0
   114
sl@0
   115
@internalComponent
sl@0
   116
*/
sl@0
   117
enum TSqlSrvFunction
sl@0
   118
	{
sl@0
   119
	//Test functions
sl@0
   120
	ESqlSrvTestBase				= 					0x00,
sl@0
   121
	ESqlSrvResourceMark			= ESqlSrvTestBase + 0x01,
sl@0
   122
	ESqlSrvResourceCheck		= ESqlSrvTestBase + 0x02,
sl@0
   123
	ESqlSrvResourceCount		= ESqlSrvTestBase + 0x03,
sl@0
   124
	ESqlSrvSetDbHeapFailure		= ESqlSrvTestBase + 0x04,
sl@0
   125
	ESqlSrvSetHeapFailure		= ESqlSrvTestBase + 0x05,
sl@0
   126
	//Profiling functions
sl@0
   127
	ESqlSrvProfilerStart		= ESqlSrvTestBase + 0x06,
sl@0
   128
	ESqlSrvProfilerStop			= ESqlSrvTestBase + 0x07,
sl@0
   129
	ESqlSrvProfilerReset		= ESqlSrvTestBase + 0x08,
sl@0
   130
	ESqlSrvProfilerSetRange		= ESqlSrvTestBase + 0x09,//not used
sl@0
   131
	ESqlSrvProfilerQuery	    = ESqlSrvTestBase + 0x0A,
sl@0
   132
	//Database functions
sl@0
   133
	ESqlSrvDbBase				= 					0x10,
sl@0
   134
	ESqlSrvDbCreate				= ESqlSrvDbBase + 	0x01,
sl@0
   135
	ESqlSrvDbCreateSecure		= ESqlSrvDbBase + 	0x02,
sl@0
   136
	ESqlSrvDbOpen				= ESqlSrvDbBase + 	0x03,
sl@0
   137
	ESqlSrvDbOpenFromHandle		= ESqlSrvDbBase + 	0x04,
sl@0
   138
	ESqlSrvDbClose				= ESqlSrvDbBase + 	0x05,
sl@0
   139
	ESqlSrvDbCopy				= ESqlSrvDbBase + 	0x06,
sl@0
   140
	ESqlSrvDbDelete				= ESqlSrvDbBase + 	0x07,
sl@0
   141
	//All operations with opcode > ESqlSrvDbDelete require valid database object (on the server side)
sl@0
   142
	ESqlSrvLastErrorMsg			= ESqlSrvDbBase + 	0x08,
sl@0
   143
	ESqlSrvDbExec8				= ESqlSrvDbBase + 	0x09,
sl@0
   144
	ESqlSrvDbExec16				= ESqlSrvDbBase + 	0x0A,
sl@0
   145
	ESqlSrvDbSetIsolationLevel	= ESqlSrvDbBase + 	0x0C,
sl@0
   146
	ESqlSrvDbGetSecurityPolicy  = ESqlSrvDbBase + 	0x0D,
sl@0
   147
	ESqlSrvDbAttach				= ESqlSrvDbBase + 	0x0E,
sl@0
   148
	ESqlSrvDbAttachFromHandle	= ESqlSrvDbBase + 	0x0F,
sl@0
   149
	ESqlSrvDbDetach				= ESqlSrvDbBase + 	0x10,
sl@0
   150
	ESqlSrvDbScalarFullSelect8	= ESqlSrvDbBase + 	0x11,
sl@0
   151
	ESqlSrvDbScalarFullSelect16	= ESqlSrvDbBase + 	0x12,
sl@0
   152
	ESqlSrvDbInTransaction		= ESqlSrvDbBase + 	0x13,
sl@0
   153
	ESqlSrvDbSize				= ESqlSrvDbBase + 	0x14,
sl@0
   154
	ESqlSrvDbSize2				= ESqlSrvDbBase + 	0x15,
sl@0
   155
	ESqlSrvDbBlobSource			= ESqlSrvDbBase + 	0x16,
sl@0
   156
	ESqlSrvDbLastInsertedRowId	= ESqlSrvDbBase + 	0x17,
sl@0
   157
	ESqlSrvDbCompact			= ESqlSrvDbBase + 	0x18,
sl@0
   158
	//Database - reserved drive space management
sl@0
   159
	ESqlSrvDbReserveDriveSpace	= ESqlSrvDbBase + 	0x19,
sl@0
   160
	ESqlSrvDbFreeReservedSpace	= ESqlSrvDbBase + 	0x1A,
sl@0
   161
	ESqlSrvDbGetReserveAccess	= ESqlSrvDbBase + 	0x1B,
sl@0
   162
	ESqlSrvDbReleaseReserveAccess=ESqlSrvDbBase + 	0x1C,
sl@0
   163
	//Statement functions
sl@0
   164
	ESqlSrvStmtBase				= 					0x50,
sl@0
   165
	ESqlSrvStmtPrepare8			= ESqlSrvStmtBase + 0x01,
sl@0
   166
	ESqlSrvStmtPrepare16		= ESqlSrvStmtBase + 0x02,
sl@0
   167
	ESqlSrvStmtClose			= ESqlSrvStmtBase + 0x03,
sl@0
   168
	ESqlSrvStmtReset			= ESqlSrvStmtBase + 0x04,
sl@0
   169
	ESqlSrvStmtExec				= ESqlSrvStmtBase + 0x05,
sl@0
   170
	ESqlSrvStmtAsyncExec		= ESqlSrvStmtBase + 0x06,
sl@0
   171
	ESqlSrvStmtBindExec			= ESqlSrvStmtBase + 0x07,
sl@0
   172
	ESqlSrvStmtAsyncBindExec	= ESqlSrvStmtBase + 0x09,
sl@0
   173
	ESqlSrvStmtNext				= ESqlSrvStmtBase + 0x0A,
sl@0
   174
	ESqlSrvStmtBindNext			= ESqlSrvStmtBase + 0x0B,
sl@0
   175
	ESqlSrvStmtColumnNames		= ESqlSrvStmtBase + 0x0C,
sl@0
   176
	ESqlSrvStmtParamNames		= ESqlSrvStmtBase + 0x0D,
sl@0
   177
	ESqlSrvStmtColumnSource		= ESqlSrvStmtBase + 0x0E,
sl@0
   178
	ESqlSrvStmtBinParamSink		= ESqlSrvStmtBase + 0x0F,
sl@0
   179
	ESqlSrvStmtTxtParamSink16	= ESqlSrvStmtBase + 0x11,
sl@0
   180
	ESqlSrvStmtBufFlat			= ESqlSrvStmtBase + 0x12,
sl@0
   181
	ESqlSrvStmtColumnValue		= ESqlSrvStmtBase + 0x13,
sl@0
   182
	ESqlSrvStmtDeclColumnTypes	= ESqlSrvStmtBase + 0x14,
sl@0
   183
	//Stream functions
sl@0
   184
	ESqlSrvStreamBase			= 					  0x70,
sl@0
   185
	ESqlSrvStreamRead			= ESqlSrvStreamBase + 0x01,
sl@0
   186
	ESqlSrvStreamWrite			= ESqlSrvStreamBase + 0x02,
sl@0
   187
	ESqlSrvStreamSize			= ESqlSrvStreamBase + 0x03,
sl@0
   188
	ESqlSrvStreamSynch			= ESqlSrvStreamBase + 0x04,
sl@0
   189
	ESqlSrvStreamClose			= ESqlSrvStreamBase + 0x05
sl@0
   190
	};
sl@0
   191
sl@0
   192
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   193
//////////                  RMessage2, function code related macros                                 ////////
sl@0
   194
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   195
sl@0
   196
/**
sl@0
   197
SQL server function mask.
sl@0
   198
The SQL server function code must be less than 0x100.
sl@0
   199
(it occupies the lower 8 bits of the 32-bit message code)
sl@0
   200
sl@0
   201
@see TSqlSrvFunction
sl@0
   202
sl@0
   203
@internalComponent
sl@0
   204
*/
sl@0
   205
const TUint KSqlSrvFunctionMask		= 0x000000FF;
sl@0
   206
sl@0
   207
/**
sl@0
   208
SQL server (statement or stream) handle mask.
sl@0
   209
The handle occupies 16 bits, right after the function code.
sl@0
   210
sl@0
   211
@see KSqlSrvHandleTypeMask
sl@0
   212
@see KSqlSrvHandleShiftBits
sl@0
   213
sl@0
   214
@internalComponent
sl@0
   215
*/
sl@0
   216
const TUint KSqlSrvHandleMask 		= 0x00FFFF00;
sl@0
   217
sl@0
   218
/**
sl@0
   219
SQL server (stream or statement) handle - shift bits.
sl@0
   220
sl@0
   221
@see KSqlSrvFunctionMask
sl@0
   222
@see KSqlSrvHandleMask
sl@0
   223
sl@0
   224
@internalComponent
sl@0
   225
*/
sl@0
   226
const TInt  KSqlSrvHandleShiftBits 	= 8;
sl@0
   227
sl@0
   228
/**
sl@0
   229
SQL server handle type bit.
sl@0
   230
sl@0
   231
@see KSqlSrvHandleMask
sl@0
   232
@see KSqlSrvHandleShiftBits
sl@0
   233
sl@0
   234
@internalComponent
sl@0
   235
*/
sl@0
   236
const TInt  KSqlSrvHandleTypeMask 	= 0x03000000;
sl@0
   237
sl@0
   238
/**
sl@0
   239
SQL server - handle type - statement or stream.
sl@0
   240
sl@0
   241
@internalComponent
sl@0
   242
*/
sl@0
   243
enum TSqlSrvHandleType
sl@0
   244
	{
sl@0
   245
	ESqlSrvNoHandle 		= 0x00000000,
sl@0
   246
	ESqlSrvStreamHandle 	= 0x01000000,
sl@0
   247
	ESqlSrvStatementHandle	= 0x02000000
sl@0
   248
	};
sl@0
   249
sl@0
   250
inline TInt MakeMsgCode(TSqlSrvFunction aFunction, TSqlSrvHandleType aHandleType, TInt aHandle);
sl@0
   251
sl@0
   252
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   253
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   254
sl@0
   255
TInt Sql2OsErrCode(TInt aSqlError, TInt aOsError);
sl@0
   256
sl@0
   257
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   258
//////////                  Case insensitive string comparisons                                     ////////
sl@0
   259
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   260
sl@0
   261
inline TInt CompareNoCase8(const TDesC8& aLeft, const TDesC8& aRight);
sl@0
   262
inline TInt CompareNoCase16(const TDesC16& aLeft, const TDesC16& aRight);
sl@0
   263
#ifdef _UNICODE
sl@0
   264
#define CompareNoCase CompareNoCase16
sl@0
   265
#else
sl@0
   266
#define CompareNoCase CompareNoCase8
sl@0
   267
#endif//_UNICODE
sl@0
   268
sl@0
   269
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   270
//////////                      Buffer alignment functions                                     /////////////
sl@0
   271
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   272
sl@0
   273
inline TInt AlignedLen8(TInt aLen);
sl@0
   274
#ifdef _DEBUG
sl@0
   275
inline TBool IsAligned8(TInt aLen);
sl@0
   276
#endif
sl@0
   277
sl@0
   278
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   279
//////////                      Compaction modes                                     ///////////////////////
sl@0
   280
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   281
sl@0
   282
/**
sl@0
   283
Compaction modes.
sl@0
   284
@internalComponent
sl@0
   285
*/
sl@0
   286
enum TSqlCompactionMode
sl@0
   287
	{
sl@0
   288
	ESqlCompactionNotSet, 
sl@0
   289
	ESqlCompactionManual, 
sl@0
   290
	ESqlCompactionBackground, 
sl@0
   291
	ESqlCompactionAuto
sl@0
   292
	};
sl@0
   293
sl@0
   294
/**
sl@0
   295
SQLite vacuum modes.
sl@0
   296
@internalComponent
sl@0
   297
*/
sl@0
   298
enum TSqliteVacuumMode
sl@0
   299
	{
sl@0
   300
	ESqliteVacuumOff			= 0,
sl@0
   301
	ESqliteVacuumAuto			= 1, 
sl@0
   302
	ESqliteVacuumIncremental	= 2
sl@0
   303
	};
sl@0
   304
sl@0
   305
sl@0
   306
/**
sl@0
   307
Default compaction mode.
sl@0
   308
@internalComponent
sl@0
   309
*/
sl@0
   310
const TSqlCompactionMode KSqlDefaultCompactionMode = ESqlCompactionBackground;
sl@0
   311
sl@0
   312
/**
sl@0
   313
Exec free page threshold in Kb, after which the background compaction will be activated.
sl@0
   314
@internalComponent
sl@0
   315
*/
sl@0
   316
const TInt KSqlCompactFreePageThresholdKb = 50;
sl@0
   317
sl@0
   318
/**
sl@0
   319
One compaction step length in milliseconds.
sl@0
   320
@internalComponent
sl@0
   321
*/
sl@0
   322
const TInt KSqlCompactStepLengthMs = 50;
sl@0
   323
sl@0
   324
/**
sl@0
   325
Interval in milliseconds between the compaction steps.
sl@0
   326
@internalComponent
sl@0
   327
*/
sl@0
   328
const TInt KSqlCompactStepIntervalMs = 50;
sl@0
   329
sl@0
   330
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   331
sl@0
   332
/**
sl@0
   333
The db config file version that is initially stored in the system settings table.
sl@0
   334
@internalComponent
sl@0
   335
*/
sl@0
   336
const TInt KSqlNullDbConfigFileVersion = 0;
sl@0
   337
sl@0
   338
////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   339
sl@0
   340
#include "SqlUtil.inl"
sl@0
   341
	
sl@0
   342
#endif //__SQLUTIL_H__