sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "sddatabase.h" sl@0: #include "../Database/testdatabaseconstants.h" sl@0: sl@0: _LIT(KTableGrammar, "GrammarTable"); sl@0: _LIT(KTableLexicon, "LexiconTable"); sl@0: _LIT(KTableModelBank, "ModelBankTable"); sl@0: _LIT(KTableRule, "RuleTable"); sl@0: _LIT(KTablePronunciation, "PronunciationTable"); sl@0: _LIT(KTableModel, "ModelTable"); sl@0: _LIT(KTableSettings, "SettingsTable"); sl@0: sl@0: _LIT(KAllCols, "*"); sl@0: _LIT(KColClientUID, "ClientUID"); sl@0: _LIT(KColGrammarID, "GrammarID"); sl@0: _LIT(KColLexiconID, "LexiconID"); sl@0: _LIT(KColModelBankID,"ModelBankID"); sl@0: _LIT(KColRuleID,"RuleID"); sl@0: _LIT(KColPronunciationID,"PronunciationID"); sl@0: _LIT(KColModelID,"ModelID"); sl@0: _LIT(KColUtteranceDuration, "UtteranceDuration"); sl@0: _LIT(KColSettingsID,"SettingsID"); sl@0: _LIT(KColSettingsValue,"SettingsValue"); sl@0: sl@0: sl@0: _LIT(KSQLSelectFromTable,"Select %S From %S"); sl@0: _LIT(KSQLSelectFromTableWhereCondition,"Select %S From %S Where %S=%u"); sl@0: sl@0: const TInt KGTColNumClientUID = 1; sl@0: const TInt KGTColNumGrammarID = 2; sl@0: const TInt KLTColNumClientUID = 1; sl@0: const TInt KLTColNumLexiconID = 2; sl@0: const TInt KMBTColNumClientUID = 1; sl@0: const TInt KMBTColNumModelBankID = 2; sl@0: sl@0: const TInt KRTColNumGrammarID = 1; sl@0: const TInt KRTColNumRuleID = 2; sl@0: const TInt KRTColNumLexiconID = 3; sl@0: const TInt KRTColNumPronunciationID =4; sl@0: sl@0: const TInt KPTColNumLexiconID = 1; sl@0: const TInt KPTColNumPronunciationID = 2; sl@0: const TInt KPTColNumModelBankID = 3; sl@0: const TInt KPTColNumModelID = 4; sl@0: sl@0: const TInt KMTColNumModelBankID = 1; sl@0: const TInt KMTColNumModelID = 2; sl@0: const TInt KMTColNumUtteranceDurationMicroSeconds = 3; sl@0: sl@0: const TInt KSTColNumSettingsID = 1; sl@0: const TInt KSTColNumSettingsValue = 2; sl@0: sl@0: const TInt KSettingLastID = 1; sl@0: sl@0: sl@0: CSDDatabase::RSDGrammarTable::RSDGrammarTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDGrammarTable::OpenL(TBool aOwnedByClient) sl@0: { sl@0: TBuf<256> query; sl@0: if (aOwnedByClient) sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid()); sl@0: else sl@0: query.Format(KSQLSelectFromTable,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid()); sl@0: sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDGrammarTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDGrammarTable::CreateGrammarL(TGrammarID& aGrammarID) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: aGrammarID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: sl@0: iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KGTColNumGrammarID,aGrammarID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDGrammarTable::AddGrammarL(TGrammarID aGrammarID) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aGrammarID); sl@0: iView.InsertL(); sl@0: iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KGTColNumGrammarID,aGrammarID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: sl@0: TBool CSDDatabase::RSDGrammarTable::FindGrammarL(TGrammarID aGrammarID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KGTColNumGrammarID)==aGrammarID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: sl@0: sl@0: void CSDDatabase::RSDGrammarTable::RemoveGrammarL(TGrammarID aGrammarID) sl@0: { sl@0: if (FindGrammarL(aGrammarID)) sl@0: { sl@0: if (iView.ColUint32(KGTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound);//change to not owned sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDGrammarTable::GetAllGrammarIDsL(RArray& aGrammarIDs) sl@0: { sl@0: aGrammarIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TGrammarID grammarID = iView.ColUint32(KGTColNumGrammarID); sl@0: User::LeaveIfError(aGrammarIDs.Append(grammarID)); sl@0: } sl@0: } sl@0: sl@0: CSDDatabase::RSDLexiconTable::RSDLexiconTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDLexiconTable::OpenL(TBool aOwnedByClient) sl@0: { sl@0: TBuf<256> query; sl@0: if (aOwnedByClient) sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid()); sl@0: else sl@0: query.Format(KSQLSelectFromTable,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid()); sl@0: sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDLexiconTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDLexiconTable::CreateLexiconL(TLexiconID& aLexiconID) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: aLexiconID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: sl@0: iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KLTColNumLexiconID,aLexiconID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDLexiconTable::AddLexiconL(TLexiconID aLexiconID) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aLexiconID); sl@0: iView.InsertL(); sl@0: iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KLTColNumLexiconID,aLexiconID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: sl@0: TBool CSDDatabase::RSDLexiconTable::FindLexiconL(TLexiconID aLexiconID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KLTColNumLexiconID)==aLexiconID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: sl@0: sl@0: void CSDDatabase::RSDLexiconTable::RemoveLexiconL(TLexiconID aLexiconID) sl@0: { sl@0: if (FindLexiconL(aLexiconID)) sl@0: { sl@0: if (iView.ColUint32(KLTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound);//change to not owned sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDLexiconTable::GetAllLexiconIDsL(RArray& aLexiconIDs) sl@0: { sl@0: aLexiconIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TLexiconID lexiconID = iView.ColUint32(KLTColNumLexiconID); sl@0: User::LeaveIfError(aLexiconIDs.Append(lexiconID)); sl@0: } sl@0: } sl@0: sl@0: CSDDatabase::RSDModelBankTable::RSDModelBankTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelBankTable::OpenL(TBool aOwnedByClient) sl@0: { sl@0: TBuf<256> query; sl@0: if (aOwnedByClient) sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid()); sl@0: else sl@0: query.Format(KSQLSelectFromTable,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid()); sl@0: sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelBankTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: TModelBankID CSDDatabase::RSDModelBankTable::CreateModelBankL() sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: TModelBankID modelBankID; sl@0: modelBankID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: sl@0: iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KMBTColNumModelBankID,modelBankID); sl@0: iView.PutL(); sl@0: return modelBankID; sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelBankTable::AddModelBankL(TModelBankID aModelBankID) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aModelBankID); sl@0: iView.InsertL(); sl@0: iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid); sl@0: iView.SetColL(KMBTColNumModelBankID,aModelBankID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: sl@0: TBool CSDDatabase::RSDModelBankTable::FindModelBankL(TModelBankID aModelBankID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KMBTColNumModelBankID)==aModelBankID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: sl@0: sl@0: void CSDDatabase::RSDModelBankTable::RemoveModelBankL(TModelBankID aModelBankID) sl@0: { sl@0: if (FindModelBankL(aModelBankID)) sl@0: { sl@0: if (iView.ColUint32(KMBTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound);//change to not owned sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelBankTable::GetAllModelBankIDsL(RArray& aModelBankIDs) sl@0: { sl@0: aModelBankIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TModelBankID modelBankID = iView.ColUint32(KMBTColNumModelBankID); sl@0: User::LeaveIfError(aModelBankIDs.Append(modelBankID)); sl@0: } sl@0: } sl@0: sl@0: sl@0: CSDDatabase::RSDModelTable::RSDModelTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelTable::OpenL(TModelBankID aModelBankID) sl@0: { sl@0: if (!iDatabase.ModelBankExistsL(aModelBankID)) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: iModelBankID = aModelBankID; sl@0: TBuf<256> query; sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModel,&KColModelBankID,aModelBankID); sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: TModelID CSDDatabase::RSDModelTable::CreateModelL(TModelData aModelData) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: TModelID modelID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: iView.SetColL(KMTColNumModelBankID,iModelBankID); sl@0: iView.SetColL(KMTColNumModelID,modelID); sl@0: iView.SetColL(KMTColNumUtteranceDurationMicroSeconds,aModelData.iUtteranceDurationMicroSeconds); sl@0: iView.PutL(); sl@0: return modelID; sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelTable::AddModelL(TModelData aModelData) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aModelData.iModelID); sl@0: iView.InsertL(); sl@0: iView.SetColL(KMTColNumModelBankID,iModelBankID); sl@0: iView.SetColL(KMTColNumModelID,aModelData.iModelID); sl@0: iView.SetColL(KMTColNumUtteranceDurationMicroSeconds, aModelData.iUtteranceDurationMicroSeconds); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelTable::GetModelDataL(TModelID aModelID, TModelData& aModelData) sl@0: { sl@0: if (!FindModelL(aModelID)) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: iView.GetL(); sl@0: aModelData.iModelID = iView.ColUint32(KMTColNumModelID); sl@0: aModelData.iUtteranceDurationMicroSeconds = iView.ColUint32(KMTColNumUtteranceDurationMicroSeconds); sl@0: } sl@0: sl@0: sl@0: sl@0: TBool CSDDatabase::RSDModelTable::FindModelL(TModelID aModelID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KMTColNumModelID)==aModelID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: sl@0: sl@0: void CSDDatabase::RSDModelTable::RemoveModelL(TModelID aModelID) sl@0: { sl@0: if (FindModelL(aModelID)) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDModelTable::GetAllModelIDsL(RArray& aModelIDs) sl@0: { sl@0: aModelIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TModelID modelID = iView.ColUint32(KMTColNumModelID); sl@0: User::LeaveIfError(aModelIDs.Append(modelID)); sl@0: } sl@0: } sl@0: sl@0: //------------------------------------------------------------------------------------------------ sl@0: CSDDatabase::RSDSettingsTable::RSDSettingsTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDSettingsTable::OpenL() sl@0: { sl@0: TBuf<256> query; sl@0: query.Format(KSQLSelectFromTable,&KAllCols,&KTableSettings); sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: } sl@0: sl@0: void CSDDatabase::RSDSettingsTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: TUint32 CSDDatabase::RSDSettingsTable::GetValueL(TUint32 aSettingID) sl@0: { sl@0: TUint32 value = 0; sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KSTColNumSettingsID)==aSettingID) sl@0: { sl@0: value = iView.ColUint32(KSTColNumSettingsValue); sl@0: found = ETrue; sl@0: break; sl@0: } sl@0: sl@0: } sl@0: if (!found) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: return value; sl@0: } sl@0: sl@0: void CSDDatabase::RSDSettingsTable::SetValueL(TUint32 aSettingID, TUint32 aValue) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KSTColNumSettingsID)==aSettingID) sl@0: { sl@0: iView.UpdateL(); sl@0: iView.SetColL(KSTColNumSettingsValue, aValue); sl@0: iView.PutL(); sl@0: found = ETrue; sl@0: break; sl@0: } sl@0: sl@0: } sl@0: // if it wasn't found, add it sl@0: if (!found) sl@0: { sl@0: iView.InsertL(); sl@0: iView.SetColL(KSTColNumSettingsID, aSettingID); sl@0: iView.SetColL(KSTColNumSettingsValue, aValue); sl@0: iView.PutL(); sl@0: } sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------------------------------------ sl@0: sl@0: CSDDatabase::RSDPronunciationTable::RSDPronunciationTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::OpenL(TLexiconID aLexiconID) sl@0: { sl@0: if (!iDatabase.LexiconExistsL(aLexiconID)) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: iLexiconID = aLexiconID; sl@0: TBuf<256> query; sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTablePronunciation,&KColLexiconID,aLexiconID); sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: TPronunciationID CSDDatabase::RSDPronunciationTable::CreatePronunciationL(TPronunciationData aPronunciationData) sl@0: { sl@0: TPronunciationID pronunciationID; sl@0: iDatabase.StartTransactionL(); sl@0: pronunciationID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: iView.SetColL(KPTColNumLexiconID,iLexiconID); sl@0: iView.SetColL(KPTColNumPronunciationID,pronunciationID); sl@0: iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID); sl@0: iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID); sl@0: iView.PutL(); sl@0: return pronunciationID; sl@0: } sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::AddPronunciationL(TPronunciationData aPronunciationData) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aPronunciationData.iPronunciationID); sl@0: iView.InsertL(); sl@0: iView.SetColL(KPTColNumLexiconID,iLexiconID); sl@0: iView.SetColL(KPTColNumPronunciationID,aPronunciationData.iPronunciationID); sl@0: iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID); sl@0: iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData) sl@0: { sl@0: if (!FindPronunciationL(aPronunciationID)) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: iView.GetL(); sl@0: aPronunciationData.iPronunciationID = iView.ColUint32(KPTColNumPronunciationID); sl@0: aPronunciationData.iModelBankID = iView.ColUint32(KPTColNumModelBankID); sl@0: aPronunciationData.iModelID = iView.ColUint32(KPTColNumModelID); sl@0: } sl@0: sl@0: sl@0: sl@0: TBool CSDDatabase::RSDPronunciationTable::FindPronunciationL(TPronunciationID aPronunciationID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KPTColNumPronunciationID)==aPronunciationID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::RemovePronunciationL(TPronunciationID aPronunciationID) sl@0: { sl@0: if (FindPronunciationL(aPronunciationID)) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDPronunciationTable::GetAllPronunciationIDsL(RArray& aPronunciationIDs) sl@0: { sl@0: aPronunciationIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TPronunciationID modelID = iView.ColUint32(KPTColNumPronunciationID); sl@0: User::LeaveIfError(aPronunciationIDs.Append(modelID)); sl@0: } sl@0: } sl@0: //-------------------------------------------------------------------------------------------------- sl@0: sl@0: CSDDatabase::RSDRuleTable::RSDRuleTable(CSDDatabase& aDatabase) sl@0: : iDatabase(aDatabase) sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDRuleTable::OpenL(TGrammarID aGrammarID) sl@0: { sl@0: if (!iDatabase.GrammarExistsL(aGrammarID)) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: iGrammarID = aGrammarID; sl@0: TBuf<256> query; sl@0: query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableRule,&KColGrammarID,aGrammarID); sl@0: User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal))); sl@0: User::LeaveIfError(iView.EvaluateAll()); sl@0: sl@0: } sl@0: sl@0: void CSDDatabase::RSDRuleTable::Close() sl@0: { sl@0: iView.Close(); sl@0: } sl@0: sl@0: TRuleID CSDDatabase::RSDRuleTable::CreateRuleL(TRuleData aRuleData) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: TRuleID ruleID = iDatabase.AllocNewIDL(); sl@0: iView.InsertL(); sl@0: iView.SetColL(KRTColNumGrammarID,iGrammarID); sl@0: iView.SetColL(KRTColNumRuleID,ruleID); sl@0: iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID); sl@0: iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID); sl@0: iView.PutL(); sl@0: return ruleID; sl@0: } sl@0: sl@0: void CSDDatabase::RSDRuleTable::AddRuleL(TRuleData aRuleData) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iDatabase.UpdateLastIDL(aRuleData.iRuleID); sl@0: sl@0: iView.InsertL(); sl@0: iView.SetColL(KRTColNumGrammarID,iGrammarID); sl@0: iView.SetColL(KRTColNumRuleID,aRuleData.iRuleID); sl@0: iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID); sl@0: iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID); sl@0: iView.PutL(); sl@0: } sl@0: sl@0: sl@0: TBool CSDDatabase::RSDRuleTable::FindRuleL(TRuleID aRuleID) sl@0: { sl@0: TBool found = EFalse; sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: if (iView.ColUint32(KRTColNumRuleID)==aRuleID) sl@0: { sl@0: found = true; sl@0: break; sl@0: } sl@0: } sl@0: return found; sl@0: } sl@0: sl@0: TBool CSDDatabase::RSDRuleTable::IsRuleValidL(TRuleID aRuleID) sl@0: { sl@0: TBool valid = EFalse; sl@0: TBool found = FindRuleL(aRuleID); sl@0: if (found) sl@0: { sl@0: TLexiconID lexiconID = iView.ColUint32(KRTColNumLexiconID); sl@0: TPronunciationID pronunciationID = iView.ColUint32(KRTColNumPronunciationID); sl@0: if (iDatabase.LexiconExistsL(lexiconID) && sl@0: iDatabase.PronunciationExistsL(lexiconID, pronunciationID)) sl@0: { sl@0: valid = ETrue; sl@0: } sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: return valid; sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::RSDRuleTable::RemoveRuleL(TRuleID aRuleID) sl@0: { sl@0: if (FindRuleL(aRuleID)) sl@0: { sl@0: iDatabase.StartTransactionL(); sl@0: iView.DeleteL(); sl@0: } sl@0: else sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: sl@0: void CSDDatabase::RSDRuleTable::GetAllRuleIDsL(RArray& aRuleIDs) sl@0: { sl@0: aRuleIDs.Reset(); sl@0: for (iView.FirstL();iView.AtRow();iView.NextL()) sl@0: { sl@0: iView.GetL(); sl@0: TRuleID modelID = iView.ColUint32(KRTColNumRuleID); sl@0: User::LeaveIfError(aRuleIDs.Append(modelID)); sl@0: } sl@0: } sl@0: //-------------------------------------------------------------------------------------------------- sl@0: sl@0: sl@0: CSDDatabase* CSDDatabase::NewL(const TDesC& aFileName, TBool aUseExisting) sl@0: { sl@0: CSDDatabase* self = new (ELeave) CSDDatabase; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aFileName, aUseExisting); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::SetClientUid(TUid aClientUid) sl@0: { sl@0: iClientUid = aClientUid; sl@0: } sl@0: sl@0: void CSDDatabase::ConstructL(const TDesC& aFileName, TBool aUseExisting) sl@0: { sl@0: if (aUseExisting) sl@0: OpenDatabaseL(aFileName); sl@0: else sl@0: CreateDatabaseL(aFileName); sl@0: } sl@0: sl@0: void CSDDatabase::OpenDatabaseL(const TDesC& aFileName) sl@0: { sl@0: RFs fsSession; sl@0: User::LeaveIfError(fsSession.Connect()); sl@0: iDbStore = CFileStore::OpenL(fsSession,aFileName,EFileRead|EFileWrite); sl@0: // open the database from the root stream sl@0: iDatabase.OpenL(iDbStore,iDbStore->Root()); sl@0: iDatabaseOpened = ETrue; sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::CreateDatabaseL(const TDesC& aFileName) sl@0: { sl@0: RFs fsSession; sl@0: User::LeaveIfError(fsSession.Connect()); sl@0: iDbStore = CPermanentFileStore::ReplaceL(fsSession,aFileName,EFileRead|EFileWrite); sl@0: // Complete file store creation sl@0: iDbStore->SetTypeL(iDbStore->Layout()); sl@0: sl@0: // Create a database in the store sl@0: TStreamId id=iDatabase.CreateL(iDbStore); sl@0: iDbStore->SetRootL(id); sl@0: sl@0: // Complete database creation by commiting the store sl@0: iDbStore->CommitL(); sl@0: sl@0: // create the CDs table sl@0: DoCreateTablesL(); sl@0: sl@0: // create an index sl@0: DoCreateIndexesL(); sl@0: sl@0: // add the inital settings sl@0: RSDSettingsTable settingsTable(*this); sl@0: settingsTable.OpenL(); sl@0: CleanupClosePushL(settingsTable); sl@0: settingsTable.SetValueL(KSettingLastID, 0); sl@0: CleanupStack::PopAndDestroy(&settingsTable); sl@0: } sl@0: sl@0: CSDDatabase::CSDDatabase() sl@0: { sl@0: sl@0: } sl@0: sl@0: CSDDatabase::~CSDDatabase() sl@0: { sl@0: if (iDatabaseOpened) sl@0: { sl@0: if (iDatabase.InTransaction()) sl@0: { sl@0: iDatabase.Rollback(); sl@0: if (iDatabase.IsDamaged()) sl@0: iDatabase.Recover(); sl@0: } sl@0: } sl@0: iDatabase.Close(); sl@0: delete iDbStore; sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::DoCreateTablesL() sl@0: { sl@0: CDbColSet* columns; sl@0: sl@0: // create Grammar Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColClientUID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColGrammarID,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableGrammar,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create Lexicon Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColClientUID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColLexiconID,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableLexicon,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create ModelBank Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColClientUID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColModelBankID,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableModelBank,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create Rule Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColGrammarID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColRuleID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColLexiconID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColPronunciationID,EDbColUint32)); sl@0: sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableRule,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create Pronunciation Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColLexiconID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColPronunciationID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColModelBankID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColModelID,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTablePronunciation,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create Model Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColModelBankID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColModelID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColUtteranceDuration,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableModel,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: sl@0: // create Settings Table sl@0: columns=CDbColSet::NewLC(); sl@0: columns->AddL(TDbCol(KColSettingsID,EDbColUint32)); sl@0: columns->AddL(TDbCol(KColSettingsValue,EDbColUint32)); sl@0: User::LeaveIfError(iDatabase.CreateTable(KTableSettings,*columns)); sl@0: CleanupStack::PopAndDestroy(columns); sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::DoCreateIndexesL() sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: TGrammarID CSDDatabase::CreateGrammarL() sl@0: { sl@0: TGrammarID grammarID; sl@0: RSDGrammarTable grammarTable(*this); sl@0: CleanupClosePushL(grammarTable); sl@0: grammarTable.OpenL(); sl@0: grammarTable.CreateGrammarL(grammarID); sl@0: CleanupStack::PopAndDestroy(&grammarTable); sl@0: return grammarID; sl@0: } sl@0: void CSDDatabase::AddGrammarL(TGrammarID aGrammarID) sl@0: { sl@0: RSDGrammarTable grammarTable(*this); sl@0: CleanupClosePushL(grammarTable); sl@0: grammarTable.OpenL(); sl@0: grammarTable.AddGrammarL(aGrammarID); sl@0: CleanupStack::PopAndDestroy(&grammarTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemoveGrammarL(TGrammarID aGrammarID) sl@0: { sl@0: RSDGrammarTable grammarTable(*this); sl@0: CleanupClosePushL(grammarTable); sl@0: grammarTable.OpenL(); sl@0: grammarTable.RemoveGrammarL(aGrammarID); sl@0: CleanupStack::PopAndDestroy(&grammarTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetAllGrammarIDsL(RArray& aGrammarIDs, TBool aOwnedByClient) sl@0: { sl@0: RSDGrammarTable grammarTable(*this); sl@0: CleanupClosePushL(grammarTable); sl@0: grammarTable.OpenL(aOwnedByClient); sl@0: grammarTable.GetAllGrammarIDsL(aGrammarIDs); sl@0: CleanupStack::PopAndDestroy(&grammarTable); sl@0: } sl@0: TBool CSDDatabase::GrammarExistsL(TGrammarID aGrammarID) sl@0: { sl@0: RSDGrammarTable grammarTable(*this); sl@0: CleanupClosePushL(grammarTable); sl@0: grammarTable.OpenL(); sl@0: TBool found = grammarTable.FindGrammarL(aGrammarID); sl@0: CleanupStack::PopAndDestroy(&grammarTable); sl@0: return found; sl@0: } sl@0: sl@0: TLexiconID CSDDatabase::CreateLexiconL() sl@0: { sl@0: TLexiconID lexiconID; sl@0: RSDLexiconTable lexiconTable(*this); sl@0: CleanupClosePushL(lexiconTable); sl@0: lexiconTable.OpenL(); sl@0: lexiconTable.CreateLexiconL(lexiconID); sl@0: CleanupStack::PopAndDestroy(&lexiconTable); sl@0: return lexiconID; sl@0: } sl@0: void CSDDatabase::AddLexiconL(TLexiconID aLexiconID) sl@0: { sl@0: RSDLexiconTable lexiconTable(*this); sl@0: CleanupClosePushL(lexiconTable); sl@0: lexiconTable.OpenL(); sl@0: lexiconTable.AddLexiconL(aLexiconID); sl@0: CleanupStack::PopAndDestroy(&lexiconTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemoveLexiconL(TLexiconID aLexiconID) sl@0: { sl@0: RSDLexiconTable lexiconTable(*this); sl@0: CleanupClosePushL(lexiconTable); sl@0: lexiconTable.OpenL(); sl@0: lexiconTable.RemoveLexiconL(aLexiconID); sl@0: CleanupStack::PopAndDestroy(&lexiconTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetAllLexiconIDsL(RArray& aLexiconIDs, TBool aOwnedByClient) sl@0: { sl@0: RSDLexiconTable lexiconTable(*this); sl@0: CleanupClosePushL(lexiconTable); sl@0: lexiconTable.OpenL(aOwnedByClient); sl@0: lexiconTable.GetAllLexiconIDsL(aLexiconIDs); sl@0: CleanupStack::PopAndDestroy(&lexiconTable); sl@0: } sl@0: TBool CSDDatabase::LexiconExistsL(TLexiconID aLexiconID) sl@0: { sl@0: RSDLexiconTable lexiconTable(*this); sl@0: CleanupClosePushL(lexiconTable); sl@0: lexiconTable.OpenL(); sl@0: TBool found = lexiconTable.FindLexiconL(aLexiconID); sl@0: CleanupStack::PopAndDestroy(&lexiconTable); sl@0: return found; sl@0: } sl@0: sl@0: TModelBankID CSDDatabase::CreateModelBankL() sl@0: { sl@0: TModelBankID modelBankID; sl@0: RSDModelBankTable modelBankTable(*this); sl@0: CleanupClosePushL(modelBankTable); sl@0: modelBankTable.OpenL(); sl@0: modelBankID = modelBankTable.CreateModelBankL(); sl@0: CleanupStack::PopAndDestroy(&modelBankTable); sl@0: return modelBankID; sl@0: } sl@0: void CSDDatabase::AddModelBankL(TModelBankID aModelBankID) sl@0: { sl@0: RSDModelBankTable modelBankTable(*this); sl@0: CleanupClosePushL(modelBankTable); sl@0: modelBankTable.OpenL(); sl@0: modelBankTable.AddModelBankL(aModelBankID); sl@0: CleanupStack::PopAndDestroy(&modelBankTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemoveModelBankL(TModelBankID aModelBankID) sl@0: { sl@0: RSDModelBankTable modelBankTable(*this); sl@0: CleanupClosePushL(modelBankTable); sl@0: modelBankTable.OpenL(); sl@0: modelBankTable.RemoveModelBankL(aModelBankID); sl@0: CleanupStack::PopAndDestroy(&modelBankTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetAllModelBankIDsL(RArray& aModelBankIDs, TBool aOwnedByClient) sl@0: { sl@0: RSDModelBankTable modelBankTable(*this); sl@0: CleanupClosePushL(modelBankTable); sl@0: modelBankTable.OpenL(aOwnedByClient); sl@0: modelBankTable.GetAllModelBankIDsL(aModelBankIDs); sl@0: CleanupStack::PopAndDestroy(&modelBankTable); sl@0: } sl@0: TBool CSDDatabase::ModelBankExistsL(TModelBankID aModelBankID) sl@0: { sl@0: RSDModelBankTable modelBankTable(*this); sl@0: CleanupClosePushL(modelBankTable); sl@0: modelBankTable.OpenL(); sl@0: TBool found = modelBankTable.FindModelBankL(aModelBankID); sl@0: CleanupStack::PopAndDestroy(&modelBankTable); sl@0: return found; sl@0: } sl@0: sl@0: sl@0: //------------------------------------------------------------------------------------------ sl@0: TModelID CSDDatabase::CreateModelL(TModelBankID aModelBankID, TModelData aModelData) sl@0: { sl@0: // TModelID modelID; sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: // modelID = modelTable.CreateModelL(aModelData); sl@0: modelTable.CreateModelL(aModelData); // EABI warning removal sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: return aModelData.iModelID; sl@0: } sl@0: void CSDDatabase::AddModelL(TModelBankID aModelBankID, TModelData aModelData) sl@0: { sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: modelTable.AddModelL(aModelData); sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemoveModelL(TModelBankID aModelBankID, TModelID aModelID) sl@0: { sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: modelTable.RemoveModelL(aModelID); sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData) sl@0: { sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: modelTable.GetModelDataL(aModelID, aModelData); sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: } sl@0: sl@0: sl@0: void CSDDatabase::GetAllModelIDsL(TModelBankID aModelBankID, RArray& aModelIDs) sl@0: { sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: modelTable.GetAllModelIDsL(aModelIDs); sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: } sl@0: TBool CSDDatabase::ModelExistsL(TModelBankID aModelBankID, TModelID aModelID) sl@0: { sl@0: RSDModelTable modelTable(*this); sl@0: CleanupClosePushL(modelTable); sl@0: modelTable.OpenL(aModelBankID); sl@0: TBool found = modelTable.FindModelL(aModelID); sl@0: CleanupStack::PopAndDestroy(&modelTable); sl@0: return found; sl@0: } sl@0: //------------------------------------------------------------------------------------------ sl@0: TPronunciationID CSDDatabase::CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData) sl@0: { sl@0: TPronunciationID pronunciationID; sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: pronunciationID = pronunciationTable.CreatePronunciationL(aPronunciationData); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: return pronunciationID; sl@0: } sl@0: void CSDDatabase::AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData) sl@0: { sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: pronunciationTable.AddPronunciationL(aPronunciationData); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID) sl@0: { sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: pronunciationTable.RemovePronunciationL(aPronunciationID); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData) sl@0: { sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: pronunciationTable.GetPronunciationDataL(aPronunciationID, aPronunciationData); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray& aPronunciationIDs) sl@0: { sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: pronunciationTable.GetAllPronunciationIDsL(aPronunciationIDs); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: } sl@0: TBool CSDDatabase::PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID) sl@0: { sl@0: RSDPronunciationTable pronunciationTable(*this); sl@0: CleanupClosePushL(pronunciationTable); sl@0: pronunciationTable.OpenL(aLexiconID); sl@0: TBool found = pronunciationTable.FindPronunciationL(aPronunciationID); sl@0: CleanupStack::PopAndDestroy(&pronunciationTable); sl@0: return found; sl@0: } sl@0: sl@0: //------------------------------------------------------------------------------------------ sl@0: TRuleID CSDDatabase::CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData) sl@0: { sl@0: TRuleID ruleID; sl@0: RSDRuleTable ruleTable(*this); sl@0: CleanupClosePushL(ruleTable); sl@0: ruleTable.OpenL(aGrammarID); sl@0: ruleID = ruleTable.CreateRuleL(aRuleData); sl@0: CleanupStack::PopAndDestroy(&ruleTable); sl@0: return ruleID; sl@0: } sl@0: void CSDDatabase::AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData) sl@0: { sl@0: RSDRuleTable ruleTable(*this); sl@0: CleanupClosePushL(ruleTable); sl@0: ruleTable.OpenL(aGrammarID); sl@0: ruleTable.AddRuleL(aRuleData); sl@0: CleanupStack::PopAndDestroy(&ruleTable); sl@0: } sl@0: sl@0: void CSDDatabase::RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID) sl@0: { sl@0: RSDRuleTable ruleTable(*this); sl@0: CleanupClosePushL(ruleTable); sl@0: ruleTable.OpenL(aGrammarID); sl@0: ruleTable.RemoveRuleL(aRuleID); sl@0: CleanupStack::PopAndDestroy(&ruleTable); sl@0: } sl@0: sl@0: void CSDDatabase::GetAllRuleIDsL(TGrammarID aGrammarID, RArray& aRuleIDs) sl@0: { sl@0: RSDRuleTable ruleTable(*this); sl@0: CleanupClosePushL(ruleTable); sl@0: ruleTable.OpenL(aGrammarID); sl@0: ruleTable.GetAllRuleIDsL(aRuleIDs); sl@0: CleanupStack::PopAndDestroy(&ruleTable); sl@0: } sl@0: TBool CSDDatabase::RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID) sl@0: { sl@0: RSDRuleTable ruleTable(*this); sl@0: CleanupClosePushL(ruleTable); sl@0: ruleTable.OpenL(aGrammarID); sl@0: TBool found = ruleTable.FindRuleL(aRuleID); sl@0: CleanupStack::PopAndDestroy(&ruleTable); sl@0: return found; sl@0: } sl@0: sl@0: TUint32 CSDDatabase::AllocNewIDL() sl@0: { sl@0: RSDSettingsTable settingsTable(*this); sl@0: CleanupClosePushL(settingsTable); sl@0: settingsTable.OpenL(); sl@0: TUint32 lastID = settingsTable.GetValueL(KSettingLastID); sl@0: lastID++; sl@0: settingsTable.SetValueL(KSettingLastID, lastID); sl@0: CleanupStack::PopAndDestroy(&settingsTable); sl@0: return lastID; sl@0: } sl@0: sl@0: void CSDDatabase::UpdateLastIDL(TUint32 aAddedID) sl@0: { sl@0: RSDSettingsTable settingsTable(*this); sl@0: CleanupClosePushL(settingsTable); sl@0: settingsTable.OpenL(); sl@0: TUint32 lastID = settingsTable.GetValueL(KSettingLastID); sl@0: if (aAddedID > lastID) sl@0: settingsTable.SetValueL(KSettingLastID, aAddedID); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: sl@0: //TUint32 CSDDatabase::iLastID = 100; sl@0: sl@0: TUid CSDDatabase::ClientUid() sl@0: { sl@0: return iClientUid; sl@0: } sl@0: sl@0: RDbDatabase& CSDDatabase::Database() sl@0: { sl@0: return iDatabase; sl@0: } sl@0: sl@0: void CSDDatabase::CommitChangesL() sl@0: { sl@0: iDatabase.Commit(); sl@0: } sl@0: sl@0: void CSDDatabase::StartTransactionL() sl@0: { sl@0: if (!iDatabase.InTransaction()) sl@0: iDatabase.Begin(); sl@0: } sl@0: sl@0: void CSDDatabase::CreateTestDatabaseL() sl@0: { sl@0: TInt i,j; sl@0: // Add Grammars sl@0: for (i = 0;i