1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/Database/sddatabase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1272 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "sddatabase.h"
1.20 +#include "../Database/testdatabaseconstants.h"
1.21 +
1.22 +_LIT(KTableGrammar, "GrammarTable");
1.23 +_LIT(KTableLexicon, "LexiconTable");
1.24 +_LIT(KTableModelBank, "ModelBankTable");
1.25 +_LIT(KTableRule, "RuleTable");
1.26 +_LIT(KTablePronunciation, "PronunciationTable");
1.27 +_LIT(KTableModel, "ModelTable");
1.28 +_LIT(KTableSettings, "SettingsTable");
1.29 +
1.30 +_LIT(KAllCols, "*");
1.31 +_LIT(KColClientUID, "ClientUID");
1.32 +_LIT(KColGrammarID, "GrammarID");
1.33 +_LIT(KColLexiconID, "LexiconID");
1.34 +_LIT(KColModelBankID,"ModelBankID");
1.35 +_LIT(KColRuleID,"RuleID");
1.36 +_LIT(KColPronunciationID,"PronunciationID");
1.37 +_LIT(KColModelID,"ModelID");
1.38 +_LIT(KColUtteranceDuration, "UtteranceDuration");
1.39 +_LIT(KColSettingsID,"SettingsID");
1.40 +_LIT(KColSettingsValue,"SettingsValue");
1.41 +
1.42 +
1.43 +_LIT(KSQLSelectFromTable,"Select %S From %S");
1.44 +_LIT(KSQLSelectFromTableWhereCondition,"Select %S From %S Where %S=%u");
1.45 +
1.46 +const TInt KGTColNumClientUID = 1;
1.47 +const TInt KGTColNumGrammarID = 2;
1.48 +const TInt KLTColNumClientUID = 1;
1.49 +const TInt KLTColNumLexiconID = 2;
1.50 +const TInt KMBTColNumClientUID = 1;
1.51 +const TInt KMBTColNumModelBankID = 2;
1.52 +
1.53 +const TInt KRTColNumGrammarID = 1;
1.54 +const TInt KRTColNumRuleID = 2;
1.55 +const TInt KRTColNumLexiconID = 3;
1.56 +const TInt KRTColNumPronunciationID =4;
1.57 +
1.58 +const TInt KPTColNumLexiconID = 1;
1.59 +const TInt KPTColNumPronunciationID = 2;
1.60 +const TInt KPTColNumModelBankID = 3;
1.61 +const TInt KPTColNumModelID = 4;
1.62 +
1.63 +const TInt KMTColNumModelBankID = 1;
1.64 +const TInt KMTColNumModelID = 2;
1.65 +const TInt KMTColNumUtteranceDurationMicroSeconds = 3;
1.66 +
1.67 +const TInt KSTColNumSettingsID = 1;
1.68 +const TInt KSTColNumSettingsValue = 2;
1.69 +
1.70 +const TInt KSettingLastID = 1;
1.71 +
1.72 +
1.73 +CSDDatabase::RSDGrammarTable::RSDGrammarTable(CSDDatabase& aDatabase)
1.74 + : iDatabase(aDatabase)
1.75 + {
1.76 +
1.77 +
1.78 + }
1.79 +
1.80 +void CSDDatabase::RSDGrammarTable::OpenL(TBool aOwnedByClient)
1.81 + {
1.82 + TBuf<256> query;
1.83 + if (aOwnedByClient)
1.84 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
1.85 + else
1.86 + query.Format(KSQLSelectFromTable,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
1.87 +
1.88 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.89 + User::LeaveIfError(iView.EvaluateAll());
1.90 +
1.91 + }
1.92 +
1.93 +void CSDDatabase::RSDGrammarTable::Close()
1.94 + {
1.95 + iView.Close();
1.96 + }
1.97 +
1.98 +void CSDDatabase::RSDGrammarTable::CreateGrammarL(TGrammarID& aGrammarID)
1.99 + {
1.100 + iDatabase.StartTransactionL();
1.101 + aGrammarID = iDatabase.AllocNewIDL();
1.102 + iView.InsertL();
1.103 +
1.104 + iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
1.105 + iView.SetColL(KGTColNumGrammarID,aGrammarID);
1.106 + iView.PutL();
1.107 + }
1.108 +
1.109 +void CSDDatabase::RSDGrammarTable::AddGrammarL(TGrammarID aGrammarID)
1.110 + {
1.111 + iDatabase.StartTransactionL();
1.112 + iDatabase.UpdateLastIDL(aGrammarID);
1.113 + iView.InsertL();
1.114 + iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
1.115 + iView.SetColL(KGTColNumGrammarID,aGrammarID);
1.116 + iView.PutL();
1.117 + }
1.118 +
1.119 +
1.120 +TBool CSDDatabase::RSDGrammarTable::FindGrammarL(TGrammarID aGrammarID)
1.121 + {
1.122 + TBool found = EFalse;
1.123 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.124 + {
1.125 + iView.GetL();
1.126 + if (iView.ColUint32(KGTColNumGrammarID)==aGrammarID)
1.127 + {
1.128 + found = true;
1.129 + break;
1.130 + }
1.131 + }
1.132 + return found;
1.133 + }
1.134 +
1.135 +
1.136 +
1.137 +void CSDDatabase::RSDGrammarTable::RemoveGrammarL(TGrammarID aGrammarID)
1.138 + {
1.139 + if (FindGrammarL(aGrammarID))
1.140 + {
1.141 + if (iView.ColUint32(KGTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
1.142 + {
1.143 + iDatabase.StartTransactionL();
1.144 + iView.DeleteL();
1.145 + }
1.146 + else
1.147 + User::Leave(KErrNotFound);//change to not owned
1.148 + }
1.149 + else
1.150 + User::Leave(KErrNotFound);
1.151 + }
1.152 +
1.153 +void CSDDatabase::RSDGrammarTable::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs)
1.154 + {
1.155 + aGrammarIDs.Reset();
1.156 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.157 + {
1.158 + iView.GetL();
1.159 + TGrammarID grammarID = iView.ColUint32(KGTColNumGrammarID);
1.160 + User::LeaveIfError(aGrammarIDs.Append(grammarID));
1.161 + }
1.162 + }
1.163 +
1.164 +CSDDatabase::RSDLexiconTable::RSDLexiconTable(CSDDatabase& aDatabase)
1.165 + : iDatabase(aDatabase)
1.166 + {
1.167 +
1.168 +
1.169 + }
1.170 +
1.171 +void CSDDatabase::RSDLexiconTable::OpenL(TBool aOwnedByClient)
1.172 + {
1.173 + TBuf<256> query;
1.174 + if (aOwnedByClient)
1.175 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
1.176 + else
1.177 + query.Format(KSQLSelectFromTable,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
1.178 +
1.179 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.180 + User::LeaveIfError(iView.EvaluateAll());
1.181 +
1.182 + }
1.183 +
1.184 +void CSDDatabase::RSDLexiconTable::Close()
1.185 + {
1.186 + iView.Close();
1.187 + }
1.188 +
1.189 +void CSDDatabase::RSDLexiconTable::CreateLexiconL(TLexiconID& aLexiconID)
1.190 + {
1.191 + iDatabase.StartTransactionL();
1.192 + aLexiconID = iDatabase.AllocNewIDL();
1.193 + iView.InsertL();
1.194 +
1.195 + iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
1.196 + iView.SetColL(KLTColNumLexiconID,aLexiconID);
1.197 + iView.PutL();
1.198 + }
1.199 +
1.200 +void CSDDatabase::RSDLexiconTable::AddLexiconL(TLexiconID aLexiconID)
1.201 + {
1.202 + iDatabase.StartTransactionL();
1.203 + iDatabase.UpdateLastIDL(aLexiconID);
1.204 + iView.InsertL();
1.205 + iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
1.206 + iView.SetColL(KLTColNumLexiconID,aLexiconID);
1.207 + iView.PutL();
1.208 + }
1.209 +
1.210 +
1.211 +TBool CSDDatabase::RSDLexiconTable::FindLexiconL(TLexiconID aLexiconID)
1.212 + {
1.213 + TBool found = EFalse;
1.214 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.215 + {
1.216 + iView.GetL();
1.217 + if (iView.ColUint32(KLTColNumLexiconID)==aLexiconID)
1.218 + {
1.219 + found = true;
1.220 + break;
1.221 + }
1.222 + }
1.223 + return found;
1.224 + }
1.225 +
1.226 +
1.227 +
1.228 +void CSDDatabase::RSDLexiconTable::RemoveLexiconL(TLexiconID aLexiconID)
1.229 + {
1.230 + if (FindLexiconL(aLexiconID))
1.231 + {
1.232 + if (iView.ColUint32(KLTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
1.233 + {
1.234 + iDatabase.StartTransactionL();
1.235 + iView.DeleteL();
1.236 + }
1.237 + else
1.238 + User::Leave(KErrNotFound);//change to not owned
1.239 + }
1.240 + else
1.241 + User::Leave(KErrNotFound);
1.242 + }
1.243 +
1.244 +void CSDDatabase::RSDLexiconTable::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs)
1.245 + {
1.246 + aLexiconIDs.Reset();
1.247 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.248 + {
1.249 + iView.GetL();
1.250 + TLexiconID lexiconID = iView.ColUint32(KLTColNumLexiconID);
1.251 + User::LeaveIfError(aLexiconIDs.Append(lexiconID));
1.252 + }
1.253 + }
1.254 +
1.255 +CSDDatabase::RSDModelBankTable::RSDModelBankTable(CSDDatabase& aDatabase)
1.256 + : iDatabase(aDatabase)
1.257 + {
1.258 +
1.259 +
1.260 + }
1.261 +
1.262 +void CSDDatabase::RSDModelBankTable::OpenL(TBool aOwnedByClient)
1.263 + {
1.264 + TBuf<256> query;
1.265 + if (aOwnedByClient)
1.266 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
1.267 + else
1.268 + query.Format(KSQLSelectFromTable,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
1.269 +
1.270 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.271 + User::LeaveIfError(iView.EvaluateAll());
1.272 +
1.273 + }
1.274 +
1.275 +void CSDDatabase::RSDModelBankTable::Close()
1.276 + {
1.277 + iView.Close();
1.278 + }
1.279 +
1.280 +TModelBankID CSDDatabase::RSDModelBankTable::CreateModelBankL()
1.281 + {
1.282 + iDatabase.StartTransactionL();
1.283 + TModelBankID modelBankID;
1.284 + modelBankID = iDatabase.AllocNewIDL();
1.285 + iView.InsertL();
1.286 +
1.287 + iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
1.288 + iView.SetColL(KMBTColNumModelBankID,modelBankID);
1.289 + iView.PutL();
1.290 + return modelBankID;
1.291 + }
1.292 +
1.293 +void CSDDatabase::RSDModelBankTable::AddModelBankL(TModelBankID aModelBankID)
1.294 + {
1.295 + iDatabase.StartTransactionL();
1.296 + iDatabase.UpdateLastIDL(aModelBankID);
1.297 + iView.InsertL();
1.298 + iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
1.299 + iView.SetColL(KMBTColNumModelBankID,aModelBankID);
1.300 + iView.PutL();
1.301 + }
1.302 +
1.303 +
1.304 +TBool CSDDatabase::RSDModelBankTable::FindModelBankL(TModelBankID aModelBankID)
1.305 + {
1.306 + TBool found = EFalse;
1.307 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.308 + {
1.309 + iView.GetL();
1.310 + if (iView.ColUint32(KMBTColNumModelBankID)==aModelBankID)
1.311 + {
1.312 + found = true;
1.313 + break;
1.314 + }
1.315 + }
1.316 + return found;
1.317 + }
1.318 +
1.319 +
1.320 +
1.321 +void CSDDatabase::RSDModelBankTable::RemoveModelBankL(TModelBankID aModelBankID)
1.322 + {
1.323 + if (FindModelBankL(aModelBankID))
1.324 + {
1.325 + if (iView.ColUint32(KMBTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)
1.326 + {
1.327 + iDatabase.StartTransactionL();
1.328 + iView.DeleteL();
1.329 + }
1.330 + else
1.331 + User::Leave(KErrNotFound);//change to not owned
1.332 + }
1.333 + else
1.334 + User::Leave(KErrNotFound);
1.335 + }
1.336 +
1.337 +void CSDDatabase::RSDModelBankTable::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs)
1.338 + {
1.339 + aModelBankIDs.Reset();
1.340 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.341 + {
1.342 + iView.GetL();
1.343 + TModelBankID modelBankID = iView.ColUint32(KMBTColNumModelBankID);
1.344 + User::LeaveIfError(aModelBankIDs.Append(modelBankID));
1.345 + }
1.346 + }
1.347 +
1.348 +
1.349 +CSDDatabase::RSDModelTable::RSDModelTable(CSDDatabase& aDatabase)
1.350 + : iDatabase(aDatabase)
1.351 + {
1.352 +
1.353 +
1.354 + }
1.355 +
1.356 +void CSDDatabase::RSDModelTable::OpenL(TModelBankID aModelBankID)
1.357 + {
1.358 + if (!iDatabase.ModelBankExistsL(aModelBankID))
1.359 + User::Leave(KErrNotFound);
1.360 +
1.361 + iModelBankID = aModelBankID;
1.362 + TBuf<256> query;
1.363 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModel,&KColModelBankID,aModelBankID);
1.364 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.365 + User::LeaveIfError(iView.EvaluateAll());
1.366 +
1.367 + }
1.368 +
1.369 +void CSDDatabase::RSDModelTable::Close()
1.370 + {
1.371 + iView.Close();
1.372 + }
1.373 +
1.374 +TModelID CSDDatabase::RSDModelTable::CreateModelL(TModelData aModelData)
1.375 + {
1.376 + iDatabase.StartTransactionL();
1.377 + TModelID modelID = iDatabase.AllocNewIDL();
1.378 + iView.InsertL();
1.379 + iView.SetColL(KMTColNumModelBankID,iModelBankID);
1.380 + iView.SetColL(KMTColNumModelID,modelID);
1.381 + iView.SetColL(KMTColNumUtteranceDurationMicroSeconds,aModelData.iUtteranceDurationMicroSeconds);
1.382 + iView.PutL();
1.383 + return modelID;
1.384 + }
1.385 +
1.386 +void CSDDatabase::RSDModelTable::AddModelL(TModelData aModelData)
1.387 + {
1.388 + iDatabase.StartTransactionL();
1.389 + iDatabase.UpdateLastIDL(aModelData.iModelID);
1.390 + iView.InsertL();
1.391 + iView.SetColL(KMTColNumModelBankID,iModelBankID);
1.392 + iView.SetColL(KMTColNumModelID,aModelData.iModelID);
1.393 + iView.SetColL(KMTColNumUtteranceDurationMicroSeconds, aModelData.iUtteranceDurationMicroSeconds);
1.394 + iView.PutL();
1.395 + }
1.396 +
1.397 +void CSDDatabase::RSDModelTable::GetModelDataL(TModelID aModelID, TModelData& aModelData)
1.398 + {
1.399 + if (!FindModelL(aModelID))
1.400 + User::Leave(KErrNotFound);
1.401 +
1.402 + iView.GetL();
1.403 + aModelData.iModelID = iView.ColUint32(KMTColNumModelID);
1.404 + aModelData.iUtteranceDurationMicroSeconds = iView.ColUint32(KMTColNumUtteranceDurationMicroSeconds);
1.405 + }
1.406 +
1.407 +
1.408 +
1.409 +TBool CSDDatabase::RSDModelTable::FindModelL(TModelID aModelID)
1.410 + {
1.411 + TBool found = EFalse;
1.412 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.413 + {
1.414 + iView.GetL();
1.415 + if (iView.ColUint32(KMTColNumModelID)==aModelID)
1.416 + {
1.417 + found = true;
1.418 + break;
1.419 + }
1.420 + }
1.421 + return found;
1.422 + }
1.423 +
1.424 +
1.425 +
1.426 +void CSDDatabase::RSDModelTable::RemoveModelL(TModelID aModelID)
1.427 + {
1.428 + if (FindModelL(aModelID))
1.429 + {
1.430 + iDatabase.StartTransactionL();
1.431 + iView.DeleteL();
1.432 + }
1.433 + else
1.434 + User::Leave(KErrNotFound);
1.435 + }
1.436 +
1.437 +void CSDDatabase::RSDModelTable::GetAllModelIDsL(RArray<TModelID>& aModelIDs)
1.438 + {
1.439 + aModelIDs.Reset();
1.440 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.441 + {
1.442 + iView.GetL();
1.443 + TModelID modelID = iView.ColUint32(KMTColNumModelID);
1.444 + User::LeaveIfError(aModelIDs.Append(modelID));
1.445 + }
1.446 + }
1.447 +
1.448 +//------------------------------------------------------------------------------------------------
1.449 +CSDDatabase::RSDSettingsTable::RSDSettingsTable(CSDDatabase& aDatabase)
1.450 + : iDatabase(aDatabase)
1.451 + {
1.452 +
1.453 +
1.454 + }
1.455 +
1.456 +void CSDDatabase::RSDSettingsTable::OpenL()
1.457 + {
1.458 + TBuf<256> query;
1.459 + query.Format(KSQLSelectFromTable,&KAllCols,&KTableSettings);
1.460 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.461 + User::LeaveIfError(iView.EvaluateAll());
1.462 + }
1.463 +
1.464 +void CSDDatabase::RSDSettingsTable::Close()
1.465 + {
1.466 + iView.Close();
1.467 + }
1.468 +
1.469 +TUint32 CSDDatabase::RSDSettingsTable::GetValueL(TUint32 aSettingID)
1.470 + {
1.471 + TUint32 value = 0;
1.472 + TBool found = EFalse;
1.473 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.474 + {
1.475 + iView.GetL();
1.476 + if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
1.477 + {
1.478 + value = iView.ColUint32(KSTColNumSettingsValue);
1.479 + found = ETrue;
1.480 + break;
1.481 + }
1.482 +
1.483 + }
1.484 + if (!found)
1.485 + User::Leave(KErrNotFound);
1.486 +
1.487 + return value;
1.488 + }
1.489 +
1.490 +void CSDDatabase::RSDSettingsTable::SetValueL(TUint32 aSettingID, TUint32 aValue)
1.491 + {
1.492 + TBool found = EFalse;
1.493 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.494 + {
1.495 + iView.GetL();
1.496 + if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
1.497 + {
1.498 + iView.UpdateL();
1.499 + iView.SetColL(KSTColNumSettingsValue, aValue);
1.500 + iView.PutL();
1.501 + found = ETrue;
1.502 + break;
1.503 + }
1.504 +
1.505 + }
1.506 + // if it wasn't found, add it
1.507 + if (!found)
1.508 + {
1.509 + iView.InsertL();
1.510 + iView.SetColL(KSTColNumSettingsID, aSettingID);
1.511 + iView.SetColL(KSTColNumSettingsValue, aValue);
1.512 + iView.PutL();
1.513 + }
1.514 + }
1.515 +
1.516 +
1.517 +//------------------------------------------------------------------------------------------------
1.518 +
1.519 +CSDDatabase::RSDPronunciationTable::RSDPronunciationTable(CSDDatabase& aDatabase)
1.520 + : iDatabase(aDatabase)
1.521 + {
1.522 +
1.523 +
1.524 + }
1.525 +
1.526 +void CSDDatabase::RSDPronunciationTable::OpenL(TLexiconID aLexiconID)
1.527 + {
1.528 + if (!iDatabase.LexiconExistsL(aLexiconID))
1.529 + User::Leave(KErrNotFound);
1.530 +
1.531 + iLexiconID = aLexiconID;
1.532 + TBuf<256> query;
1.533 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTablePronunciation,&KColLexiconID,aLexiconID);
1.534 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.535 + User::LeaveIfError(iView.EvaluateAll());
1.536 +
1.537 + }
1.538 +
1.539 +void CSDDatabase::RSDPronunciationTable::Close()
1.540 + {
1.541 + iView.Close();
1.542 + }
1.543 +
1.544 +TPronunciationID CSDDatabase::RSDPronunciationTable::CreatePronunciationL(TPronunciationData aPronunciationData)
1.545 + {
1.546 + TPronunciationID pronunciationID;
1.547 + iDatabase.StartTransactionL();
1.548 + pronunciationID = iDatabase.AllocNewIDL();
1.549 + iView.InsertL();
1.550 + iView.SetColL(KPTColNumLexiconID,iLexiconID);
1.551 + iView.SetColL(KPTColNumPronunciationID,pronunciationID);
1.552 + iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
1.553 + iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
1.554 + iView.PutL();
1.555 + return pronunciationID;
1.556 + }
1.557 +
1.558 +void CSDDatabase::RSDPronunciationTable::AddPronunciationL(TPronunciationData aPronunciationData)
1.559 + {
1.560 + iDatabase.StartTransactionL();
1.561 + iDatabase.UpdateLastIDL(aPronunciationData.iPronunciationID);
1.562 + iView.InsertL();
1.563 + iView.SetColL(KPTColNumLexiconID,iLexiconID);
1.564 + iView.SetColL(KPTColNumPronunciationID,aPronunciationData.iPronunciationID);
1.565 + iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
1.566 + iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
1.567 + iView.PutL();
1.568 + }
1.569 +
1.570 +void CSDDatabase::RSDPronunciationTable::GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
1.571 + {
1.572 + if (!FindPronunciationL(aPronunciationID))
1.573 + User::Leave(KErrNotFound);
1.574 +
1.575 + iView.GetL();
1.576 + aPronunciationData.iPronunciationID = iView.ColUint32(KPTColNumPronunciationID);
1.577 + aPronunciationData.iModelBankID = iView.ColUint32(KPTColNumModelBankID);
1.578 + aPronunciationData.iModelID = iView.ColUint32(KPTColNumModelID);
1.579 + }
1.580 +
1.581 +
1.582 +
1.583 +TBool CSDDatabase::RSDPronunciationTable::FindPronunciationL(TPronunciationID aPronunciationID)
1.584 + {
1.585 + TBool found = EFalse;
1.586 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.587 + {
1.588 + iView.GetL();
1.589 + if (iView.ColUint32(KPTColNumPronunciationID)==aPronunciationID)
1.590 + {
1.591 + found = true;
1.592 + break;
1.593 + }
1.594 + }
1.595 + return found;
1.596 + }
1.597 +
1.598 +
1.599 +
1.600 +void CSDDatabase::RSDPronunciationTable::RemovePronunciationL(TPronunciationID aPronunciationID)
1.601 + {
1.602 + if (FindPronunciationL(aPronunciationID))
1.603 + {
1.604 + iDatabase.StartTransactionL();
1.605 + iView.DeleteL();
1.606 + }
1.607 + else
1.608 + User::Leave(KErrNotFound);
1.609 + }
1.610 +
1.611 +void CSDDatabase::RSDPronunciationTable::GetAllPronunciationIDsL(RArray<TPronunciationID>& aPronunciationIDs)
1.612 + {
1.613 + aPronunciationIDs.Reset();
1.614 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.615 + {
1.616 + iView.GetL();
1.617 + TPronunciationID modelID = iView.ColUint32(KPTColNumPronunciationID);
1.618 + User::LeaveIfError(aPronunciationIDs.Append(modelID));
1.619 + }
1.620 + }
1.621 +//--------------------------------------------------------------------------------------------------
1.622 +
1.623 +CSDDatabase::RSDRuleTable::RSDRuleTable(CSDDatabase& aDatabase)
1.624 + : iDatabase(aDatabase)
1.625 + {
1.626 +
1.627 +
1.628 + }
1.629 +
1.630 +void CSDDatabase::RSDRuleTable::OpenL(TGrammarID aGrammarID)
1.631 + {
1.632 + if (!iDatabase.GrammarExistsL(aGrammarID))
1.633 + User::Leave(KErrNotFound);
1.634 +
1.635 + iGrammarID = aGrammarID;
1.636 + TBuf<256> query;
1.637 + query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableRule,&KColGrammarID,aGrammarID);
1.638 + User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
1.639 + User::LeaveIfError(iView.EvaluateAll());
1.640 +
1.641 + }
1.642 +
1.643 +void CSDDatabase::RSDRuleTable::Close()
1.644 + {
1.645 + iView.Close();
1.646 + }
1.647 +
1.648 +TRuleID CSDDatabase::RSDRuleTable::CreateRuleL(TRuleData aRuleData)
1.649 + {
1.650 + iDatabase.StartTransactionL();
1.651 + TRuleID ruleID = iDatabase.AllocNewIDL();
1.652 + iView.InsertL();
1.653 + iView.SetColL(KRTColNumGrammarID,iGrammarID);
1.654 + iView.SetColL(KRTColNumRuleID,ruleID);
1.655 + iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
1.656 + iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
1.657 + iView.PutL();
1.658 + return ruleID;
1.659 + }
1.660 +
1.661 +void CSDDatabase::RSDRuleTable::AddRuleL(TRuleData aRuleData)
1.662 + {
1.663 + iDatabase.StartTransactionL();
1.664 + iDatabase.UpdateLastIDL(aRuleData.iRuleID);
1.665 +
1.666 + iView.InsertL();
1.667 + iView.SetColL(KRTColNumGrammarID,iGrammarID);
1.668 + iView.SetColL(KRTColNumRuleID,aRuleData.iRuleID);
1.669 + iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
1.670 + iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
1.671 + iView.PutL();
1.672 + }
1.673 +
1.674 +
1.675 +TBool CSDDatabase::RSDRuleTable::FindRuleL(TRuleID aRuleID)
1.676 + {
1.677 + TBool found = EFalse;
1.678 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.679 + {
1.680 + iView.GetL();
1.681 + if (iView.ColUint32(KRTColNumRuleID)==aRuleID)
1.682 + {
1.683 + found = true;
1.684 + break;
1.685 + }
1.686 + }
1.687 + return found;
1.688 + }
1.689 +
1.690 +TBool CSDDatabase::RSDRuleTable::IsRuleValidL(TRuleID aRuleID)
1.691 + {
1.692 + TBool valid = EFalse;
1.693 + TBool found = FindRuleL(aRuleID);
1.694 + if (found)
1.695 + {
1.696 + TLexiconID lexiconID = iView.ColUint32(KRTColNumLexiconID);
1.697 + TPronunciationID pronunciationID = iView.ColUint32(KRTColNumPronunciationID);
1.698 + if (iDatabase.LexiconExistsL(lexiconID) &&
1.699 + iDatabase.PronunciationExistsL(lexiconID, pronunciationID))
1.700 + {
1.701 + valid = ETrue;
1.702 + }
1.703 + }
1.704 + else
1.705 + User::Leave(KErrNotFound);
1.706 + return valid;
1.707 + }
1.708 +
1.709 +
1.710 +void CSDDatabase::RSDRuleTable::RemoveRuleL(TRuleID aRuleID)
1.711 + {
1.712 + if (FindRuleL(aRuleID))
1.713 + {
1.714 + iDatabase.StartTransactionL();
1.715 + iView.DeleteL();
1.716 + }
1.717 + else
1.718 + User::Leave(KErrNotFound);
1.719 + }
1.720 +
1.721 +void CSDDatabase::RSDRuleTable::GetAllRuleIDsL(RArray<TRuleID>& aRuleIDs)
1.722 + {
1.723 + aRuleIDs.Reset();
1.724 + for (iView.FirstL();iView.AtRow();iView.NextL())
1.725 + {
1.726 + iView.GetL();
1.727 + TRuleID modelID = iView.ColUint32(KRTColNumRuleID);
1.728 + User::LeaveIfError(aRuleIDs.Append(modelID));
1.729 + }
1.730 + }
1.731 +//--------------------------------------------------------------------------------------------------
1.732 +
1.733 +
1.734 +CSDDatabase* CSDDatabase::NewL(const TDesC& aFileName, TBool aUseExisting)
1.735 + {
1.736 + CSDDatabase* self = new (ELeave) CSDDatabase;
1.737 + CleanupStack::PushL(self);
1.738 + self->ConstructL(aFileName, aUseExisting);
1.739 + CleanupStack::Pop();
1.740 + return self;
1.741 + }
1.742 +
1.743 +
1.744 +void CSDDatabase::SetClientUid(TUid aClientUid)
1.745 + {
1.746 + iClientUid = aClientUid;
1.747 + }
1.748 +
1.749 +void CSDDatabase::ConstructL(const TDesC& aFileName, TBool aUseExisting)
1.750 + {
1.751 + if (aUseExisting)
1.752 + OpenDatabaseL(aFileName);
1.753 + else
1.754 + CreateDatabaseL(aFileName);
1.755 + }
1.756 +
1.757 +void CSDDatabase::OpenDatabaseL(const TDesC& aFileName)
1.758 + {
1.759 + RFs fsSession;
1.760 + User::LeaveIfError(fsSession.Connect());
1.761 + iDbStore = CFileStore::OpenL(fsSession,aFileName,EFileRead|EFileWrite);
1.762 + // open the database from the root stream
1.763 + iDatabase.OpenL(iDbStore,iDbStore->Root());
1.764 + iDatabaseOpened = ETrue;
1.765 + }
1.766 +
1.767 +
1.768 +void CSDDatabase::CreateDatabaseL(const TDesC& aFileName)
1.769 + {
1.770 + RFs fsSession;
1.771 + User::LeaveIfError(fsSession.Connect());
1.772 + iDbStore = CPermanentFileStore::ReplaceL(fsSession,aFileName,EFileRead|EFileWrite);
1.773 + // Complete file store creation
1.774 + iDbStore->SetTypeL(iDbStore->Layout());
1.775 +
1.776 + // Create a database in the store
1.777 + TStreamId id=iDatabase.CreateL(iDbStore);
1.778 + iDbStore->SetRootL(id);
1.779 +
1.780 + // Complete database creation by commiting the store
1.781 + iDbStore->CommitL();
1.782 +
1.783 + // create the CDs table
1.784 + DoCreateTablesL();
1.785 +
1.786 + // create an index
1.787 + DoCreateIndexesL();
1.788 +
1.789 + // add the inital settings
1.790 + RSDSettingsTable settingsTable(*this);
1.791 + settingsTable.OpenL();
1.792 + CleanupClosePushL(settingsTable);
1.793 + settingsTable.SetValueL(KSettingLastID, 0);
1.794 + CleanupStack::PopAndDestroy(&settingsTable);
1.795 + }
1.796 +
1.797 +CSDDatabase::CSDDatabase()
1.798 + {
1.799 +
1.800 + }
1.801 +
1.802 +CSDDatabase::~CSDDatabase()
1.803 + {
1.804 + if (iDatabaseOpened)
1.805 + {
1.806 + if (iDatabase.InTransaction())
1.807 + {
1.808 + iDatabase.Rollback();
1.809 + if (iDatabase.IsDamaged())
1.810 + iDatabase.Recover();
1.811 + }
1.812 + }
1.813 + iDatabase.Close();
1.814 + delete iDbStore;
1.815 + }
1.816 +
1.817 +
1.818 +void CSDDatabase::DoCreateTablesL()
1.819 + {
1.820 + CDbColSet* columns;
1.821 +
1.822 + // create Grammar Table
1.823 + columns=CDbColSet::NewLC();
1.824 + columns->AddL(TDbCol(KColClientUID,EDbColUint32));
1.825 + columns->AddL(TDbCol(KColGrammarID,EDbColUint32));
1.826 + User::LeaveIfError(iDatabase.CreateTable(KTableGrammar,*columns));
1.827 + CleanupStack::PopAndDestroy(columns);
1.828 +
1.829 + // create Lexicon Table
1.830 + columns=CDbColSet::NewLC();
1.831 + columns->AddL(TDbCol(KColClientUID,EDbColUint32));
1.832 + columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
1.833 + User::LeaveIfError(iDatabase.CreateTable(KTableLexicon,*columns));
1.834 + CleanupStack::PopAndDestroy(columns);
1.835 +
1.836 + // create ModelBank Table
1.837 + columns=CDbColSet::NewLC();
1.838 + columns->AddL(TDbCol(KColClientUID,EDbColUint32));
1.839 + columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
1.840 + User::LeaveIfError(iDatabase.CreateTable(KTableModelBank,*columns));
1.841 + CleanupStack::PopAndDestroy(columns);
1.842 +
1.843 + // create Rule Table
1.844 + columns=CDbColSet::NewLC();
1.845 + columns->AddL(TDbCol(KColGrammarID,EDbColUint32));
1.846 + columns->AddL(TDbCol(KColRuleID,EDbColUint32));
1.847 + columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
1.848 + columns->AddL(TDbCol(KColPronunciationID,EDbColUint32));
1.849 +
1.850 + User::LeaveIfError(iDatabase.CreateTable(KTableRule,*columns));
1.851 + CleanupStack::PopAndDestroy(columns);
1.852 +
1.853 + // create Pronunciation Table
1.854 + columns=CDbColSet::NewLC();
1.855 + columns->AddL(TDbCol(KColLexiconID,EDbColUint32));
1.856 + columns->AddL(TDbCol(KColPronunciationID,EDbColUint32));
1.857 + columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
1.858 + columns->AddL(TDbCol(KColModelID,EDbColUint32));
1.859 + User::LeaveIfError(iDatabase.CreateTable(KTablePronunciation,*columns));
1.860 + CleanupStack::PopAndDestroy(columns);
1.861 +
1.862 + // create Model Table
1.863 + columns=CDbColSet::NewLC();
1.864 + columns->AddL(TDbCol(KColModelBankID,EDbColUint32));
1.865 + columns->AddL(TDbCol(KColModelID,EDbColUint32));
1.866 + columns->AddL(TDbCol(KColUtteranceDuration,EDbColUint32));
1.867 + User::LeaveIfError(iDatabase.CreateTable(KTableModel,*columns));
1.868 + CleanupStack::PopAndDestroy(columns);
1.869 +
1.870 + // create Settings Table
1.871 + columns=CDbColSet::NewLC();
1.872 + columns->AddL(TDbCol(KColSettingsID,EDbColUint32));
1.873 + columns->AddL(TDbCol(KColSettingsValue,EDbColUint32));
1.874 + User::LeaveIfError(iDatabase.CreateTable(KTableSettings,*columns));
1.875 + CleanupStack::PopAndDestroy(columns);
1.876 + }
1.877 +
1.878 +
1.879 +void CSDDatabase::DoCreateIndexesL()
1.880 + {
1.881 +
1.882 +
1.883 + }
1.884 +
1.885 +TGrammarID CSDDatabase::CreateGrammarL()
1.886 + {
1.887 + TGrammarID grammarID;
1.888 + RSDGrammarTable grammarTable(*this);
1.889 + CleanupClosePushL(grammarTable);
1.890 + grammarTable.OpenL();
1.891 + grammarTable.CreateGrammarL(grammarID);
1.892 + CleanupStack::PopAndDestroy(&grammarTable);
1.893 + return grammarID;
1.894 + }
1.895 +void CSDDatabase::AddGrammarL(TGrammarID aGrammarID)
1.896 + {
1.897 + RSDGrammarTable grammarTable(*this);
1.898 + CleanupClosePushL(grammarTable);
1.899 + grammarTable.OpenL();
1.900 + grammarTable.AddGrammarL(aGrammarID);
1.901 + CleanupStack::PopAndDestroy(&grammarTable);
1.902 + }
1.903 +
1.904 +void CSDDatabase::RemoveGrammarL(TGrammarID aGrammarID)
1.905 + {
1.906 + RSDGrammarTable grammarTable(*this);
1.907 + CleanupClosePushL(grammarTable);
1.908 + grammarTable.OpenL();
1.909 + grammarTable.RemoveGrammarL(aGrammarID);
1.910 + CleanupStack::PopAndDestroy(&grammarTable);
1.911 + }
1.912 +
1.913 +void CSDDatabase::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs, TBool aOwnedByClient)
1.914 + {
1.915 + RSDGrammarTable grammarTable(*this);
1.916 + CleanupClosePushL(grammarTable);
1.917 + grammarTable.OpenL(aOwnedByClient);
1.918 + grammarTable.GetAllGrammarIDsL(aGrammarIDs);
1.919 + CleanupStack::PopAndDestroy(&grammarTable);
1.920 + }
1.921 +TBool CSDDatabase::GrammarExistsL(TGrammarID aGrammarID)
1.922 + {
1.923 + RSDGrammarTable grammarTable(*this);
1.924 + CleanupClosePushL(grammarTable);
1.925 + grammarTable.OpenL();
1.926 + TBool found = grammarTable.FindGrammarL(aGrammarID);
1.927 + CleanupStack::PopAndDestroy(&grammarTable);
1.928 + return found;
1.929 + }
1.930 +
1.931 +TLexiconID CSDDatabase::CreateLexiconL()
1.932 + {
1.933 + TLexiconID lexiconID;
1.934 + RSDLexiconTable lexiconTable(*this);
1.935 + CleanupClosePushL(lexiconTable);
1.936 + lexiconTable.OpenL();
1.937 + lexiconTable.CreateLexiconL(lexiconID);
1.938 + CleanupStack::PopAndDestroy(&lexiconTable);
1.939 + return lexiconID;
1.940 + }
1.941 +void CSDDatabase::AddLexiconL(TLexiconID aLexiconID)
1.942 + {
1.943 + RSDLexiconTable lexiconTable(*this);
1.944 + CleanupClosePushL(lexiconTable);
1.945 + lexiconTable.OpenL();
1.946 + lexiconTable.AddLexiconL(aLexiconID);
1.947 + CleanupStack::PopAndDestroy(&lexiconTable);
1.948 + }
1.949 +
1.950 +void CSDDatabase::RemoveLexiconL(TLexiconID aLexiconID)
1.951 + {
1.952 + RSDLexiconTable lexiconTable(*this);
1.953 + CleanupClosePushL(lexiconTable);
1.954 + lexiconTable.OpenL();
1.955 + lexiconTable.RemoveLexiconL(aLexiconID);
1.956 + CleanupStack::PopAndDestroy(&lexiconTable);
1.957 + }
1.958 +
1.959 +void CSDDatabase::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs, TBool aOwnedByClient)
1.960 + {
1.961 + RSDLexiconTable lexiconTable(*this);
1.962 + CleanupClosePushL(lexiconTable);
1.963 + lexiconTable.OpenL(aOwnedByClient);
1.964 + lexiconTable.GetAllLexiconIDsL(aLexiconIDs);
1.965 + CleanupStack::PopAndDestroy(&lexiconTable);
1.966 + }
1.967 +TBool CSDDatabase::LexiconExistsL(TLexiconID aLexiconID)
1.968 + {
1.969 + RSDLexiconTable lexiconTable(*this);
1.970 + CleanupClosePushL(lexiconTable);
1.971 + lexiconTable.OpenL();
1.972 + TBool found = lexiconTable.FindLexiconL(aLexiconID);
1.973 + CleanupStack::PopAndDestroy(&lexiconTable);
1.974 + return found;
1.975 + }
1.976 +
1.977 +TModelBankID CSDDatabase::CreateModelBankL()
1.978 + {
1.979 + TModelBankID modelBankID;
1.980 + RSDModelBankTable modelBankTable(*this);
1.981 + CleanupClosePushL(modelBankTable);
1.982 + modelBankTable.OpenL();
1.983 + modelBankID = modelBankTable.CreateModelBankL();
1.984 + CleanupStack::PopAndDestroy(&modelBankTable);
1.985 + return modelBankID;
1.986 + }
1.987 +void CSDDatabase::AddModelBankL(TModelBankID aModelBankID)
1.988 + {
1.989 + RSDModelBankTable modelBankTable(*this);
1.990 + CleanupClosePushL(modelBankTable);
1.991 + modelBankTable.OpenL();
1.992 + modelBankTable.AddModelBankL(aModelBankID);
1.993 + CleanupStack::PopAndDestroy(&modelBankTable);
1.994 + }
1.995 +
1.996 +void CSDDatabase::RemoveModelBankL(TModelBankID aModelBankID)
1.997 + {
1.998 + RSDModelBankTable modelBankTable(*this);
1.999 + CleanupClosePushL(modelBankTable);
1.1000 + modelBankTable.OpenL();
1.1001 + modelBankTable.RemoveModelBankL(aModelBankID);
1.1002 + CleanupStack::PopAndDestroy(&modelBankTable);
1.1003 + }
1.1004 +
1.1005 +void CSDDatabase::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs, TBool aOwnedByClient)
1.1006 + {
1.1007 + RSDModelBankTable modelBankTable(*this);
1.1008 + CleanupClosePushL(modelBankTable);
1.1009 + modelBankTable.OpenL(aOwnedByClient);
1.1010 + modelBankTable.GetAllModelBankIDsL(aModelBankIDs);
1.1011 + CleanupStack::PopAndDestroy(&modelBankTable);
1.1012 + }
1.1013 +TBool CSDDatabase::ModelBankExistsL(TModelBankID aModelBankID)
1.1014 + {
1.1015 + RSDModelBankTable modelBankTable(*this);
1.1016 + CleanupClosePushL(modelBankTable);
1.1017 + modelBankTable.OpenL();
1.1018 + TBool found = modelBankTable.FindModelBankL(aModelBankID);
1.1019 + CleanupStack::PopAndDestroy(&modelBankTable);
1.1020 + return found;
1.1021 + }
1.1022 +
1.1023 +
1.1024 +//------------------------------------------------------------------------------------------
1.1025 +TModelID CSDDatabase::CreateModelL(TModelBankID aModelBankID, TModelData aModelData)
1.1026 + {
1.1027 +// TModelID modelID;
1.1028 + RSDModelTable modelTable(*this);
1.1029 + CleanupClosePushL(modelTable);
1.1030 + modelTable.OpenL(aModelBankID);
1.1031 +// modelID = modelTable.CreateModelL(aModelData);
1.1032 + modelTable.CreateModelL(aModelData); // EABI warning removal
1.1033 + CleanupStack::PopAndDestroy(&modelTable);
1.1034 + return aModelData.iModelID;
1.1035 + }
1.1036 +void CSDDatabase::AddModelL(TModelBankID aModelBankID, TModelData aModelData)
1.1037 + {
1.1038 + RSDModelTable modelTable(*this);
1.1039 + CleanupClosePushL(modelTable);
1.1040 + modelTable.OpenL(aModelBankID);
1.1041 + modelTable.AddModelL(aModelData);
1.1042 + CleanupStack::PopAndDestroy(&modelTable);
1.1043 + }
1.1044 +
1.1045 +void CSDDatabase::RemoveModelL(TModelBankID aModelBankID, TModelID aModelID)
1.1046 + {
1.1047 + RSDModelTable modelTable(*this);
1.1048 + CleanupClosePushL(modelTable);
1.1049 + modelTable.OpenL(aModelBankID);
1.1050 + modelTable.RemoveModelL(aModelID);
1.1051 + CleanupStack::PopAndDestroy(&modelTable);
1.1052 + }
1.1053 +
1.1054 +void CSDDatabase::GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData)
1.1055 + {
1.1056 + RSDModelTable modelTable(*this);
1.1057 + CleanupClosePushL(modelTable);
1.1058 + modelTable.OpenL(aModelBankID);
1.1059 + modelTable.GetModelDataL(aModelID, aModelData);
1.1060 + CleanupStack::PopAndDestroy(&modelTable);
1.1061 + }
1.1062 +
1.1063 +
1.1064 +void CSDDatabase::GetAllModelIDsL(TModelBankID aModelBankID, RArray<TModelID>& aModelIDs)
1.1065 + {
1.1066 + RSDModelTable modelTable(*this);
1.1067 + CleanupClosePushL(modelTable);
1.1068 + modelTable.OpenL(aModelBankID);
1.1069 + modelTable.GetAllModelIDsL(aModelIDs);
1.1070 + CleanupStack::PopAndDestroy(&modelTable);
1.1071 + }
1.1072 +TBool CSDDatabase::ModelExistsL(TModelBankID aModelBankID, TModelID aModelID)
1.1073 + {
1.1074 + RSDModelTable modelTable(*this);
1.1075 + CleanupClosePushL(modelTable);
1.1076 + modelTable.OpenL(aModelBankID);
1.1077 + TBool found = modelTable.FindModelL(aModelID);
1.1078 + CleanupStack::PopAndDestroy(&modelTable);
1.1079 + return found;
1.1080 + }
1.1081 +//------------------------------------------------------------------------------------------
1.1082 +TPronunciationID CSDDatabase::CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
1.1083 + {
1.1084 + TPronunciationID pronunciationID;
1.1085 + RSDPronunciationTable pronunciationTable(*this);
1.1086 + CleanupClosePushL(pronunciationTable);
1.1087 + pronunciationTable.OpenL(aLexiconID);
1.1088 + pronunciationID = pronunciationTable.CreatePronunciationL(aPronunciationData);
1.1089 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1090 + return pronunciationID;
1.1091 + }
1.1092 +void CSDDatabase::AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
1.1093 + {
1.1094 + RSDPronunciationTable pronunciationTable(*this);
1.1095 + CleanupClosePushL(pronunciationTable);
1.1096 + pronunciationTable.OpenL(aLexiconID);
1.1097 + pronunciationTable.AddPronunciationL(aPronunciationData);
1.1098 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1099 + }
1.1100 +
1.1101 +void CSDDatabase::RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
1.1102 + {
1.1103 + RSDPronunciationTable pronunciationTable(*this);
1.1104 + CleanupClosePushL(pronunciationTable);
1.1105 + pronunciationTable.OpenL(aLexiconID);
1.1106 + pronunciationTable.RemovePronunciationL(aPronunciationID);
1.1107 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1108 + }
1.1109 +
1.1110 +void CSDDatabase::GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
1.1111 + {
1.1112 + RSDPronunciationTable pronunciationTable(*this);
1.1113 + CleanupClosePushL(pronunciationTable);
1.1114 + pronunciationTable.OpenL(aLexiconID);
1.1115 + pronunciationTable.GetPronunciationDataL(aPronunciationID, aPronunciationData);
1.1116 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1117 + }
1.1118 +
1.1119 +void CSDDatabase::GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs)
1.1120 + {
1.1121 + RSDPronunciationTable pronunciationTable(*this);
1.1122 + CleanupClosePushL(pronunciationTable);
1.1123 + pronunciationTable.OpenL(aLexiconID);
1.1124 + pronunciationTable.GetAllPronunciationIDsL(aPronunciationIDs);
1.1125 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1126 + }
1.1127 +TBool CSDDatabase::PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
1.1128 + {
1.1129 + RSDPronunciationTable pronunciationTable(*this);
1.1130 + CleanupClosePushL(pronunciationTable);
1.1131 + pronunciationTable.OpenL(aLexiconID);
1.1132 + TBool found = pronunciationTable.FindPronunciationL(aPronunciationID);
1.1133 + CleanupStack::PopAndDestroy(&pronunciationTable);
1.1134 + return found;
1.1135 + }
1.1136 +
1.1137 +//------------------------------------------------------------------------------------------
1.1138 +TRuleID CSDDatabase::CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
1.1139 + {
1.1140 + TRuleID ruleID;
1.1141 + RSDRuleTable ruleTable(*this);
1.1142 + CleanupClosePushL(ruleTable);
1.1143 + ruleTable.OpenL(aGrammarID);
1.1144 + ruleID = ruleTable.CreateRuleL(aRuleData);
1.1145 + CleanupStack::PopAndDestroy(&ruleTable);
1.1146 + return ruleID;
1.1147 + }
1.1148 +void CSDDatabase::AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
1.1149 + {
1.1150 + RSDRuleTable ruleTable(*this);
1.1151 + CleanupClosePushL(ruleTable);
1.1152 + ruleTable.OpenL(aGrammarID);
1.1153 + ruleTable.AddRuleL(aRuleData);
1.1154 + CleanupStack::PopAndDestroy(&ruleTable);
1.1155 + }
1.1156 +
1.1157 +void CSDDatabase::RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID)
1.1158 + {
1.1159 + RSDRuleTable ruleTable(*this);
1.1160 + CleanupClosePushL(ruleTable);
1.1161 + ruleTable.OpenL(aGrammarID);
1.1162 + ruleTable.RemoveRuleL(aRuleID);
1.1163 + CleanupStack::PopAndDestroy(&ruleTable);
1.1164 + }
1.1165 +
1.1166 +void CSDDatabase::GetAllRuleIDsL(TGrammarID aGrammarID, RArray<TRuleID>& aRuleIDs)
1.1167 + {
1.1168 + RSDRuleTable ruleTable(*this);
1.1169 + CleanupClosePushL(ruleTable);
1.1170 + ruleTable.OpenL(aGrammarID);
1.1171 + ruleTable.GetAllRuleIDsL(aRuleIDs);
1.1172 + CleanupStack::PopAndDestroy(&ruleTable);
1.1173 + }
1.1174 +TBool CSDDatabase::RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID)
1.1175 + {
1.1176 + RSDRuleTable ruleTable(*this);
1.1177 + CleanupClosePushL(ruleTable);
1.1178 + ruleTable.OpenL(aGrammarID);
1.1179 + TBool found = ruleTable.FindRuleL(aRuleID);
1.1180 + CleanupStack::PopAndDestroy(&ruleTable);
1.1181 + return found;
1.1182 + }
1.1183 +
1.1184 +TUint32 CSDDatabase::AllocNewIDL()
1.1185 + {
1.1186 + RSDSettingsTable settingsTable(*this);
1.1187 + CleanupClosePushL(settingsTable);
1.1188 + settingsTable.OpenL();
1.1189 + TUint32 lastID = settingsTable.GetValueL(KSettingLastID);
1.1190 + lastID++;
1.1191 + settingsTable.SetValueL(KSettingLastID, lastID);
1.1192 + CleanupStack::PopAndDestroy(&settingsTable);
1.1193 + return lastID;
1.1194 + }
1.1195 +
1.1196 +void CSDDatabase::UpdateLastIDL(TUint32 aAddedID)
1.1197 + {
1.1198 + RSDSettingsTable settingsTable(*this);
1.1199 + CleanupClosePushL(settingsTable);
1.1200 + settingsTable.OpenL();
1.1201 + TUint32 lastID = settingsTable.GetValueL(KSettingLastID);
1.1202 + if (aAddedID > lastID)
1.1203 + settingsTable.SetValueL(KSettingLastID, aAddedID);
1.1204 + CleanupStack::PopAndDestroy();
1.1205 + }
1.1206 +
1.1207 +
1.1208 +//TUint32 CSDDatabase::iLastID = 100;
1.1209 +
1.1210 +TUid CSDDatabase::ClientUid()
1.1211 + {
1.1212 + return iClientUid;
1.1213 + }
1.1214 +
1.1215 +RDbDatabase& CSDDatabase::Database()
1.1216 + {
1.1217 + return iDatabase;
1.1218 + }
1.1219 +
1.1220 +void CSDDatabase::CommitChangesL()
1.1221 + {
1.1222 + iDatabase.Commit();
1.1223 + }
1.1224 +
1.1225 +void CSDDatabase::StartTransactionL()
1.1226 + {
1.1227 + if (!iDatabase.InTransaction())
1.1228 + iDatabase.Begin();
1.1229 + }
1.1230 +
1.1231 +void CSDDatabase::CreateTestDatabaseL()
1.1232 + {
1.1233 + TInt i,j;
1.1234 + // Add Grammars
1.1235 + for (i = 0;i<KNumGrammars;i++)
1.1236 + AddGrammarL(KGrammarIDs[i]);
1.1237 +
1.1238 + // Add Lexicons
1.1239 + for (i = 0;i<KNumLexicons;i++)
1.1240 + AddLexiconL(KLexiconIDs[i]);
1.1241 +
1.1242 + // Add ModelBanks
1.1243 + for (i = 0;i<KNumLexicons;i++)
1.1244 + AddModelBankL(KModelBankIDs[i]);
1.1245 +
1.1246 + // Add Rules
1.1247 + for (i = 0;i<KNumGrammars;i++)
1.1248 + for (j = 0; j < KNumRules; j++)
1.1249 + {
1.1250 + TGrammarID grammarID = KGrammarIDs[i];
1.1251 + TRuleData ruleData = KRuleIDs[i][j];
1.1252 + AddRuleL(grammarID, ruleData);
1.1253 + }
1.1254 +
1.1255 + // Add Pronunciations
1.1256 + for (i = 0;i<KNumLexicons;i++)
1.1257 + for (j = 0; j < KNumPronunciations; j++)
1.1258 + {
1.1259 + TLexiconID lexiconID = KLexiconIDs[i];
1.1260 + TPronunciationData pronunciationData = KPronunciationIDs[i][j];
1.1261 + AddPronunciationL(lexiconID, pronunciationData);
1.1262 + }
1.1263 +
1.1264 + // Add Models
1.1265 + for (i = 0;i<KNumModelBanks;i++)
1.1266 + for (j = 0; j < KNumModels; j++)
1.1267 + {
1.1268 + TModelData modelData = KModelIDs[i][j];
1.1269 + TModelBankID modelBankID = KModelBankIDs[i];
1.1270 + AddModelL(modelBankID, modelData);
1.1271 + }
1.1272 + CommitChangesL();
1.1273 + }
1.1274 +
1.1275 +