|
1 /* |
|
2 * Copyright (c) 2002 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: TNssVasDbCreator is responsible for creating VasDatabase.db. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nssvastvasdbcreator.h" |
|
20 #include <e32cons.h> |
|
21 #include <s32file.h> |
|
22 #include <d32dbms.h> |
|
23 #include "nssvascoreconstant.h" |
|
24 |
|
25 // in bytes |
|
26 const TInt KClientDataColSize = 100; |
|
27 |
|
28 // ============================ Methods =============================== |
|
29 |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // TNssVasDbCreator::TNssVasDbCreator |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 TNssVasDbCreator::TNssVasDbCreator() |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // TNssVasDbCreator::CreateVasDatabaseL |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void TNssVasDbCreator::CreateVasDatabaseL( RDbs& iDbSession ) |
|
44 { |
|
45 RDbNamedDatabase database; |
|
46 TInt error = database.Create( iDbSession, KVasDatabaseName, KVasDatabaseFormatString ); |
|
47 CleanupClosePushL( database ); |
|
48 if ( error == KErrAlreadyExists ) |
|
49 { |
|
50 // Ignore KErrAlreadyExists, we will use the existing one if it is there |
|
51 error = KErrNone; |
|
52 } |
|
53 else if ( error == KErrNone ) |
|
54 { |
|
55 // Create tables |
|
56 CreateTablesAndIndiciesL( database ); |
|
57 } |
|
58 |
|
59 CleanupStack::PopAndDestroy( &database ); // Close database |
|
60 |
|
61 User::LeaveIfError( error ); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // TNssVasDbCreator::CreateTablesAndIndiciesL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void TNssVasDbCreator::CreateTablesAndIndiciesL( RDbNamedDatabase& aDatabase ) |
|
69 { |
|
70 CreateContextTableL( aDatabase ); |
|
71 CreateContextIndexL( aDatabase ); |
|
72 CreateTagTableL( aDatabase ); |
|
73 CreateTagIndexL( aDatabase ); |
|
74 CreateRRDTableL( aDatabase ); |
|
75 CreateRRDIndexL( aDatabase ); |
|
76 CreateWriteLockTableL( aDatabase ); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // TNssVasDbCreator::CreateContextTableL |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 /* Context Table |
|
84 * |
|
85 * Was up to 2.0: |
|
86 * |
|
87 * name|global|contextid|lexiconid|grammarid|modelbankid |
|
88 * ------------------------------------------------------ |
|
89 * | | | | | |
|
90 * |
|
91 * In 2.8: |
|
92 * |
|
93 * |name|global|contextid|lexiconid|grammarid|modelbankid|clientdata| |
|
94 * |----------------------------------------------------------------| |
|
95 * | | | | | | | | |
|
96 */ |
|
97 void TNssVasDbCreator::CreateContextTableL( RDbNamedDatabase& aDatabase ) |
|
98 { |
|
99 _LIT(KContextTable, "contexttable"); |
|
100 _LIT(KCol1, "name"); |
|
101 _LIT(KCol2, "global"); |
|
102 _LIT(KCol3, "contextid"); |
|
103 _LIT(KCol4, "lexiconid"); |
|
104 _LIT(KCol5, "grammarid"); |
|
105 _LIT(KCol6, "modelbankid"); |
|
106 _LIT(KCol8, "clientdata"); // NSS Extension(tm) |
|
107 |
|
108 // Create the context table definition (columnset). |
|
109 CDbColSet* columns = CDbColSet::NewLC(); |
|
110 |
|
111 // add column definitions |
|
112 |
|
113 // The name column first. |
|
114 TDbCol dbCol1(KCol1, EDbColText,KNssVasDbContextName); |
|
115 dbCol1.iAttributes = TDbCol::ENotNull; |
|
116 columns->AddL(dbCol1); |
|
117 |
|
118 // The global flag column |
|
119 TDbCol dbCol2(KCol2, EDbColUint32); |
|
120 dbCol2.iAttributes = TDbCol::ENotNull; |
|
121 columns->AddL(dbCol2); |
|
122 |
|
123 // The context id flag CDbKey* key = CDbKey::NewLC(); |
|
124 TDbCol dbCol3(KCol3, EDbColUint32); |
|
125 dbCol3.iAttributes = TDbCol::EAutoIncrement|TDbCol::ENotNull; |
|
126 columns->AddL(dbCol3); |
|
127 |
|
128 // The lexicon id |
|
129 TDbCol dbCol4(KCol4, EDbColUint32); |
|
130 dbCol4.iAttributes = TDbCol::ENotNull; |
|
131 columns->AddL(dbCol4); |
|
132 |
|
133 // The grammar id |
|
134 TDbCol dbCol5( KCol5, EDbColUint32 ); |
|
135 dbCol5.iAttributes = TDbCol::ENotNull; |
|
136 columns->AddL( dbCol5 ); |
|
137 |
|
138 // The modelbank id |
|
139 TDbCol dbCol6( KCol6, EDbColUint32 ); |
|
140 dbCol6.iAttributes = TDbCol::ENotNull; |
|
141 columns->AddL( dbCol6 ); |
|
142 |
|
143 // 100 bytes of client data. New in 2.8. |
|
144 TDbCol dbCol8( KCol8, EDbColBinary, KClientDataColSize ); |
|
145 // Can be null |
|
146 columns->AddL( dbCol8 ); |
|
147 |
|
148 // Now actually create the table. |
|
149 User::LeaveIfError( aDatabase.CreateTable( KContextTable, *columns ) ); |
|
150 |
|
151 // Cleanup columns |
|
152 CleanupStack::PopAndDestroy( columns ); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // TNssVasDbCreator::CreateContextIndexL |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void TNssVasDbCreator::CreateContextIndexL( RDbNamedDatabase& aDatabase ) |
|
160 { |
|
161 _LIT( KTable, "contexttable" ); |
|
162 // Same as table name is a bit weird, but we leave it unchanged to avoid |
|
163 // potential incompatibility with some other code, that might access |
|
164 // index by name |
|
165 _LIT( KIndexName, "contexttable"); |
|
166 //_LIT( KCol3, "contextid" ); |
|
167 CreateSingleColumnIndexL( aDatabase, KIndexName, KContextIdCol, ETrue, KTable); |
|
168 |
|
169 } |
|
170 |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // TNssVasDbCreator::CreateTagTableL |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 /* |
|
177 * Tag Table |
|
178 * |
|
179 * tagid|contextid|name|ruleid| |
|
180 * ----------------------------- |
|
181 * | | | | |
|
182 * |
|
183 */ |
|
184 void TNssVasDbCreator::CreateTagTableL( RDbNamedDatabase& aDatabase ) |
|
185 { |
|
186 _LIT(KTagTable,"tagtable"); |
|
187 _LIT(KCol1, "tagid"); |
|
188 _LIT(KCol2, "contextid"); |
|
189 _LIT(KCol3, "name"); |
|
190 _LIT(KCol5, "ruleid"); |
|
191 |
|
192 |
|
193 // Create the tag table definition (columnset). |
|
194 CDbColSet* columns = CDbColSet::NewLC(); |
|
195 |
|
196 // The tag id |
|
197 TDbCol dbCol1(KCol1, EDbColUint32); |
|
198 dbCol1.iAttributes = TDbCol::EAutoIncrement|TDbCol::ENotNull; |
|
199 columns->AddL(dbCol1); |
|
200 |
|
201 // The context id |
|
202 TDbCol dbCol2(KCol2, EDbColUint32); |
|
203 dbCol2.iAttributes = TDbCol::ENotNull; |
|
204 columns->AddL(dbCol2); |
|
205 |
|
206 // The speechitem/tag name column. |
|
207 TDbCol dbCol3(KCol3, EDbColText,KNssVasDbSpeechItemName); |
|
208 dbCol3.iAttributes = TDbCol::ENotNull; |
|
209 columns->AddL(dbCol3); |
|
210 |
|
211 // The rule id |
|
212 TDbCol dbCol5(KCol5, EDbColUint32); |
|
213 dbCol5.iAttributes = TDbCol::ENotNull; |
|
214 columns->AddL(dbCol5); |
|
215 |
|
216 // Now actually create the table. |
|
217 User::LeaveIfError ( aDatabase.CreateTable(KTagTable, *columns)); |
|
218 |
|
219 // Cleanup columns |
|
220 CleanupStack::PopAndDestroy( columns ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // TNssVasDbCreator::CreateTagIndexL |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void TNssVasDbCreator::CreateTagIndexL( RDbNamedDatabase& aDatabase ) |
|
228 { |
|
229 _LIT( KTable, "tagtable" ); |
|
230 CreateSingleColumnIndexL(aDatabase, KTable, KTagIdCol, ETrue, KTable); |
|
231 _LIT( KContextIndexName, "tagtable_contextid_idx" ); |
|
232 CreateSingleColumnIndexL(aDatabase, KContextIndexName, KContextIdCol, EFalse, KTable); |
|
233 _LIT( KRuleIndexName, "tagtable_ruleid_idx" ); |
|
234 CreateSingleColumnIndexL(aDatabase, KRuleIndexName, KRuleIdCol, EFalse, KTable); |
|
235 _LIT( KIndexName, "tagtable_contextid_ruleid_idx" ); |
|
236 CreateTwoColumnIndexL( KIndexName, KContextIdCol, KRuleIdCol, ETrue, KTable); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // TNssVasDbCreator::CreateRRDTableL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 /* RRD Text Table RRD Int Table |
|
244 * |
|
245 * tagid|text|pos tagid|int|pos |
|
246 * -------------- ------------- |
|
247 * | | | | |
|
248 */ |
|
249 void TNssVasDbCreator::CreateRRDTableL( RDbNamedDatabase& aDatabase ) |
|
250 { |
|
251 _LIT( KRRDTextTable, "rrdtexttable" ); |
|
252 _LIT( KRRDIntTable, "rrdinttable" ); |
|
253 |
|
254 _LIT( KCol1, "tagid" ); |
|
255 _LIT( KTextCol2,"rrdtext" ); |
|
256 _LIT( KIdCol2, "rrdint" ); |
|
257 _LIT( KCol3, "rrdposition" ); |
|
258 |
|
259 // Create the rrd tables definition (columnset). |
|
260 CDbColSet* textcolumns = CDbColSet::NewLC(); |
|
261 CDbColSet* intcolumns = CDbColSet::NewLC(); |
|
262 |
|
263 // The tag id |
|
264 TDbCol dbCol1( KCol1, EDbColUint32 ); |
|
265 //dbCol1.iAttributes = TDbCol::ENotNull; |
|
266 textcolumns->AddL( dbCol1 ); |
|
267 intcolumns->AddL( dbCol1 ); |
|
268 |
|
269 // The rrd text |
|
270 TDbCol dbCol2( KTextCol2, EDbColText, KNssVasDbRRDText ); |
|
271 //dbCol2.iAttributes = TDbCol::ENotNull; |
|
272 textcolumns->AddL( dbCol2 ); |
|
273 |
|
274 //The rrd int |
|
275 TDbCol iddbCol2( KIdCol2, EDbColUint32 ); |
|
276 //iddbCol2.iAttributes = TDbCol::ENotNull; |
|
277 intcolumns->AddL( iddbCol2 ); |
|
278 |
|
279 // The position |
|
280 TDbCol dbCol3( KCol3, EDbColUint32 ); |
|
281 //dbCol3.iAttributes = TDbCol::ENotNull; |
|
282 textcolumns->AddL( dbCol3 ); |
|
283 intcolumns->AddL( dbCol3 ); |
|
284 |
|
285 User::LeaveIfError( aDatabase.CreateTable( KRRDTextTable, *textcolumns ) ); |
|
286 User::LeaveIfError( aDatabase.CreateTable( KRRDIntTable, *intcolumns ) ); |
|
287 |
|
288 // Cleanup textcolumns & idcolumns |
|
289 CleanupStack::PopAndDestroy( intcolumns ); |
|
290 CleanupStack::PopAndDestroy( textcolumns ); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // TNssVasDbCreator::CreateRRDIndexL |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void TNssVasDbCreator::CreateRRDIndexL( RDbNamedDatabase& aDatabase ) |
|
298 { |
|
299 _LIT( KRRDTextTable, "rrdtexttable" ); |
|
300 _LIT( KRRDIntTable, "rrdinttable" ); |
|
301 _LIT( KRRDTextTagIndex, "rrdtexttable_tagid_idx"); |
|
302 _LIT( KRRDIntTagIndex, "rrdinttable_tagid_idx" ); |
|
303 _LIT( KRRDTextTagPosIndex, "rrdtexttable_tagid_pos_idx"); |
|
304 _LIT( KRRDIntTagPosIndex, "rrdinttable_tagid__pos_idx" ); |
|
305 // constraints |
|
306 CreateTwoColumnIndexL(KRRDTextTagPosIndex, KTagIdCol, KRRDPositionCol, ETrue, KRRDTextTable); |
|
307 CreateTwoColumnIndexL(KRRDIntTagPosIndex, KTagIdCol, KRRDPositionCol, ETrue, KRRDIntTable); |
|
308 // and for actual searches |
|
309 CreateSingleColumnIndexL(aDatabase, KRRDTextTagIndex, KTagIdCol, EFalse, KRRDTextTable); |
|
310 CreateSingleColumnIndexL(aDatabase, KRRDIntTagIndex, KTagIdCol, EFalse, KRRDIntTable); |
|
311 } |
|
312 |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // TNssVasDbCreator::CreateWriteLockTableL |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 /* Write lock table |
|
319 * |
|
320 * temporary |
|
321 * |---------| |
|
322 * | | |
|
323 */ |
|
324 void TNssVasDbCreator::CreateWriteLockTableL( RDbNamedDatabase& aDatabase ) |
|
325 { |
|
326 _LIT( KWriteLockTable, "writelocktable" ); |
|
327 |
|
328 _LIT( KCol1, "temporary" ); |
|
329 |
|
330 // Create the rrd tables definition (columnset). |
|
331 CDbColSet* columns = CDbColSet::NewLC(); |
|
332 |
|
333 // The tag id |
|
334 TDbCol dbCol1( KCol1, EDbColUint32 ); |
|
335 columns->AddL( dbCol1 ); |
|
336 |
|
337 User::LeaveIfError( aDatabase.CreateTable( KWriteLockTable, *columns ) ); |
|
338 |
|
339 // Cleanup columns |
|
340 CleanupStack::PopAndDestroy( columns ); |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // TNssVasDbCreator::CreateSingleColumnIndexL |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void TNssVasDbCreator::CreateSingleColumnIndexL( RDbNamedDatabase& aDatabase, |
|
348 const TDesC& aIndexName, |
|
349 const TDesC& aColumnName, |
|
350 const TBool aUnique, |
|
351 const TDesC& aTableName) |
|
352 { |
|
353 // Create the index key... |
|
354 CDbKey* key = CDbKey::NewLC(); |
|
355 |
|
356 // and add the key columns. |
|
357 TDbKeyCol keyCol( aColumnName ); |
|
358 key->AddL( keyCol ); |
|
359 if( aUnique ) |
|
360 { |
|
361 key->MakeUnique(); |
|
362 } |
|
363 |
|
364 // Create the index |
|
365 User::LeaveIfError( aDatabase.CreateIndex( aIndexName, aTableName, *key ) ); |
|
366 |
|
367 // Cleanup key |
|
368 CleanupStack::PopAndDestroy(key); |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // TNssVasDbCreator::CreateTwoColumnIndexL |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 void TNssVasDbCreator::CreateTwoColumnIndexL( const TDesC& /*anIndexName*/, |
|
376 const TDesC& /*aFirstColumnName*/, |
|
377 const TDesC& /*aSecondColumnName*/, |
|
378 const TBool /*aUnique*/, |
|
379 const TDesC& /*aTableName*/) |
|
380 { |
|
381 } |
|
382 |