Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "sddatabase.h"
17 #include "../Database/testdatabaseconstants.h"
19 _LIT(KTableGrammar, "GrammarTable");
20 _LIT(KTableLexicon, "LexiconTable");
21 _LIT(KTableModelBank, "ModelBankTable");
22 _LIT(KTableRule, "RuleTable");
23 _LIT(KTablePronunciation, "PronunciationTable");
24 _LIT(KTableModel, "ModelTable");
25 _LIT(KTableSettings, "SettingsTable");
28 _LIT(KColClientUID, "ClientUID");
29 _LIT(KColGrammarID, "GrammarID");
30 _LIT(KColLexiconID, "LexiconID");
31 _LIT(KColModelBankID,"ModelBankID");
32 _LIT(KColRuleID,"RuleID");
33 _LIT(KColPronunciationID,"PronunciationID");
34 _LIT(KColModelID,"ModelID");
35 _LIT(KColUtteranceDuration, "UtteranceDuration");
36 _LIT(KColSettingsID,"SettingsID");
37 _LIT(KColSettingsValue,"SettingsValue");
40 _LIT(KSQLSelectFromTable,"Select %S From %S");
41 _LIT(KSQLSelectFromTableWhereCondition,"Select %S From %S Where %S=%u");
43 const TInt KGTColNumClientUID = 1;
44 const TInt KGTColNumGrammarID = 2;
45 const TInt KLTColNumClientUID = 1;
46 const TInt KLTColNumLexiconID = 2;
47 const TInt KMBTColNumClientUID = 1;
48 const TInt KMBTColNumModelBankID = 2;
50 const TInt KRTColNumGrammarID = 1;
51 const TInt KRTColNumRuleID = 2;
52 const TInt KRTColNumLexiconID = 3;
53 const TInt KRTColNumPronunciationID =4;
55 const TInt KPTColNumLexiconID = 1;
56 const TInt KPTColNumPronunciationID = 2;
57 const TInt KPTColNumModelBankID = 3;
58 const TInt KPTColNumModelID = 4;
60 const TInt KMTColNumModelBankID = 1;
61 const TInt KMTColNumModelID = 2;
62 const TInt KMTColNumUtteranceDurationMicroSeconds = 3;
64 const TInt KSTColNumSettingsID = 1;
65 const TInt KSTColNumSettingsValue = 2;
67 const TInt KSettingLastID = 1;
70 CSDDatabase::RSDGrammarTable::RSDGrammarTable(CSDDatabase& aDatabase)
71 : iDatabase(aDatabase)
77 void CSDDatabase::RSDGrammarTable::OpenL(TBool aOwnedByClient)
81 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
83 query.Format(KSQLSelectFromTable,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
85 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
86 User::LeaveIfError(iView.EvaluateAll());
90 void CSDDatabase::RSDGrammarTable::Close()
95 void CSDDatabase::RSDGrammarTable::CreateGrammarL(TGrammarID& aGrammarID)
97 iDatabase.StartTransactionL();
98 aGrammarID = iDatabase.AllocNewIDL();
101 iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
102 iView.SetColL(KGTColNumGrammarID,aGrammarID);
106 void CSDDatabase::RSDGrammarTable::AddGrammarL(TGrammarID aGrammarID)
108 iDatabase.StartTransactionL();
109 iDatabase.UpdateLastIDL(aGrammarID);
111 iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
112 iView.SetColL(KGTColNumGrammarID,aGrammarID);
117 TBool CSDDatabase::RSDGrammarTable::FindGrammarL(TGrammarID aGrammarID)
119 TBool found = EFalse;
120 for (iView.FirstL();iView.AtRow();iView.NextL())
123 if (iView.ColUint32(KGTColNumGrammarID)==aGrammarID)
134 void CSDDatabase::RSDGrammarTable::RemoveGrammarL(TGrammarID aGrammarID)
136 if (FindGrammarL(aGrammarID))
138 if (iView.ColUint32(KGTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
140 iDatabase.StartTransactionL();
144 User::Leave(KErrNotFound);//change to not owned
147 User::Leave(KErrNotFound);
150 void CSDDatabase::RSDGrammarTable::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs)
153 for (iView.FirstL();iView.AtRow();iView.NextL())
156 TGrammarID grammarID = iView.ColUint32(KGTColNumGrammarID);
157 User::LeaveIfError(aGrammarIDs.Append(grammarID));
161 CSDDatabase::RSDLexiconTable::RSDLexiconTable(CSDDatabase& aDatabase)
162 : iDatabase(aDatabase)
168 void CSDDatabase::RSDLexiconTable::OpenL(TBool aOwnedByClient)
172 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
174 query.Format(KSQLSelectFromTable,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
176 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
177 User::LeaveIfError(iView.EvaluateAll());
181 void CSDDatabase::RSDLexiconTable::Close()
186 void CSDDatabase::RSDLexiconTable::CreateLexiconL(TLexiconID& aLexiconID)
188 iDatabase.StartTransactionL();
189 aLexiconID = iDatabase.AllocNewIDL();
192 iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
193 iView.SetColL(KLTColNumLexiconID,aLexiconID);
197 void CSDDatabase::RSDLexiconTable::AddLexiconL(TLexiconID aLexiconID)
199 iDatabase.StartTransactionL();
200 iDatabase.UpdateLastIDL(aLexiconID);
202 iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
203 iView.SetColL(KLTColNumLexiconID,aLexiconID);
208 TBool CSDDatabase::RSDLexiconTable::FindLexiconL(TLexiconID aLexiconID)
210 TBool found = EFalse;
211 for (iView.FirstL();iView.AtRow();iView.NextL())
214 if (iView.ColUint32(KLTColNumLexiconID)==aLexiconID)
225 void CSDDatabase::RSDLexiconTable::RemoveLexiconL(TLexiconID aLexiconID)
227 if (FindLexiconL(aLexiconID))
229 if (iView.ColUint32(KLTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
231 iDatabase.StartTransactionL();
235 User::Leave(KErrNotFound);//change to not owned
238 User::Leave(KErrNotFound);
241 void CSDDatabase::RSDLexiconTable::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs)
244 for (iView.FirstL();iView.AtRow();iView.NextL())
247 TLexiconID lexiconID = iView.ColUint32(KLTColNumLexiconID);
248 User::LeaveIfError(aLexiconIDs.Append(lexiconID));
252 CSDDatabase::RSDModelBankTable::RSDModelBankTable(CSDDatabase& aDatabase)
253 : iDatabase(aDatabase)
259 void CSDDatabase::RSDModelBankTable::OpenL(TBool aOwnedByClient)
263 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
265 query.Format(KSQLSelectFromTable,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
267 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
268 User::LeaveIfError(iView.EvaluateAll());
272 void CSDDatabase::RSDModelBankTable::Close()
277 TModelBankID CSDDatabase::RSDModelBankTable::CreateModelBankL()
279 iDatabase.StartTransactionL();
280 TModelBankID modelBankID;
281 modelBankID = iDatabase.AllocNewIDL();
284 iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
285 iView.SetColL(KMBTColNumModelBankID,modelBankID);
290 void CSDDatabase::RSDModelBankTable::AddModelBankL(TModelBankID aModelBankID)
292 iDatabase.StartTransactionL();
293 iDatabase.UpdateLastIDL(aModelBankID);
295 iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
296 iView.SetColL(KMBTColNumModelBankID,aModelBankID);
301 TBool CSDDatabase::RSDModelBankTable::FindModelBankL(TModelBankID aModelBankID)
303 TBool found = EFalse;
304 for (iView.FirstL();iView.AtRow();iView.NextL())
307 if (iView.ColUint32(KMBTColNumModelBankID)==aModelBankID)
318 void CSDDatabase::RSDModelBankTable::RemoveModelBankL(TModelBankID aModelBankID)
320 if (FindModelBankL(aModelBankID))
322 if (iView.ColUint32(KMBTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
324 iDatabase.StartTransactionL();
328 User::Leave(KErrNotFound);//change to not owned
331 User::Leave(KErrNotFound);
334 void CSDDatabase::RSDModelBankTable::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs)
336 aModelBankIDs.Reset();
337 for (iView.FirstL();iView.AtRow();iView.NextL())
340 TModelBankID modelBankID = iView.ColUint32(KMBTColNumModelBankID);
341 User::LeaveIfError(aModelBankIDs.Append(modelBankID));
346 CSDDatabase::RSDModelTable::RSDModelTable(CSDDatabase& aDatabase)
347 : iDatabase(aDatabase)
353 void CSDDatabase::RSDModelTable::OpenL(TModelBankID aModelBankID)
355 if (!iDatabase.ModelBankExistsL(aModelBankID))
356 User::Leave(KErrNotFound);
358 iModelBankID = aModelBankID;
360 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModel,&KColModelBankID,aModelBankID);
361 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
362 User::LeaveIfError(iView.EvaluateAll());
366 void CSDDatabase::RSDModelTable::Close()
371 TModelID CSDDatabase::RSDModelTable::CreateModelL(TModelData aModelData)
373 iDatabase.StartTransactionL();
374 TModelID modelID = iDatabase.AllocNewIDL();
376 iView.SetColL(KMTColNumModelBankID,iModelBankID);
377 iView.SetColL(KMTColNumModelID,modelID);
378 iView.SetColL(KMTColNumUtteranceDurationMicroSeconds,aModelData.iUtteranceDurationMicroSeconds);
383 void CSDDatabase::RSDModelTable::AddModelL(TModelData aModelData)
385 iDatabase.StartTransactionL();
386 iDatabase.UpdateLastIDL(aModelData.iModelID);
388 iView.SetColL(KMTColNumModelBankID,iModelBankID);
389 iView.SetColL(KMTColNumModelID,aModelData.iModelID);
390 iView.SetColL(KMTColNumUtteranceDurationMicroSeconds, aModelData.iUtteranceDurationMicroSeconds);
394 void CSDDatabase::RSDModelTable::GetModelDataL(TModelID aModelID, TModelData& aModelData)
396 if (!FindModelL(aModelID))
397 User::Leave(KErrNotFound);
400 aModelData.iModelID = iView.ColUint32(KMTColNumModelID);
401 aModelData.iUtteranceDurationMicroSeconds = iView.ColUint32(KMTColNumUtteranceDurationMicroSeconds);
406 TBool CSDDatabase::RSDModelTable::FindModelL(TModelID aModelID)
408 TBool found = EFalse;
409 for (iView.FirstL();iView.AtRow();iView.NextL())
412 if (iView.ColUint32(KMTColNumModelID)==aModelID)
423 void CSDDatabase::RSDModelTable::RemoveModelL(TModelID aModelID)
425 if (FindModelL(aModelID))
427 iDatabase.StartTransactionL();
431 User::Leave(KErrNotFound);
434 void CSDDatabase::RSDModelTable::GetAllModelIDsL(RArray<TModelID>& aModelIDs)
437 for (iView.FirstL();iView.AtRow();iView.NextL())
440 TModelID modelID = iView.ColUint32(KMTColNumModelID);
441 User::LeaveIfError(aModelIDs.Append(modelID));
445 //------------------------------------------------------------------------------------------------
446 CSDDatabase::RSDSettingsTable::RSDSettingsTable(CSDDatabase& aDatabase)
447 : iDatabase(aDatabase)
453 void CSDDatabase::RSDSettingsTable::OpenL()
456 query.Format(KSQLSelectFromTable,&KAllCols,&KTableSettings);
457 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
458 User::LeaveIfError(iView.EvaluateAll());
461 void CSDDatabase::RSDSettingsTable::Close()
466 TUint32 CSDDatabase::RSDSettingsTable::GetValueL(TUint32 aSettingID)
469 TBool found = EFalse;
470 for (iView.FirstL();iView.AtRow();iView.NextL())
473 if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
475 value = iView.ColUint32(KSTColNumSettingsValue);
482 User::Leave(KErrNotFound);
487 void CSDDatabase::RSDSettingsTable::SetValueL(TUint32 aSettingID, TUint32 aValue)
489 TBool found = EFalse;
490 for (iView.FirstL();iView.AtRow();iView.NextL())
493 if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
496 iView.SetColL(KSTColNumSettingsValue, aValue);
503 // if it wasn't found, add it
507 iView.SetColL(KSTColNumSettingsID, aSettingID);
508 iView.SetColL(KSTColNumSettingsValue, aValue);
514 //------------------------------------------------------------------------------------------------
516 CSDDatabase::RSDPronunciationTable::RSDPronunciationTable(CSDDatabase& aDatabase)
517 : iDatabase(aDatabase)
523 void CSDDatabase::RSDPronunciationTable::OpenL(TLexiconID aLexiconID)
525 if (!iDatabase.LexiconExistsL(aLexiconID))
526 User::Leave(KErrNotFound);
528 iLexiconID = aLexiconID;
530 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTablePronunciation,&KColLexiconID,aLexiconID);
531 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
532 User::LeaveIfError(iView.EvaluateAll());
536 void CSDDatabase::RSDPronunciationTable::Close()
541 TPronunciationID CSDDatabase::RSDPronunciationTable::CreatePronunciationL(TPronunciationData aPronunciationData)
543 TPronunciationID pronunciationID;
544 iDatabase.StartTransactionL();
545 pronunciationID = iDatabase.AllocNewIDL();
547 iView.SetColL(KPTColNumLexiconID,iLexiconID);
548 iView.SetColL(KPTColNumPronunciationID,pronunciationID);
549 iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
550 iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
552 return pronunciationID;
555 void CSDDatabase::RSDPronunciationTable::AddPronunciationL(TPronunciationData aPronunciationData)
557 iDatabase.StartTransactionL();
558 iDatabase.UpdateLastIDL(aPronunciationData.iPronunciationID);
560 iView.SetColL(KPTColNumLexiconID,iLexiconID);
561 iView.SetColL(KPTColNumPronunciationID,aPronunciationData.iPronunciationID);
562 iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
563 iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
567 void CSDDatabase::RSDPronunciationTable::GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
569 if (!FindPronunciationL(aPronunciationID))
570 User::Leave(KErrNotFound);
573 aPronunciationData.iPronunciationID = iView.ColUint32(KPTColNumPronunciationID);
574 aPronunciationData.iModelBankID = iView.ColUint32(KPTColNumModelBankID);
575 aPronunciationData.iModelID = iView.ColUint32(KPTColNumModelID);
580 TBool CSDDatabase::RSDPronunciationTable::FindPronunciationL(TPronunciationID aPronunciationID)
582 TBool found = EFalse;
583 for (iView.FirstL();iView.AtRow();iView.NextL())
586 if (iView.ColUint32(KPTColNumPronunciationID)==aPronunciationID)
597 void CSDDatabase::RSDPronunciationTable::RemovePronunciationL(TPronunciationID aPronunciationID)
599 if (FindPronunciationL(aPronunciationID))
601 iDatabase.StartTransactionL();
605 User::Leave(KErrNotFound);
608 void CSDDatabase::RSDPronunciationTable::GetAllPronunciationIDsL(RArray<TPronunciationID>& aPronunciationIDs)
610 aPronunciationIDs.Reset();
611 for (iView.FirstL();iView.AtRow();iView.NextL())
614 TPronunciationID modelID = iView.ColUint32(KPTColNumPronunciationID);
615 User::LeaveIfError(aPronunciationIDs.Append(modelID));
618 //--------------------------------------------------------------------------------------------------
620 CSDDatabase::RSDRuleTable::RSDRuleTable(CSDDatabase& aDatabase)
621 : iDatabase(aDatabase)
627 void CSDDatabase::RSDRuleTable::OpenL(TGrammarID aGrammarID)
629 if (!iDatabase.GrammarExistsL(aGrammarID))
630 User::Leave(KErrNotFound);
632 iGrammarID = aGrammarID;
634 query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableRule,&KColGrammarID,aGrammarID);
635 User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
636 User::LeaveIfError(iView.EvaluateAll());
640 void CSDDatabase::RSDRuleTable::Close()
645 TRuleID CSDDatabase::RSDRuleTable::CreateRuleL(TRuleData aRuleData)
647 iDatabase.StartTransactionL();
648 TRuleID ruleID = iDatabase.AllocNewIDL();
650 iView.SetColL(KRTColNumGrammarID,iGrammarID);
651 iView.SetColL(KRTColNumRuleID,ruleID);
652 iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
653 iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
658 void CSDDatabase::RSDRuleTable::AddRuleL(TRuleData aRuleData)
660 iDatabase.StartTransactionL();
661 iDatabase.UpdateLastIDL(aRuleData.iRuleID);
664 iView.SetColL(KRTColNumGrammarID,iGrammarID);
665 iView.SetColL(KRTColNumRuleID,aRuleData.iRuleID);
666 iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
667 iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
672 TBool CSDDatabase::RSDRuleTable::FindRuleL(TRuleID aRuleID)
674 TBool found = EFalse;
675 for (iView.FirstL();iView.AtRow();iView.NextL())
678 if (iView.ColUint32(KRTColNumRuleID)==aRuleID)
687 TBool CSDDatabase::RSDRuleTable::IsRuleValidL(TRuleID aRuleID)
689 TBool valid = EFalse;
690 TBool found = FindRuleL(aRuleID);
693 TLexiconID lexiconID = iView.ColUint32(KRTColNumLexiconID);
694 TPronunciationID pronunciationID = iView.ColUint32(KRTColNumPronunciationID);
695 if (iDatabase.LexiconExistsL(lexiconID) &&
696 iDatabase.PronunciationExistsL(lexiconID, pronunciationID))
702 User::Leave(KErrNotFound);
707 void CSDDatabase::RSDRuleTable::RemoveRuleL(TRuleID aRuleID)
709 if (FindRuleL(aRuleID))
711 iDatabase.StartTransactionL();
715 User::Leave(KErrNotFound);
718 void CSDDatabase::RSDRuleTable::GetAllRuleIDsL(RArray<TRuleID>& aRuleIDs)
721 for (iView.FirstL();iView.AtRow();iView.NextL())
724 TRuleID modelID = iView.ColUint32(KRTColNumRuleID);
725 User::LeaveIfError(aRuleIDs.Append(modelID));
728 //--------------------------------------------------------------------------------------------------
731 CSDDatabase* CSDDatabase::NewL(const TDesC& aFileName, TBool aUseExisting)
733 CSDDatabase* self = new (ELeave) CSDDatabase;
734 CleanupStack::PushL(self);
735 self->ConstructL(aFileName, aUseExisting);
741 void CSDDatabase::SetClientUid(TUid aClientUid)
743 iClientUid = aClientUid;
746 void CSDDatabase::ConstructL(const TDesC& aFileName, TBool aUseExisting)
749 OpenDatabaseL(aFileName);
751 CreateDatabaseL(aFileName);
754 void CSDDatabase::OpenDatabaseL(const TDesC& aFileName)
757 User::LeaveIfError(fsSession.Connect());
758 iDbStore = CFileStore::OpenL(fsSession,aFileName,EFileRead|EFileWrite);
759 // open the database from the root stream
760 iDatabase.OpenL(iDbStore,iDbStore->Root());
761 iDatabaseOpened = ETrue;
765 void CSDDatabase::CreateDatabaseL(const TDesC& aFileName)
768 User::LeaveIfError(fsSession.Connect());
769 iDbStore = CPermanentFileStore::ReplaceL(fsSession,aFileName,EFileRead|EFileWrite);
770 // Complete file store creation
771 iDbStore->SetTypeL(iDbStore->Layout());
773 // Create a database in the store
774 TStreamId id=iDatabase.CreateL(iDbStore);
775 iDbStore->SetRootL(id);
777 // Complete database creation by commiting the store
780 // create the CDs table
786 // add the inital settings
787 RSDSettingsTable settingsTable(*this);
788 settingsTable.OpenL();
789 CleanupClosePushL(settingsTable);
790 settingsTable.SetValueL(KSettingLastID, 0);
791 CleanupStack::PopAndDestroy(&settingsTable);
794 CSDDatabase::CSDDatabase()
799 CSDDatabase::~CSDDatabase()
803 if (iDatabase.InTransaction())
805 iDatabase.Rollback();
806 if (iDatabase.IsDamaged())
815 void CSDDatabase::DoCreateTablesL()
819 // create Grammar Table
820 columns=CDbColSet::NewLC();
821 columns->AddL(TDbCol(KColClientUID,EDbColUint32));
822 columns->AddL(TDbCol(KColGrammarID,EDbColUint32));
823 User::LeaveIfError(iDatabase.CreateTable(KTableGrammar,*columns));
824 CleanupStack::PopAndDestroy(columns);
826 // create Lexicon Table
827 columns=CDbColSet::NewLC();
828 columns->AddL(TDbCol(KColClientUID,EDbColUint32));
829 columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
830 User::LeaveIfError(iDatabase.CreateTable(KTableLexicon,*columns));
831 CleanupStack::PopAndDestroy(columns);
833 // create ModelBank Table
834 columns=CDbColSet::NewLC();
835 columns->AddL(TDbCol(KColClientUID,EDbColUint32));
836 columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
837 User::LeaveIfError(iDatabase.CreateTable(KTableModelBank,*columns));
838 CleanupStack::PopAndDestroy(columns);
841 columns=CDbColSet::NewLC();
842 columns->AddL(TDbCol(KColGrammarID,EDbColUint32));
843 columns->AddL(TDbCol(KColRuleID,EDbColUint32));
844 columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
845 columns->AddL(TDbCol(KColPronunciationID,EDbColUint32));
847 User::LeaveIfError(iDatabase.CreateTable(KTableRule,*columns));
848 CleanupStack::PopAndDestroy(columns);
850 // create Pronunciation Table
851 columns=CDbColSet::NewLC();
852 columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
853 columns->AddL(TDbCol(KColPronunciationID,EDbColUint32));
854 columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
855 columns->AddL(TDbCol(KColModelID,EDbColUint32));
856 User::LeaveIfError(iDatabase.CreateTable(KTablePronunciation,*columns));
857 CleanupStack::PopAndDestroy(columns);
859 // create Model Table
860 columns=CDbColSet::NewLC();
861 columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
862 columns->AddL(TDbCol(KColModelID,EDbColUint32));
863 columns->AddL(TDbCol(KColUtteranceDuration,EDbColUint32));
864 User::LeaveIfError(iDatabase.CreateTable(KTableModel,*columns));
865 CleanupStack::PopAndDestroy(columns);
867 // create Settings Table
868 columns=CDbColSet::NewLC();
869 columns->AddL(TDbCol(KColSettingsID,EDbColUint32));
870 columns->AddL(TDbCol(KColSettingsValue,EDbColUint32));
871 User::LeaveIfError(iDatabase.CreateTable(KTableSettings,*columns));
872 CleanupStack::PopAndDestroy(columns);
876 void CSDDatabase::DoCreateIndexesL()
882 TGrammarID CSDDatabase::CreateGrammarL()
884 TGrammarID grammarID;
885 RSDGrammarTable grammarTable(*this);
886 CleanupClosePushL(grammarTable);
887 grammarTable.OpenL();
888 grammarTable.CreateGrammarL(grammarID);
889 CleanupStack::PopAndDestroy(&grammarTable);
892 void CSDDatabase::AddGrammarL(TGrammarID aGrammarID)
894 RSDGrammarTable grammarTable(*this);
895 CleanupClosePushL(grammarTable);
896 grammarTable.OpenL();
897 grammarTable.AddGrammarL(aGrammarID);
898 CleanupStack::PopAndDestroy(&grammarTable);
901 void CSDDatabase::RemoveGrammarL(TGrammarID aGrammarID)
903 RSDGrammarTable grammarTable(*this);
904 CleanupClosePushL(grammarTable);
905 grammarTable.OpenL();
906 grammarTable.RemoveGrammarL(aGrammarID);
907 CleanupStack::PopAndDestroy(&grammarTable);
910 void CSDDatabase::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs, TBool aOwnedByClient)
912 RSDGrammarTable grammarTable(*this);
913 CleanupClosePushL(grammarTable);
914 grammarTable.OpenL(aOwnedByClient);
915 grammarTable.GetAllGrammarIDsL(aGrammarIDs);
916 CleanupStack::PopAndDestroy(&grammarTable);
918 TBool CSDDatabase::GrammarExistsL(TGrammarID aGrammarID)
920 RSDGrammarTable grammarTable(*this);
921 CleanupClosePushL(grammarTable);
922 grammarTable.OpenL();
923 TBool found = grammarTable.FindGrammarL(aGrammarID);
924 CleanupStack::PopAndDestroy(&grammarTable);
928 TLexiconID CSDDatabase::CreateLexiconL()
930 TLexiconID lexiconID;
931 RSDLexiconTable lexiconTable(*this);
932 CleanupClosePushL(lexiconTable);
933 lexiconTable.OpenL();
934 lexiconTable.CreateLexiconL(lexiconID);
935 CleanupStack::PopAndDestroy(&lexiconTable);
938 void CSDDatabase::AddLexiconL(TLexiconID aLexiconID)
940 RSDLexiconTable lexiconTable(*this);
941 CleanupClosePushL(lexiconTable);
942 lexiconTable.OpenL();
943 lexiconTable.AddLexiconL(aLexiconID);
944 CleanupStack::PopAndDestroy(&lexiconTable);
947 void CSDDatabase::RemoveLexiconL(TLexiconID aLexiconID)
949 RSDLexiconTable lexiconTable(*this);
950 CleanupClosePushL(lexiconTable);
951 lexiconTable.OpenL();
952 lexiconTable.RemoveLexiconL(aLexiconID);
953 CleanupStack::PopAndDestroy(&lexiconTable);
956 void CSDDatabase::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs, TBool aOwnedByClient)
958 RSDLexiconTable lexiconTable(*this);
959 CleanupClosePushL(lexiconTable);
960 lexiconTable.OpenL(aOwnedByClient);
961 lexiconTable.GetAllLexiconIDsL(aLexiconIDs);
962 CleanupStack::PopAndDestroy(&lexiconTable);
964 TBool CSDDatabase::LexiconExistsL(TLexiconID aLexiconID)
966 RSDLexiconTable lexiconTable(*this);
967 CleanupClosePushL(lexiconTable);
968 lexiconTable.OpenL();
969 TBool found = lexiconTable.FindLexiconL(aLexiconID);
970 CleanupStack::PopAndDestroy(&lexiconTable);
974 TModelBankID CSDDatabase::CreateModelBankL()
976 TModelBankID modelBankID;
977 RSDModelBankTable modelBankTable(*this);
978 CleanupClosePushL(modelBankTable);
979 modelBankTable.OpenL();
980 modelBankID = modelBankTable.CreateModelBankL();
981 CleanupStack::PopAndDestroy(&modelBankTable);
984 void CSDDatabase::AddModelBankL(TModelBankID aModelBankID)
986 RSDModelBankTable modelBankTable(*this);
987 CleanupClosePushL(modelBankTable);
988 modelBankTable.OpenL();
989 modelBankTable.AddModelBankL(aModelBankID);
990 CleanupStack::PopAndDestroy(&modelBankTable);
993 void CSDDatabase::RemoveModelBankL(TModelBankID aModelBankID)
995 RSDModelBankTable modelBankTable(*this);
996 CleanupClosePushL(modelBankTable);
997 modelBankTable.OpenL();
998 modelBankTable.RemoveModelBankL(aModelBankID);
999 CleanupStack::PopAndDestroy(&modelBankTable);
1002 void CSDDatabase::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs, TBool aOwnedByClient)
1004 RSDModelBankTable modelBankTable(*this);
1005 CleanupClosePushL(modelBankTable);
1006 modelBankTable.OpenL(aOwnedByClient);
1007 modelBankTable.GetAllModelBankIDsL(aModelBankIDs);
1008 CleanupStack::PopAndDestroy(&modelBankTable);
1010 TBool CSDDatabase::ModelBankExistsL(TModelBankID aModelBankID)
1012 RSDModelBankTable modelBankTable(*this);
1013 CleanupClosePushL(modelBankTable);
1014 modelBankTable.OpenL();
1015 TBool found = modelBankTable.FindModelBankL(aModelBankID);
1016 CleanupStack::PopAndDestroy(&modelBankTable);
1021 //------------------------------------------------------------------------------------------
1022 TModelID CSDDatabase::CreateModelL(TModelBankID aModelBankID, TModelData aModelData)
1024 // TModelID modelID;
1025 RSDModelTable modelTable(*this);
1026 CleanupClosePushL(modelTable);
1027 modelTable.OpenL(aModelBankID);
1028 // modelID = modelTable.CreateModelL(aModelData);
1029 modelTable.CreateModelL(aModelData); // EABI warning removal
1030 CleanupStack::PopAndDestroy(&modelTable);
1031 return aModelData.iModelID;
1033 void CSDDatabase::AddModelL(TModelBankID aModelBankID, TModelData aModelData)
1035 RSDModelTable modelTable(*this);
1036 CleanupClosePushL(modelTable);
1037 modelTable.OpenL(aModelBankID);
1038 modelTable.AddModelL(aModelData);
1039 CleanupStack::PopAndDestroy(&modelTable);
1042 void CSDDatabase::RemoveModelL(TModelBankID aModelBankID, TModelID aModelID)
1044 RSDModelTable modelTable(*this);
1045 CleanupClosePushL(modelTable);
1046 modelTable.OpenL(aModelBankID);
1047 modelTable.RemoveModelL(aModelID);
1048 CleanupStack::PopAndDestroy(&modelTable);
1051 void CSDDatabase::GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData)
1053 RSDModelTable modelTable(*this);
1054 CleanupClosePushL(modelTable);
1055 modelTable.OpenL(aModelBankID);
1056 modelTable.GetModelDataL(aModelID, aModelData);
1057 CleanupStack::PopAndDestroy(&modelTable);
1061 void CSDDatabase::GetAllModelIDsL(TModelBankID aModelBankID, RArray<TModelID>& aModelIDs)
1063 RSDModelTable modelTable(*this);
1064 CleanupClosePushL(modelTable);
1065 modelTable.OpenL(aModelBankID);
1066 modelTable.GetAllModelIDsL(aModelIDs);
1067 CleanupStack::PopAndDestroy(&modelTable);
1069 TBool CSDDatabase::ModelExistsL(TModelBankID aModelBankID, TModelID aModelID)
1071 RSDModelTable modelTable(*this);
1072 CleanupClosePushL(modelTable);
1073 modelTable.OpenL(aModelBankID);
1074 TBool found = modelTable.FindModelL(aModelID);
1075 CleanupStack::PopAndDestroy(&modelTable);
1078 //------------------------------------------------------------------------------------------
1079 TPronunciationID CSDDatabase::CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
1081 TPronunciationID pronunciationID;
1082 RSDPronunciationTable pronunciationTable(*this);
1083 CleanupClosePushL(pronunciationTable);
1084 pronunciationTable.OpenL(aLexiconID);
1085 pronunciationID = pronunciationTable.CreatePronunciationL(aPronunciationData);
1086 CleanupStack::PopAndDestroy(&pronunciationTable);
1087 return pronunciationID;
1089 void CSDDatabase::AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
1091 RSDPronunciationTable pronunciationTable(*this);
1092 CleanupClosePushL(pronunciationTable);
1093 pronunciationTable.OpenL(aLexiconID);
1094 pronunciationTable.AddPronunciationL(aPronunciationData);
1095 CleanupStack::PopAndDestroy(&pronunciationTable);
1098 void CSDDatabase::RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
1100 RSDPronunciationTable pronunciationTable(*this);
1101 CleanupClosePushL(pronunciationTable);
1102 pronunciationTable.OpenL(aLexiconID);
1103 pronunciationTable.RemovePronunciationL(aPronunciationID);
1104 CleanupStack::PopAndDestroy(&pronunciationTable);
1107 void CSDDatabase::GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
1109 RSDPronunciationTable pronunciationTable(*this);
1110 CleanupClosePushL(pronunciationTable);
1111 pronunciationTable.OpenL(aLexiconID);
1112 pronunciationTable.GetPronunciationDataL(aPronunciationID, aPronunciationData);
1113 CleanupStack::PopAndDestroy(&pronunciationTable);
1116 void CSDDatabase::GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs)
1118 RSDPronunciationTable pronunciationTable(*this);
1119 CleanupClosePushL(pronunciationTable);
1120 pronunciationTable.OpenL(aLexiconID);
1121 pronunciationTable.GetAllPronunciationIDsL(aPronunciationIDs);
1122 CleanupStack::PopAndDestroy(&pronunciationTable);
1124 TBool CSDDatabase::PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
1126 RSDPronunciationTable pronunciationTable(*this);
1127 CleanupClosePushL(pronunciationTable);
1128 pronunciationTable.OpenL(aLexiconID);
1129 TBool found = pronunciationTable.FindPronunciationL(aPronunciationID);
1130 CleanupStack::PopAndDestroy(&pronunciationTable);
1134 //------------------------------------------------------------------------------------------
1135 TRuleID CSDDatabase::CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
1138 RSDRuleTable ruleTable(*this);
1139 CleanupClosePushL(ruleTable);
1140 ruleTable.OpenL(aGrammarID);
1141 ruleID = ruleTable.CreateRuleL(aRuleData);
1142 CleanupStack::PopAndDestroy(&ruleTable);
1145 void CSDDatabase::AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
1147 RSDRuleTable ruleTable(*this);
1148 CleanupClosePushL(ruleTable);
1149 ruleTable.OpenL(aGrammarID);
1150 ruleTable.AddRuleL(aRuleData);
1151 CleanupStack::PopAndDestroy(&ruleTable);
1154 void CSDDatabase::RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID)
1156 RSDRuleTable ruleTable(*this);
1157 CleanupClosePushL(ruleTable);
1158 ruleTable.OpenL(aGrammarID);
1159 ruleTable.RemoveRuleL(aRuleID);
1160 CleanupStack::PopAndDestroy(&ruleTable);
1163 void CSDDatabase::GetAllRuleIDsL(TGrammarID aGrammarID, RArray<TRuleID>& aRuleIDs)
1165 RSDRuleTable ruleTable(*this);
1166 CleanupClosePushL(ruleTable);
1167 ruleTable.OpenL(aGrammarID);
1168 ruleTable.GetAllRuleIDsL(aRuleIDs);
1169 CleanupStack::PopAndDestroy(&ruleTable);
1171 TBool CSDDatabase::RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID)
1173 RSDRuleTable ruleTable(*this);
1174 CleanupClosePushL(ruleTable);
1175 ruleTable.OpenL(aGrammarID);
1176 TBool found = ruleTable.FindRuleL(aRuleID);
1177 CleanupStack::PopAndDestroy(&ruleTable);
1181 TUint32 CSDDatabase::AllocNewIDL()
1183 RSDSettingsTable settingsTable(*this);
1184 CleanupClosePushL(settingsTable);
1185 settingsTable.OpenL();
1186 TUint32 lastID = settingsTable.GetValueL(KSettingLastID);
1188 settingsTable.SetValueL(KSettingLastID, lastID);
1189 CleanupStack::PopAndDestroy(&settingsTable);
1193 void CSDDatabase::UpdateLastIDL(TUint32 aAddedID)
1195 RSDSettingsTable settingsTable(*this);
1196 CleanupClosePushL(settingsTable);
1197 settingsTable.OpenL();
1198 TUint32 lastID = settingsTable.GetValueL(KSettingLastID);
1199 if (aAddedID > lastID)
1200 settingsTable.SetValueL(KSettingLastID, aAddedID);
1201 CleanupStack::PopAndDestroy();
1205 //TUint32 CSDDatabase::iLastID = 100;
1207 TUid CSDDatabase::ClientUid()
1212 RDbDatabase& CSDDatabase::Database()
1217 void CSDDatabase::CommitChangesL()
1222 void CSDDatabase::StartTransactionL()
1224 if (!iDatabase.InTransaction())
1228 void CSDDatabase::CreateTestDatabaseL()
1232 for (i = 0;i<KNumGrammars;i++)
1233 AddGrammarL(KGrammarIDs[i]);
1236 for (i = 0;i<KNumLexicons;i++)
1237 AddLexiconL(KLexiconIDs[i]);
1240 for (i = 0;i<KNumLexicons;i++)
1241 AddModelBankL(KModelBankIDs[i]);
1244 for (i = 0;i<KNumGrammars;i++)
1245 for (j = 0; j < KNumRules; j++)
1247 TGrammarID grammarID = KGrammarIDs[i];
1248 TRuleData ruleData = KRuleIDs[i][j];
1249 AddRuleL(grammarID, ruleData);
1252 // Add Pronunciations
1253 for (i = 0;i<KNumLexicons;i++)
1254 for (j = 0; j < KNumPronunciations; j++)
1256 TLexiconID lexiconID = KLexiconIDs[i];
1257 TPronunciationData pronunciationData = KPronunciationIDs[i][j];
1258 AddPronunciationL(lexiconID, pronunciationData);
1262 for (i = 0;i<KNumModelBanks;i++)
1263 for (j = 0; j < KNumModels; j++)
1265 TModelData modelData = KModelIDs[i][j];
1266 TModelBankID modelBankID = KModelBankIDs[i];
1267 AddModelL(modelBankID, modelData);