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