sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings" sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __SQLUTIL_H__ sl@0: #define __SQLUTIL_H__ sl@0: sl@0: #include //TInt sl@0: sl@0: /** sl@0: Defines the maximum length of text or binary data that can be transferred sl@0: from the SQL server to the SQL client in a single IPC call. sl@0: sl@0: This constant affects the behaviour of a number of functions, specifically: sl@0: - RSqlStatement::ColumnBinaryL() sl@0: - RSqlStatement::ColumnTextL() sl@0: . sl@0: It also affects the behaviour of member functions of the classes: sl@0: - RSqlParamWriteStream sl@0: - RSqlColumnReadStream sl@0: sl@0: @see RSqlStatement::ColumnBinaryL() sl@0: @see RSqlStatement::ColumnTextL() sl@0: @see RSqlParamWriteStream sl@0: @see RSqlColumnReadStream sl@0: sl@0: @internalComponent sl@0: */ sl@0: #ifdef _DEBUG sl@0: const TInt KSqlMaxDesLen = 8; sl@0: #else sl@0: const TInt KSqlMaxDesLen = 256; sl@0: #endif sl@0: sl@0: /** sl@0: Used internally for making sure config manipulation buffers sl@0: are not exceeded sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlSrvMaxConfigStrLen = 256; sl@0: sl@0: /** sl@0: If some server function retuns a non-negative error, which value is bigger than KSqlClientBufOverflowCode, sl@0: then it means the server wanted to send a data buffer to the client but the client's sl@0: buffer is not big enough. The client must increase the buffer size and try to retrieve the data only. sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlClientBufOverflowCode = 0x1000; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: enum TSqlBufFlatType sl@0: { sl@0: ESqlColumnNamesBuf, sl@0: ESqlParamNamesBuf, sl@0: ESqlColumnValuesBuf, sl@0: ESqlDeclColumnTypesBuf sl@0: }; sl@0: sl@0: /** sl@0: This structure is used for IPC data transfers sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_STRUCT(TSqlIpcData) sl@0: { sl@0: inline TSqlIpcData() : sl@0: iPrm1(0), sl@0: iPrm2(0) sl@0: { sl@0: } sl@0: TUint32 iPrm1; sl@0: TUint32 iPrm2; sl@0: }; sl@0: sl@0: /** sl@0: IPC function codes used for communication between SqlDb.dll and SqlSrv.exe. sl@0: sl@0: The max function code allowed is 0xFF - see KSqlSrvFunctionMask declaration in the same file. sl@0: sl@0: The 32-bit RMessage2 function code format, which is used by the SQL client and server, is: sl@0: sl@0: @code sl@0: Bits: 31................................0 sl@0: Bytes: 0 1 2 3 sl@0: XXXXXXTT HHHHHHHH HHHHHHHH FFFFFFFF sl@0: sl@0: Where: sl@0: - "X" - unused bits; sl@0: - "T" - handle type: 0 - statement handle, 1 - stream handle, 2 - no handle; sl@0: - "H" - statement or stream handle, 16 bits; sl@0: - "F" - function code, 8 bits (see KSqlSrvFunctionMask); sl@0: @endcode sl@0: sl@0: @see RMessage2 sl@0: @see KSqlSrvFunctionMask sl@0: @see KSqlSrvHandleMask sl@0: @see KSqlSrvHandleTypeMask sl@0: @see KSqlSrvHandleShiftBits sl@0: @see CSqlSrvSession sl@0: @see CSqlSrvSession::ServiceL() sl@0: sl@0: @internalComponent sl@0: */ sl@0: enum TSqlSrvFunction sl@0: { sl@0: //Test functions sl@0: ESqlSrvTestBase = 0x00, sl@0: ESqlSrvResourceMark = ESqlSrvTestBase + 0x01, sl@0: ESqlSrvResourceCheck = ESqlSrvTestBase + 0x02, sl@0: ESqlSrvResourceCount = ESqlSrvTestBase + 0x03, sl@0: ESqlSrvSetDbHeapFailure = ESqlSrvTestBase + 0x04, sl@0: ESqlSrvSetHeapFailure = ESqlSrvTestBase + 0x05, sl@0: //Profiling functions sl@0: ESqlSrvProfilerStart = ESqlSrvTestBase + 0x06, sl@0: ESqlSrvProfilerStop = ESqlSrvTestBase + 0x07, sl@0: ESqlSrvProfilerReset = ESqlSrvTestBase + 0x08, sl@0: ESqlSrvProfilerSetRange = ESqlSrvTestBase + 0x09,//not used sl@0: ESqlSrvProfilerQuery = ESqlSrvTestBase + 0x0A, sl@0: //Database functions sl@0: ESqlSrvDbBase = 0x10, sl@0: ESqlSrvDbCreate = ESqlSrvDbBase + 0x01, sl@0: ESqlSrvDbCreateSecure = ESqlSrvDbBase + 0x02, sl@0: ESqlSrvDbOpen = ESqlSrvDbBase + 0x03, sl@0: ESqlSrvDbOpenFromHandle = ESqlSrvDbBase + 0x04, sl@0: ESqlSrvDbClose = ESqlSrvDbBase + 0x05, sl@0: ESqlSrvDbCopy = ESqlSrvDbBase + 0x06, sl@0: ESqlSrvDbDelete = ESqlSrvDbBase + 0x07, sl@0: //All operations with opcode > ESqlSrvDbDelete require valid database object (on the server side) sl@0: ESqlSrvLastErrorMsg = ESqlSrvDbBase + 0x08, sl@0: ESqlSrvDbExec8 = ESqlSrvDbBase + 0x09, sl@0: ESqlSrvDbExec16 = ESqlSrvDbBase + 0x0A, sl@0: ESqlSrvDbSetIsolationLevel = ESqlSrvDbBase + 0x0C, sl@0: ESqlSrvDbGetSecurityPolicy = ESqlSrvDbBase + 0x0D, sl@0: ESqlSrvDbAttach = ESqlSrvDbBase + 0x0E, sl@0: ESqlSrvDbAttachFromHandle = ESqlSrvDbBase + 0x0F, sl@0: ESqlSrvDbDetach = ESqlSrvDbBase + 0x10, sl@0: ESqlSrvDbScalarFullSelect8 = ESqlSrvDbBase + 0x11, sl@0: ESqlSrvDbScalarFullSelect16 = ESqlSrvDbBase + 0x12, sl@0: ESqlSrvDbInTransaction = ESqlSrvDbBase + 0x13, sl@0: ESqlSrvDbSize = ESqlSrvDbBase + 0x14, sl@0: ESqlSrvDbSize2 = ESqlSrvDbBase + 0x15, sl@0: ESqlSrvDbBlobSource = ESqlSrvDbBase + 0x16, sl@0: ESqlSrvDbLastInsertedRowId = ESqlSrvDbBase + 0x17, sl@0: ESqlSrvDbCompact = ESqlSrvDbBase + 0x18, sl@0: //Database - reserved drive space management sl@0: ESqlSrvDbReserveDriveSpace = ESqlSrvDbBase + 0x19, sl@0: ESqlSrvDbFreeReservedSpace = ESqlSrvDbBase + 0x1A, sl@0: ESqlSrvDbGetReserveAccess = ESqlSrvDbBase + 0x1B, sl@0: ESqlSrvDbReleaseReserveAccess=ESqlSrvDbBase + 0x1C, sl@0: //Statement functions sl@0: ESqlSrvStmtBase = 0x50, sl@0: ESqlSrvStmtPrepare8 = ESqlSrvStmtBase + 0x01, sl@0: ESqlSrvStmtPrepare16 = ESqlSrvStmtBase + 0x02, sl@0: ESqlSrvStmtClose = ESqlSrvStmtBase + 0x03, sl@0: ESqlSrvStmtReset = ESqlSrvStmtBase + 0x04, sl@0: ESqlSrvStmtExec = ESqlSrvStmtBase + 0x05, sl@0: ESqlSrvStmtAsyncExec = ESqlSrvStmtBase + 0x06, sl@0: ESqlSrvStmtBindExec = ESqlSrvStmtBase + 0x07, sl@0: ESqlSrvStmtAsyncBindExec = ESqlSrvStmtBase + 0x09, sl@0: ESqlSrvStmtNext = ESqlSrvStmtBase + 0x0A, sl@0: ESqlSrvStmtBindNext = ESqlSrvStmtBase + 0x0B, sl@0: ESqlSrvStmtColumnNames = ESqlSrvStmtBase + 0x0C, sl@0: ESqlSrvStmtParamNames = ESqlSrvStmtBase + 0x0D, sl@0: ESqlSrvStmtColumnSource = ESqlSrvStmtBase + 0x0E, sl@0: ESqlSrvStmtBinParamSink = ESqlSrvStmtBase + 0x0F, sl@0: ESqlSrvStmtTxtParamSink16 = ESqlSrvStmtBase + 0x11, sl@0: ESqlSrvStmtBufFlat = ESqlSrvStmtBase + 0x12, sl@0: ESqlSrvStmtColumnValue = ESqlSrvStmtBase + 0x13, sl@0: ESqlSrvStmtDeclColumnTypes = ESqlSrvStmtBase + 0x14, sl@0: //Stream functions sl@0: ESqlSrvStreamBase = 0x70, sl@0: ESqlSrvStreamRead = ESqlSrvStreamBase + 0x01, sl@0: ESqlSrvStreamWrite = ESqlSrvStreamBase + 0x02, sl@0: ESqlSrvStreamSize = ESqlSrvStreamBase + 0x03, sl@0: ESqlSrvStreamSynch = ESqlSrvStreamBase + 0x04, sl@0: ESqlSrvStreamClose = ESqlSrvStreamBase + 0x05 sl@0: }; sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: ////////// RMessage2, function code related macros //////// sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: SQL server function mask. sl@0: The SQL server function code must be less than 0x100. sl@0: (it occupies the lower 8 bits of the 32-bit message code) sl@0: sl@0: @see TSqlSrvFunction sl@0: sl@0: @internalComponent sl@0: */ sl@0: const TUint KSqlSrvFunctionMask = 0x000000FF; sl@0: sl@0: /** sl@0: SQL server (statement or stream) handle mask. sl@0: The handle occupies 16 bits, right after the function code. sl@0: sl@0: @see KSqlSrvHandleTypeMask sl@0: @see KSqlSrvHandleShiftBits sl@0: sl@0: @internalComponent sl@0: */ sl@0: const TUint KSqlSrvHandleMask = 0x00FFFF00; sl@0: sl@0: /** sl@0: SQL server (stream or statement) handle - shift bits. sl@0: sl@0: @see KSqlSrvFunctionMask sl@0: @see KSqlSrvHandleMask sl@0: sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlSrvHandleShiftBits = 8; sl@0: sl@0: /** sl@0: SQL server handle type bit. sl@0: sl@0: @see KSqlSrvHandleMask sl@0: @see KSqlSrvHandleShiftBits sl@0: sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlSrvHandleTypeMask = 0x03000000; sl@0: sl@0: /** sl@0: SQL server - handle type - statement or stream. sl@0: sl@0: @internalComponent sl@0: */ sl@0: enum TSqlSrvHandleType sl@0: { sl@0: ESqlSrvNoHandle = 0x00000000, sl@0: ESqlSrvStreamHandle = 0x01000000, sl@0: ESqlSrvStatementHandle = 0x02000000 sl@0: }; sl@0: sl@0: inline TInt MakeMsgCode(TSqlSrvFunction aFunction, TSqlSrvHandleType aHandleType, TInt aHandle); sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: TInt Sql2OsErrCode(TInt aSqlError, TInt aOsError); sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: ////////// Case insensitive string comparisons //////// sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: inline TInt CompareNoCase8(const TDesC8& aLeft, const TDesC8& aRight); sl@0: inline TInt CompareNoCase16(const TDesC16& aLeft, const TDesC16& aRight); sl@0: #ifdef _UNICODE sl@0: #define CompareNoCase CompareNoCase16 sl@0: #else sl@0: #define CompareNoCase CompareNoCase8 sl@0: #endif//_UNICODE sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: ////////// Buffer alignment functions ///////////// sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: inline TInt AlignedLen8(TInt aLen); sl@0: #ifdef _DEBUG sl@0: inline TBool IsAligned8(TInt aLen); sl@0: #endif sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: ////////// Compaction modes /////////////////////// sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: Compaction modes. sl@0: @internalComponent sl@0: */ sl@0: enum TSqlCompactionMode sl@0: { sl@0: ESqlCompactionNotSet, sl@0: ESqlCompactionManual, sl@0: ESqlCompactionBackground, sl@0: ESqlCompactionAuto sl@0: }; sl@0: sl@0: /** sl@0: SQLite vacuum modes. sl@0: @internalComponent sl@0: */ sl@0: enum TSqliteVacuumMode sl@0: { sl@0: ESqliteVacuumOff = 0, sl@0: ESqliteVacuumAuto = 1, sl@0: ESqliteVacuumIncremental = 2 sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Default compaction mode. sl@0: @internalComponent sl@0: */ sl@0: const TSqlCompactionMode KSqlDefaultCompactionMode = ESqlCompactionBackground; sl@0: sl@0: /** sl@0: Exec free page threshold in Kb, after which the background compaction will be activated. sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlCompactFreePageThresholdKb = 50; sl@0: sl@0: /** sl@0: One compaction step length in milliseconds. sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlCompactStepLengthMs = 50; sl@0: sl@0: /** sl@0: Interval in milliseconds between the compaction steps. sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlCompactStepIntervalMs = 50; sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: The db config file version that is initially stored in the system settings table. sl@0: @internalComponent sl@0: */ sl@0: const TInt KSqlNullDbConfigFileVersion = 0; sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: #include "SqlUtil.inl" sl@0: sl@0: #endif //__SQLUTIL_H__