First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Defines a writable interface for UPS Decision Database
29 #include <ups/upsdb.h>
30 #include <ups/upserr.h>
31 #include <ups/upsconst.h>
34 namespace UserPromptService
37 //Database, table and index names
38 _LIT(KDecisionTable, "UPSDecisions");
39 _LIT(KPrimaryIndex, "UPSPrimaryIndex");
40 _LIT(KRecordIdIndex, "UPSRecordIdIndex");
42 //Column names of the decision table
43 _LIT(KColServerSid, "ServerSid");
44 _LIT(KColServiceId, "ServiceId");
45 _LIT(KColClientSid, "ClientSid");
46 _LIT(KColEvaluatorId, "EvaluatorId");
47 _LIT(KColFingerprint, "Fingerprint");
48 _LIT(KColClientEntity, "ClientEntity");
49 _LIT(KColDescription, "Description");
50 _LIT(KColResult, "Result");
51 _LIT(KColEvaluatorInfo, "EvaluatorInfo");
52 _LIT(KColMajorPolicyVersion,"MajorPolicyVersion");
53 _LIT(KColRecordId, "RecordId");
56 static const TInt KBaseSQLLength = 33;
57 static const TInt KMaxIntCondition = 26; //columnname_length(11) + equal_sign(1) + max_decimal_digit_length(9) + and_length(5)
58 static const TInt KMaxStringCondition = 52; //columnname_length(12) + equal_sign(1) + max_field_length(32) + two_singlequote(2) + and_length(5)
59 static const TInt KCompactionTreshold = 50; //a percentage which indicates at least how much of the size of the database must be live data
60 static const TInt KIndexColumnNumber = 7; //The number of columns constructing the decision index
62 //Basic SQL statement parts
63 _LIT(KSQLQueryBase, "SELECT * FROM %S");
64 _LIT(KSQLQueryString, "%S");
65 _LIT(KSQLQueryConditionInt, "%u");
66 _LIT(KSQLQueryConditionString, "'%S'");
67 _LIT(KSQLQueryWhere, " WHERE ");
68 _LIT(KSQLQueryAnd, " AND ");
69 _LIT(KSQLQueryNull, " IS NULL");
70 _LIT(KSQLQueryEqual, "=");
71 _LIT(KSQLQueryNotEqual, "<>");
72 _LIT(KSQLQueryLessThan, "<");
73 _LIT(KSQLQueryGreaterThan, ">");
74 _LIT(KSQLQueryLessThanOrEqual, "<=");
75 _LIT(KSQLQueryGreaterThanOrEqual,">=");
77 //Other classes used in UPS database
78 class CDecisionFilter;
79 class CDecisionRecord;
82 NONSHARABLE_CLASS(CDecisionDbCompactor):public CActive
84 Provides an interface to compact the decision database asynchronously. While the
85 compaction operation is in progress, the database cannot be used for any other
86 operations such as searching records or preparing views.
89 friend class CDecisionDbW;
92 IMPORT_C void Compact(TRequestStatus& aStatus);
93 ~CDecisionDbCompactor();
96 static CDecisionDbCompactor *NewLC();
97 CDecisionDbCompactor();
100 From CActive. Handles incremental database compaction.
104 From CActive. Cancels current database compaction.
108 From CActive. Handles errors.
110 TInt RunError(TInt aError);
114 Handle to the interface used for performing database compaction in incremental steps
116 RDbIncremental iDbIncremental;
118 Contains the current step count for the incremental compaction operation
120 TPckgBuf<TInt> iStep;
122 Copy of the status variable of the client which requested the compaction service
124 TRequestStatus* iClientStatus;
128 NONSHARABLE_CLASS(CDecisionDbW):public CDecisionDb
130 A writable interface for UPS decision database. Connects to the database during construction.
131 Creates the decision database and table, if not exist. Performs querying, insertion and deletion
132 operations on the decision database.
136 IMPORT_C static CDecisionDbW *NewL(const TDesC& aDbName, RFs& aFs);
137 IMPORT_C static CDecisionDbW *NewLC(const TDesC& aDbName, RFs& aFs);
141 IMPORT_C void CreateDecisionL(CDecisionRecord& aRecord);
142 IMPORT_C CDecisionRecord *GetDecisionL(CDecisionFilter& aFilter);
143 IMPORT_C TBool UpdateDecisionL(CDecisionFilter& aFilter, CDecisionRecord& aNewRecord);
144 IMPORT_C void RemoveDecisionsL(CDecisionFilter& aFilter);
145 IMPORT_C void DeleteDatabaseL(RFs& aFs);
146 IMPORT_C CDecisionDbCompactor *PrepareCompactionLC();
151 void ConstructL(const TDesC& aDbName, RFs& aFs);
152 void OpenDatabaseL(RFs& aFs);
153 void CreateDatabaseL(RFs& aFs);
156 void DoRemoveDecisionL(CDecisionFilter& aFilter);
157 void UpdateCurrentRowL(RDbTable& aTable, CDecisionRecord& aRecord);
158 void PrepareForSearchL(RDbTable& aTable, CDecisionFilter& aFilter,TDbSeekMultiKey<KIndexColumnNumber>& aSeekKey);
162 * The fully qualified path of the database