|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ccotentinfodb.h" |
|
19 #include "ccontentinfo.h" |
|
20 #include <cpixcontentinfocommon.h> |
|
21 #include "OstTraceDefinitions.h" |
|
22 #ifdef OST_TRACE_COMPILER_IN_USE |
|
23 #include "ccontentinfodbTraces.h" |
|
24 #endif |
|
25 |
|
26 |
|
27 // The max length for creating sql query for KCISqlFormatSeek format |
|
28 const TInt KCISqlStringMaxLength(100); |
|
29 //SQL query to fetch the records with given Plugin name |
|
30 _LIT(KCISqlFormatSeek , "SELECT * FROM table1 WHERE NAME='%S'"); |
|
31 //SQL query to delete the records with given plugin name |
|
32 _LIT(KCISqlDelete, "DELETE FROM table1 WHERE NAME='%S'"); |
|
33 //Syntax for adding a row to sql database |
|
34 _LIT(KInsertRowFormat,"INSERT INTO table1(NAME,INS,BLS) values('%S',%d,%d)"); |
|
35 //syntax to retrieve all the rows from the sql database |
|
36 _LIT(KSelectAllRowsFormat,"SELECT * FROM table1"); |
|
37 //syntax to update Index status for a given plugin |
|
38 _LIT(KUpdateISFormat,"UPDATE table1 SET INS=%d WHERE NAME = '%S'"); |
|
39 //syntax to update Blacklist status for a given plugin |
|
40 _LIT(KUpdateBSFormat,"UPDATE table1 SET BLS=%d WHERE NAME = '%S'"); |
|
41 _LIT(KDriveC, "c:"); |
|
42 //syntax for removing all the records in the table |
|
43 _LIT(KRemoveAll, "DELETE FROM table1" ); |
|
44 //syntax for creating table with plugin name, indexing status and blacklist status as the columns |
|
45 _LIT(KCreateTableFormat,"CREATE TABLE table1(NAME TEXT NOT NULL, INS INTEGER, BLS INTEGER, PRIMARY KEY(NAME))"); |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CContentInfoDb::NewL() |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CContentInfoDb* CContentInfoDb::NewL() |
|
52 { |
|
53 OstTraceFunctionEntry0( CCONTENTINFODB_NEWL_ENTRY ); |
|
54 CContentInfoDb* instance = CContentInfoDb::NewLC(); |
|
55 CleanupStack::Pop( instance ); |
|
56 OstTraceFunctionExit0( CCONTENTINFODB_NEWL_EXIT ); |
|
57 return instance; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CContentInfoDb::NewLC() |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CContentInfoDb* CContentInfoDb::NewLC() |
|
65 { |
|
66 OstTraceFunctionEntry0( CCONTENTINFODB_NEWLC_ENTRY ); |
|
67 CContentInfoDb* instance = new (ELeave) CContentInfoDb(); |
|
68 CleanupStack::PushL( instance ); |
|
69 instance->ConstructL(); |
|
70 OstTraceFunctionExit0( CCONTENTINFODB_NEWLC_EXIT ); |
|
71 return instance; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CContentInfoDb::CContentInfoDb() |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CContentInfoDb::CContentInfoDb() |
|
79 { |
|
80 //Do the necessary initialisation |
|
81 iOpened = EFalse; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CContentInfoDb::~CContentInfoDb |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CContentInfoDb::~CContentInfoDb() |
|
89 { |
|
90 iDatabase.Close(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CBlacklistDb::ConstructL() |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CContentInfoDb::ConstructL() |
|
98 { |
|
99 OstTraceFunctionEntry0( CCONTENTINFODB_CONSTRUCTL_ENTRY ); |
|
100 //Open the sql database.If doesn't exist,create the sql database and open it |
|
101 RFs fssession; |
|
102 User::LeaveIfError( fssession.Connect() ); |
|
103 TFileName privatePath; |
|
104 TFileName datafile; |
|
105 fssession.CreatePrivatePath(EDriveC); |
|
106 fssession.PrivatePath(privatePath);//data caged path of loading process |
|
107 fssession.Close(); |
|
108 datafile.Copy(KDriveC); |
|
109 datafile.Append(privatePath); |
|
110 datafile.Append( KContentInfoFileName ); |
|
111 |
|
112 TInt err = iDatabase.Open( datafile ); |
|
113 |
|
114 switch ( err ) |
|
115 { |
|
116 case KErrNone: |
|
117 iOpened = ETrue; |
|
118 break; |
|
119 |
|
120 case KErrNotFound: |
|
121 case KErrPathNotFound: |
|
122 { |
|
123 //Create the database |
|
124 TRAPD( error , CreateDBL() ); |
|
125 |
|
126 if ( error == KErrNone ) |
|
127 { |
|
128 iOpened = ETrue; |
|
129 } |
|
130 } |
|
131 break; |
|
132 |
|
133 default: |
|
134 break; |
|
135 } |
|
136 |
|
137 OstTraceFunctionExit0( CCONTENTINFODB_CONSTRUCTL_EXIT ); |
|
138 return; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CContentInfoDb::AddL() |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CContentInfoDb::AddL( CContentInfo* aContentInfo ) |
|
146 { |
|
147 OstTraceFunctionEntry0( CCONTENTINFODB_ADDL_ENTRY ); |
|
148 //Add the item record to database |
|
149 |
|
150 if ( !iOpened ) |
|
151 return KErrNotReady; |
|
152 |
|
153 //Prepare the sql |
|
154 TBuf<KCISqlStringMaxLength> sql; |
|
155 HBufC* contentname = aContentInfo->GetNameL(); |
|
156 |
|
157 TInt indexstatus = aContentInfo->GetIndexStatus(); |
|
158 TBool blstatus = aContentInfo->GetBlacklistStatus(); |
|
159 sql.Format( KInsertRowFormat , contentname , indexstatus , blstatus ); |
|
160 |
|
161 TInt err = iDatabase.Exec(sql) ; |
|
162 |
|
163 delete contentname; |
|
164 OstTraceFunctionExit0( CCONTENTINFODB_ADDL_EXIT ); |
|
165 return err; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CContentInfoDb::UpdateBlacklistStatusL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CContentInfoDb::UpdateBlacklistStatusL( const TDesC& aContentName , TInt aBlacklistStatus ) |
|
173 { |
|
174 OstTraceFunctionEntry0( CCONTENTINFODB_UPDATEBLACKLISTSTATUSL_ENTRY ); |
|
175 //Update the item record to database |
|
176 if ( !iOpened ) |
|
177 return KErrNotReady; |
|
178 |
|
179 //Prepare the sql |
|
180 TBuf<KCISqlStringMaxLength> sql; |
|
181 sql.Format( KUpdateBSFormat , aBlacklistStatus, &aContentName ); |
|
182 |
|
183 TInt err = iDatabase.Exec(sql) ; |
|
184 |
|
185 OstTraceFunctionExit0( CCONTENTINFODB_UPDATEBLACKLISTSTATUSL_EXIT ); |
|
186 return err; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CContentInfoDb::UpdatePluginIndexStatusL |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 TInt CContentInfoDb::UpdatePluginIndexStatusL( const TDesC& aContentName , TInt aIndexStatus ) |
|
194 { |
|
195 OstTraceFunctionEntry0( CCONTENTINFODB_UPDATEPLUGININDEXSTATUSL_ENTRY ); |
|
196 //Update the item record to database |
|
197 |
|
198 if ( !iOpened ) |
|
199 return KErrNotReady; |
|
200 |
|
201 //Prepare the sql |
|
202 TBuf<KCISqlStringMaxLength> sql; |
|
203 sql.Format( KUpdateISFormat , aIndexStatus, &aContentName ); |
|
204 |
|
205 TInt err = iDatabase.Exec(sql) ; |
|
206 |
|
207 OstTraceFunctionExit0( CCONTENTINFODB_UPDATEPLUGININDEXSTATUSL_EXIT ); |
|
208 return err; |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CContentInfoDb::RemoveL |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CContentInfoDb::RemoveL( const TDesC& aContentName ) |
|
216 { |
|
217 OstTraceFunctionEntry0( CCONTENTINFODB_REMOVEL_ENTRY ); |
|
218 //remove the item record to database |
|
219 |
|
220 if ( !iOpened ) |
|
221 User::Leave( KErrNotReady ); |
|
222 |
|
223 //Prepare the sql |
|
224 TBuf<KCISqlStringMaxLength> sql; |
|
225 sql.Format( KCISqlDelete , &aContentName ); |
|
226 |
|
227 User::LeaveIfError( iDatabase.Exec(sql) ); |
|
228 OstTraceFunctionExit0( CCONTENTINFODB_REMOVEL_EXIT ); |
|
229 return ; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CContentInfoDb::ResetDatabaseL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CContentInfoDb::ResetDatabaseL( ) |
|
237 { |
|
238 OstTraceFunctionEntry0( CCONTENTINFODB_RESETDATABASEL_ENTRY ); |
|
239 //remove all the item record to database |
|
240 |
|
241 if ( !iOpened ) |
|
242 User::Leave( KErrNotReady ); |
|
243 |
|
244 //Prepare the sql |
|
245 TBuf<KCISqlStringMaxLength> sql; |
|
246 sql.Copy( KRemoveAll ); |
|
247 |
|
248 User::LeaveIfError( iDatabase.Exec(sql) ); |
|
249 |
|
250 OstTraceFunctionExit0( CCONTENTINFODB_RESETDATABASEL_EXIT ); |
|
251 return ; |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CContentInfoDb::FindL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 TBool CContentInfoDb::FindL(const TDesC& aContentName) |
|
259 { |
|
260 OstTraceFunctionEntry0( CCONTENTINFODB_FINDL_ENTRY ); |
|
261 if ( !iOpened ) |
|
262 User::Leave( KErrNotReady ); |
|
263 |
|
264 //Prepare the sql |
|
265 TBuf<KCISqlStringMaxLength> sql; |
|
266 sql.Format( KCISqlFormatSeek, &aContentName ); |
|
267 |
|
268 RSqlStatement stmt; |
|
269 stmt.Prepare( iDatabase , sql ); |
|
270 |
|
271 TBool isfound = ( KSqlAtRow == stmt.Next() )?ETrue:EFalse; |
|
272 OstTraceFunctionExit0( CCONTENTINFODB_FINDL_EXIT ); |
|
273 return isfound; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CContentInfoDb::GetContentCountL |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 TInt CContentInfoDb::GetContentCountL() |
|
281 { |
|
282 OstTraceFunctionEntry0( CCONTENTINFODB_GETCONTENTCOUNTL_ENTRY ); |
|
283 if ( !iOpened ) |
|
284 User::Leave( KErrNotReady ); |
|
285 |
|
286 TInt count = 0; |
|
287 |
|
288 //Prepare the sql |
|
289 TBuf<KCISqlStringMaxLength> sql; |
|
290 sql.Copy( KSelectAllRowsFormat ); |
|
291 |
|
292 RSqlStatement stmt; |
|
293 stmt.Prepare( iDatabase , sql ); |
|
294 |
|
295 while ( KSqlAtEnd != stmt.Next() ) |
|
296 ++count; |
|
297 |
|
298 OstTraceFunctionExit0( CCONTENTINFODB_GETCONTENTCOUNTL_EXIT ); |
|
299 return count; |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CContentInfoDb::CreateDBL |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 void CContentInfoDb::CreateDBL() |
|
307 { |
|
308 OstTraceFunctionEntry0( CCONTENTINFODB_CREATEDBL_ENTRY ); |
|
309 |
|
310 iDatabase.Close(); |
|
311 |
|
312 TFileName privatePath; |
|
313 TFileName datafile; |
|
314 RFs fssession; |
|
315 User::LeaveIfError( fssession.Connect() ); |
|
316 fssession.CreatePrivatePath(EDriveC); |
|
317 fssession.PrivatePath(privatePath);//data caged path of loading process |
|
318 fssession.Close(); |
|
319 datafile.Copy(KDriveC); |
|
320 datafile.Append(privatePath); |
|
321 datafile.Append( KContentInfoFileName ); |
|
322 |
|
323 //create the database |
|
324 User::LeaveIfError( iDatabase.Create( datafile ) ); |
|
325 |
|
326 //Add table |
|
327 TBuf<KCISqlStringMaxLength> sql; |
|
328 sql.Copy( KCreateTableFormat ); |
|
329 |
|
330 User::LeaveIfError( iDatabase.Exec( sql ) ); |
|
331 |
|
332 OstTraceFunctionExit0( CCONTENTINFODB_CREATEDBL_EXIT ); |
|
333 } |
|
334 //EOF |