1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/testexecute/SQLite/src/hashing.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,313 @@
1.4 +// Copyright (c) 2006-2009 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 +
1.19 +#include "hashing.h"
1.20 +#include "sqlfn.h"
1.21 +#include "cdtest.h"
1.22 +#include <sqldb.h>
1.23 +
1.24 +//
1.25 +// This code is for setting up and accessing hashes. These are used within
1.26 +// the test harness to associate a word (for example "KErrNone") with an
1.27 +// integer value (0 in this case). The base class CSQLHashUtil contains the
1.28 +// accessor and destructor methods which do 99% of the work. All of the
1.29 +// other classes merely contain constructors to set up their hashes.
1.30 +//
1.31 +
1.32 +// Basic functionality first...
1.33 +TPtrC* CSQLHashUtil::GetStringFromNum(TInt aErrNum)
1.34 + {
1.35 + return ihash.Find(aErrNum);
1.36 + }
1.37 +
1.38 +TInt CSQLHashUtil::GetNumFromString(TPtrC aErrMsg)
1.39 + {
1.40 + THashMapIter<TInt, TPtrC> it(ihash);
1.41 + it.NextValue();
1.42 + while (it.CurrentValue())
1.43 + {
1.44 + if (*it.CurrentValue() == aErrMsg)
1.45 + return *it.CurrentKey();
1.46 + it.NextValue();
1.47 + }
1.48 + return (KErrNotFound);
1.49 + }
1.50 +
1.51 +CSQLHashUtil::~CSQLHashUtil()
1.52 + {
1.53 + while(ihash.Count())
1.54 + {
1.55 + THashMapIter<TInt, TPtrC> it(ihash);
1.56 + const TInt *curkey = it.NextKey();
1.57 + ihash.Remove(*curkey);
1.58 + }
1.59 + }
1.60 +
1.61 +// Now setup OS errors..
1.62 +CSQLOsErrHash::CSQLOsErrHash()
1.63 + {
1.64 + // error codes from e32err.h
1.65 + ihash.Insert(KErrNone, _L("KErrNone"));
1.66 + ihash.Insert(KErrNotFound, _L("KErrNotFound"));
1.67 + ihash.Insert(KErrGeneral, _L("KErrGeneral"));
1.68 + ihash.Insert(KErrCancel, _L("KErrCancel"));
1.69 + ihash.Insert(KErrNoMemory, _L("KErrNoMemory"));
1.70 + ihash.Insert(KErrNotSupported, _L("KErrNotSupported"));
1.71 + ihash.Insert(KErrArgument, _L("KErrArgument"));
1.72 + ihash.Insert(KErrTotalLossOfPrecision, _L("KErrTotalLossOfPrecision"));
1.73 + ihash.Insert(KErrBadHandle, _L("KErrBadHandle"));
1.74 + ihash.Insert(KErrOverflow, _L("KErrOverflow"));
1.75 + ihash.Insert(KErrUnderflow, _L("KErrUnderflow"));
1.76 + ihash.Insert(KErrAlreadyExists, _L("KErrAlreadyExists"));
1.77 + ihash.Insert(KErrPathNotFound, _L("KErrPathNotFound"));
1.78 + ihash.Insert(KErrDied, _L("KErrDied"));
1.79 + ihash.Insert(KErrInUse, _L("KErrInUse"));
1.80 + ihash.Insert(KErrServerTerminated, _L("KErrServerTerminated"));
1.81 + ihash.Insert(KErrServerBusy, _L("KErrServerBusy"));
1.82 + ihash.Insert(KErrCompletion, _L("KErrCompletion"));
1.83 + ihash.Insert(KErrNotReady, _L("KErrNotReady"));
1.84 + ihash.Insert(KErrUnknown, _L("KErrUnknown"));
1.85 + ihash.Insert(KErrCorrupt, _L("KErrCorrupt"));
1.86 + ihash.Insert(KErrAccessDenied, _L("KErrAccessDenied"));
1.87 + ihash.Insert(KErrLocked, _L("KErrLocked"));
1.88 + ihash.Insert(KErrWrite, _L("KErrWrite"));
1.89 + ihash.Insert(KErrDisMounted, _L("KErrDisMounted"));
1.90 + ihash.Insert(KErrEof, _L("KErrEof"));
1.91 + ihash.Insert(KErrDiskFull, _L("KErrDiskFull"));
1.92 + ihash.Insert(KErrBadDriver, _L("KErrBadDriver"));
1.93 + ihash.Insert(KErrBadName, _L("KErrBadName"));
1.94 + ihash.Insert(KErrCommsLineFail, _L("KErrCommsLineFail"));
1.95 + ihash.Insert(KErrCommsFrame, _L("KErrCommsFrame"));
1.96 + ihash.Insert(KErrCommsOverrun, _L("KErrCommsOverrun"));
1.97 + ihash.Insert(KErrCommsParity, _L("KErrCommsParity"));
1.98 + ihash.Insert(KErrTimedOut, _L("KErrTimedOut"));
1.99 + ihash.Insert(KErrCouldNotConnect, _L("KErrCouldNotConnect"));
1.100 + ihash.Insert(KErrCouldNotDisconnect, _L("KErrCouldNotDisconnect"));
1.101 + ihash.Insert(KErrDisconnected, _L("KErrDisconnected"));
1.102 + ihash.Insert(KErrBadLibraryEntryPoint, _L("KErrBadLibraryEntryPoint"));
1.103 + ihash.Insert(KErrBadDescriptor, _L("KErrBadDescriptor"));
1.104 + ihash.Insert(KErrAbort, _L("KErrAbort"));
1.105 + ihash.Insert(KErrTooBig, _L("KErrTooBig"));
1.106 + ihash.Insert(KErrDivideByZero, _L("KErrDivideByZero"));
1.107 + ihash.Insert(KErrBadPower, _L("KErrBadPower"));
1.108 + ihash.Insert(KErrDirFull, _L("KErrDirFull"));
1.109 + ihash.Insert(KErrHardwareNotAvailable, _L("KErrHardwareNotAvailable"));
1.110 + ihash.Insert(KErrSessionClosed, _L("KErrSessionClosed"));
1.111 + ihash.Insert(KErrPermissionDenied, _L("KErrPermissionDenied"));
1.112 + ihash.Insert(KErrExtensionNotSupported, _L("KErrExtensionNotSupported"));
1.113 + TInt err = ihash.Insert(KErrCommsBreak, _L("KErrCommsBreak"));
1.114 + if( err == KErrNone )
1.115 + return;
1.116 + User::Panic(_L("Unable to create OS error hash"), 1411);
1.117 + }
1.118 +
1.119 +// Now setup SQL errors..
1.120 +CSQLErrHash::CSQLErrHash()
1.121 + {
1.122 + // error codes from sqldb.h
1.123 + ihash.Insert(KSqlErrGeneral, _L("KSqlErrGeneral"));
1.124 + ihash.Insert(KSqlErrInternal, _L("KSqlErrInternal"));
1.125 + ihash.Insert(KSqlErrPermission, _L("KSqlErrPermission"));
1.126 + ihash.Insert(KSqlErrAbort, _L("KSqlErrAbort"));
1.127 + ihash.Insert(KSqlErrBusy, _L("KSqlErrBusy"));
1.128 + ihash.Insert(KSqlErrLocked, _L("KSqlErrLocked"));
1.129 + ihash.Insert(KSqlErrReadOnly, _L("KSqlErrReadOnly"));
1.130 + ihash.Insert(KSqlErrInterrupt, _L("KSqlErrInterrupt"));
1.131 + ihash.Insert(KSqlErrIO, _L("KSqlErrIO"));
1.132 + ihash.Insert(KSqlErrCorrupt, _L("KSqlErrCorrupt"));
1.133 + ihash.Insert(KSqlErrNotFound, _L("KSqlErrNotFound"));
1.134 + ihash.Insert(KSqlErrFull, _L("KSqlErrFull"));
1.135 + ihash.Insert(KSqlErrCantOpen, _L("KSqlErrCantOpen"));
1.136 + ihash.Insert(KSqlErrProtocol, _L("KSqlErrProtocol"));
1.137 + ihash.Insert(KSqlErrEmpty, _L("KSqlErrEmpty"));
1.138 + ihash.Insert(KSqlErrSchema, _L("KSqlErrSchema"));
1.139 + ihash.Insert(KSqlErrTooBig, _L("KSqlErrTooBig"));
1.140 + ihash.Insert(KSqlErrConstraint, _L("KSqlErrConstraint"));
1.141 + ihash.Insert(KSqlErrMismatch, _L("KSqlErrMismatch"));
1.142 + ihash.Insert(KSqlErrMisuse, _L("KSqlErrMisuse"));
1.143 + ihash.Insert(KSqlErrRange, _L("KSqlErrRange"));
1.144 + ihash.Insert(KSqlErrNotDb, _L("KSqlErrNotDb"));
1.145 + ihash.Insert(KSqlErrStmtExpired, _L("KSqlErrStmtExpired"));
1.146 + // The last two aren't strictly errors, but it is convenient to treat
1.147 + // them as such to process the output from RSqlStatement::Next().
1.148 + ihash.Insert(KSqlAtRow, _L("KSqlAtRow"));
1.149 + TInt err = ihash.Insert(KSqlAtEnd, _L("KSqlAtEnd"));
1.150 + if( err == KErrNone )
1.151 + return;
1.152 + User::Panic(_L("Unable to create SQL error hash"), 1412);
1.153 + }
1.154 +
1.155 +// Now do the SQL enumerations..
1.156 +CSQLColTypeHash::CSQLColTypeHash()
1.157 + {
1.158 + // Enumerations for sqldb.h
1.159 + ihash.Insert(ESqlNull, _L("ESqlNull"));
1.160 + ihash.Insert(ESqlInt, _L("ESqlInt"));
1.161 + ihash.Insert(ESqlInt64, _L("ESqlInt64"));
1.162 + ihash.Insert(ESqlReal, _L("ESqlReal"));
1.163 + ihash.Insert(ESqlText, _L("ESqlText"));
1.164 + ihash.Insert(ESqlBinary, _L("ESqlBinary"));
1.165 + TInt err = ihash.Insert(ESqlNull, _L("ESqlNull"));
1.166 + if( err == KErrNone )
1.167 + return;
1.168 +
1.169 + User::Panic(_L("Unable to create column type hash"), 1413);
1.170 + }
1.171 +
1.172 +// Now do the enumerations for all of the functions in sqlfn..
1.173 +CSQLTEFAction::CSQLTEFAction()
1.174 + {
1.175 + // Enumerations from sqlfn.h
1.176 + ihash.Insert(CSQLFnStep::Efn_undefined, _L("fn_undefined"));
1.177 + ihash.Insert(CSQLFnStep::Efn_nop, _L("NoOperation"));
1.178 + ihash.Insert(CSQLFnStep::Efn_create, _L("Create"));
1.179 + ihash.Insert(CSQLFnStep::Efn_createl, _L("CreateL"));
1.180 + ihash.Insert(CSQLFnStep::Efn_createsp, _L("CreateSP"));
1.181 + ihash.Insert(CSQLFnStep::Efn_open, _L("Open"));
1.182 + ihash.Insert(CSQLFnStep::Efn_openl, _L("OpenL"));
1.183 + ihash.Insert(CSQLFnStep::Efn_attach, _L("Attach"));
1.184 + ihash.Insert(CSQLFnStep::Efn_detach, _L("Detach"));
1.185 + ihash.Insert(CSQLFnStep::Efn_copy, _L("Copy"));
1.186 + ihash.Insert(CSQLFnStep::Efn_delete, _L("Delete"));
1.187 + ihash.Insert(CSQLFnStep::Efn_close, _L("Close"));
1.188 + ihash.Insert(CSQLFnStep::Efn_exec, _L("Exec"));
1.189 + ihash.Insert(CSQLFnStep::Efn_setisolationlevel, _L("SetIsolationLevel"));
1.190 + ihash.Insert(CSQLFnStep::Efn_lasterrormessage, _L("LastErrorMessage"));
1.191 + ihash.Insert(CSQLFnStep::Efn_reservedrivespace, _L("ReserveDriveSpace"));
1.192 + ihash.Insert(CSQLFnStep::Efn_freereservedspace, _L("FreeReservedSpace"));
1.193 + ihash.Insert(CSQLFnStep::Efn_getreserveaccess, _L("GetReserveAccess"));
1.194 + ihash.Insert(CSQLFnStep::Efn_releasereserveaccess, _L("ReleaseReserveAccess"));
1.195 + ihash.Insert(CSQLFnStep::Erstmt_prepare, _L("Prepare"));
1.196 + ihash.Insert(CSQLFnStep::Erstmt_preparel, _L("PrepareL"));
1.197 + ihash.Insert(CSQLFnStep::Erstmt_close, _L("St_Close"));
1.198 + ihash.Insert(CSQLFnStep::Erstmt_atrow, _L("AtRow"));
1.199 + ihash.Insert(CSQLFnStep::Erstmt_reset, _L("Reset"));
1.200 + ihash.Insert(CSQLFnStep::Erstmt_exec, _L("St_Exec"));
1.201 + ihash.Insert(CSQLFnStep::Erstmt_next, _L("Next"));
1.202 + ihash.Insert(CSQLFnStep::Erstmt_paramindex, _L("ParameterIndex"));
1.203 + ihash.Insert(CSQLFnStep::Erstmt_colindex, _L("ColumnIndex"));
1.204 + ihash.Insert(CSQLFnStep::Erstmt_coltype, _L("ColumnType"));
1.205 + ihash.Insert(CSQLFnStep::Erstmt_colsize, _L("ColumnSize"));
1.206 + ihash.Insert(CSQLFnStep::Erstmt_bindnull, _L("BindNull"));
1.207 + ihash.Insert(CSQLFnStep::Erstmt_bindint, _L("BindInt"));
1.208 + ihash.Insert(CSQLFnStep::Erstmt_bindint64, _L("BindInt64_"));
1.209 + ihash.Insert(CSQLFnStep::Erstmt_bindreal, _L("BindReal"));
1.210 + ihash.Insert(CSQLFnStep::Erstmt_bindtext, _L("BindText"));
1.211 + ihash.Insert(CSQLFnStep::Erstmt_bindbigtext, _L("BindTextFromFile"));
1.212 + ihash.Insert(CSQLFnStep::Erstmt_bindbinary, _L("BindBinary"));
1.213 + ihash.Insert(CSQLFnStep::Erstmt_isnull, _L("IsNull"));
1.214 + ihash.Insert(CSQLFnStep::Erstmt_colint, _L("ColumnInt"));
1.215 + ihash.Insert(CSQLFnStep::Erstmt_colint64, _L("ColumnInt64_"));
1.216 + ihash.Insert(CSQLFnStep::Erstmt_colreal, _L("ColumnReal"));
1.217 + ihash.Insert(CSQLFnStep::Erstmt_coltextL, _L("ColumnTextL"));
1.218 + ihash.Insert(CSQLFnStep::Erstmt_coltextP, _L("ColumnTextP"));
1.219 + ihash.Insert(CSQLFnStep::Erstmt_coltextD, _L("ColumnTextD"));
1.220 + ihash.Insert(CSQLFnStep::Erstmt_colbinL, _L("ColumnBinaryL"));
1.221 + ihash.Insert(CSQLFnStep::Erstmt_colbinP, _L("ColumnBinaryP"));
1.222 + ihash.Insert(CSQLFnStep::Erstmt_colbinD, _L("ColumnBinaryD"));
1.223 + ihash.Insert(CSQLFnStep::Esp_create, _L("SPCreate"));
1.224 + ihash.Insert(CSQLFnStep::Esp_createl, _L("SPCreateL"));
1.225 + ihash.Insert(CSQLFnStep::Esp_close, _L("SPClose"));
1.226 + ihash.Insert(CSQLFnStep::Esp_setdbpolicy, _L("SetDBPolicy"));
1.227 + ihash.Insert(CSQLFnStep::Esp_setpolicy, _L("SetPolicy"));
1.228 + ihash.Insert(CSQLFnStep::Esp_externalizel, _L("SPExternalizeL"));
1.229 + ihash.Insert(CSQLFnStep::Esp_internalizel, _L("SPInternalizeL"));
1.230 + ihash.Insert(CSQLFnStep::Estreamwrite_bindtext, _L("StreamWriteBindText"));
1.231 + ihash.Insert(CSQLFnStep::Estreamwrite_bindbinary, _L("StreamWriteBindBin"));
1.232 + ihash.Insert(CSQLFnStep::Estreamread_columntext, _L("StreamReadColText"));
1.233 + ihash.Insert(CSQLFnStep::Estreamread_columnbinary, _L("StreamReadColBin"));
1.234 + ihash.Insert(CSQLFnStep::Edefineconfig, _L("DefineConfig"));
1.235 + ihash.Insert(CSQLFnStep::Ectrl_newblock, _L("NewBlock"));
1.236 + ihash.Insert(CSQLFnStep::Ectrl_function, _L("Function"));
1.237 + ihash.Insert(CSQLFnStep::Ectrl_waitA, _L("WaitA"));
1.238 + ihash.Insert(CSQLFnStep::Ectrl_signalA, _L("SignalA"));
1.239 + ihash.Insert(CSQLFnStep::Ectrl_waitB, _L("WaitB"));
1.240 + ihash.Insert(CSQLFnStep::Ectrl_signalB, _L("SignalB"));
1.241 + ihash.Insert(CSQLFnStep::Ectrl_sleep, _L("Sleep"));
1.242 + ihash.Insert(CSQLFnStep::Ectrl_eightbit, _L("EightBit"));
1.243 + ihash.Insert(CSQLFnStep::Ectrl_async, _L("Async"));
1.244 + TInt err = ihash.Insert(CSQLFnStep::Ectrl_endblock, _L("EndBlock"));
1.245 + if( err == KErrNone )
1.246 + return;
1.247 +
1.248 + User::Panic(_L("Unable to create action hash"), 1414);
1.249 + }
1.250 +
1.251 +CSQLCapability::CSQLCapability()
1.252 + {
1.253 + ihash.Insert(ECapabilityTCB, _L("ECapabilityTCB"));
1.254 + ihash.Insert(ECapabilityCommDD, _L("ECapabilityCommDD"));
1.255 + ihash.Insert(ECapabilityPowerMgmt, _L("ECapabilityPowerMgmt"));
1.256 + ihash.Insert(ECapabilityMultimediaDD, _L("ECapabilityMultimediaDD"));
1.257 + ihash.Insert(ECapabilityReadDeviceData, _L("ECapabilityReadDeviceData"));
1.258 + ihash.Insert(ECapabilityWriteDeviceData, _L("ECapabilityWriteDeviceData"));
1.259 + ihash.Insert(ECapabilityDRM, _L("ECapabilityDRM"));
1.260 + ihash.Insert(ECapabilityTrustedUI, _L("ECapabilityTrustedUI"));
1.261 + ihash.Insert(ECapabilityProtServ, _L("ECapabilityProtServ"));
1.262 + ihash.Insert(ECapabilityDiskAdmin, _L("ECapabilityDiskAdmin"));
1.263 + ihash.Insert(ECapabilityNetworkControl, _L("ECapabilityNetworkControl"));
1.264 + ihash.Insert(ECapabilityAllFiles, _L("ECapabilityAllFiles"));
1.265 + ihash.Insert(ECapabilitySwEvent, _L("ECapabilitySwEvent"));
1.266 + ihash.Insert(ECapabilityNetworkServices, _L("ECapabilityNetworkServices"));
1.267 + ihash.Insert(ECapabilityLocalServices, _L("ECapabilityLocalServices"));
1.268 + ihash.Insert(ECapabilityReadUserData, _L("ECapabilityReadUserData"));
1.269 + ihash.Insert(ECapabilityWriteUserData, _L("ECapabilityWriteUserData"));
1.270 + ihash.Insert(ECapabilityLocation, _L("ECapabilityLocation"));
1.271 + ihash.Insert(ECapabilitySurroundingsDD, _L("ECapabilitySurroundingsDD"));
1.272 + ihash.Insert(ECapabilityUserEnvironment, _L("ECapabilityUserEnvironment"));
1.273 + ihash.Insert(ECapability_Limit, _L("ECapability_Limit"));
1.274 + ihash.Insert(ECapability_HardLimit, _L("ECapability_HardLimit"));
1.275 + ihash.Insert(ECapability_None, _L("ECapability_None"));
1.276 + TInt err = ihash.Insert(ECapability_Denied, _L("ECapability_Denied"));
1.277 + if( err == KErrNone )
1.278 + return;
1.279 +
1.280 + User::Panic(_L("Unable to create capability hash"), 1414);
1.281 + }
1.282 +
1.283 +CSQLPolicy::CSQLPolicy()
1.284 + {
1.285 + ihash.Insert(RSqlSecurityPolicy::ESchemaPolicy, _L("ESchemaPolicy"));
1.286 + ihash.Insert(RSqlSecurityPolicy::EReadPolicy, _L("EReadPolicy"));
1.287 + TInt err = ihash.Insert(RSqlSecurityPolicy::EWritePolicy, _L("EWritePolicy"));
1.288 + if( err == KErrNone )
1.289 + return;
1.290 +
1.291 + User::Panic(_L("Unable to create SQL policy hash"), 1414);
1.292 + }
1.293 +
1.294 +CSQLObject::CSQLObject()
1.295 + {
1.296 + TInt err = ihash.Insert(RSqlSecurityPolicy::ETable, _L("ETable"));
1.297 + if( err == KErrNone )
1.298 + return;
1.299 +
1.300 + User::Panic(_L("Unable to create SQL policy hash"), 1414);
1.301 + }
1.302 +
1.303 +CSQLSFSTEFAction::CSQLSFSTEFAction()
1.304 + {
1.305 + ihash.Insert(ESFS_SelectIntL, _L("SelectIntL"));
1.306 + ihash.Insert(ESFS_SelectInt64L, _L("SelectInt64L"));
1.307 + ihash.Insert(ESFS_SelectRealL, _L("SelectRealL"));
1.308 + ihash.Insert(ESFS_SelectTextL, _L("SelectTextL"));
1.309 +
1.310 + TInt err = ihash.Insert(ESFS_SelectBinaryL, _L("SelectBinaryL"));
1.311 + if( err == KErrNone )
1.312 + return;
1.313 +
1.314 + User::Panic(_L("Unable to create action hash"), 1414);
1.315 + }
1.316 +