os/mm/mmdevicefw/speechrecogsupport/tsrc/ASR/src/Database/sddatabase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "sddatabase.h"
    17 #include "../Database/testdatabaseconstants.h"
    18 
    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");
    26 
    27 _LIT(KAllCols, "*");
    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");
    38 
    39 
    40 _LIT(KSQLSelectFromTable,"Select %S From %S");
    41 _LIT(KSQLSelectFromTableWhereCondition,"Select %S From %S Where %S=%u");
    42 
    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;
    49 
    50 const TInt KRTColNumGrammarID = 1;
    51 const TInt KRTColNumRuleID = 2;
    52 const TInt KRTColNumLexiconID = 3;
    53 const TInt KRTColNumPronunciationID =4;
    54 
    55 const TInt KPTColNumLexiconID = 1;
    56 const TInt KPTColNumPronunciationID = 2;
    57 const TInt KPTColNumModelBankID = 3;
    58 const TInt KPTColNumModelID = 4;
    59 
    60 const TInt KMTColNumModelBankID = 1;
    61 const TInt KMTColNumModelID = 2;
    62 const TInt KMTColNumUtteranceDurationMicroSeconds = 3;
    63 
    64 const TInt KSTColNumSettingsID = 1;
    65 const TInt KSTColNumSettingsValue = 2;
    66 
    67 const TInt KSettingLastID = 1;
    68 	
    69 	
    70 CSDDatabase::RSDGrammarTable::RSDGrammarTable(CSDDatabase& aDatabase)
    71 	: iDatabase(aDatabase)
    72 	{
    73 	
    74 	
    75 	}
    76 	
    77 void CSDDatabase::RSDGrammarTable::OpenL(TBool aOwnedByClient)
    78 	{
    79 	TBuf<256> query;
    80 	if (aOwnedByClient)	
    81 		query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
    82 	else	
    83 		query.Format(KSQLSelectFromTable,&KAllCols,&KTableGrammar,&KColClientUID,iDatabase.ClientUid());
    84 		
    85 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
    86 	User::LeaveIfError(iView.EvaluateAll());
    87 	
    88 	}
    89 	
    90 void CSDDatabase::RSDGrammarTable::Close()
    91 	{
    92 	iView.Close();
    93 	}
    94 	
    95 void CSDDatabase::RSDGrammarTable::CreateGrammarL(TGrammarID& aGrammarID)
    96 	{
    97 	iDatabase.StartTransactionL();
    98 	aGrammarID = iDatabase.AllocNewIDL();	
    99 	iView.InsertL();
   100 
   101 	iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
   102 	iView.SetColL(KGTColNumGrammarID,aGrammarID);
   103 	iView.PutL();
   104 	}
   105 	
   106 void CSDDatabase::RSDGrammarTable::AddGrammarL(TGrammarID aGrammarID)
   107 	{
   108 	iDatabase.StartTransactionL();
   109 	iDatabase.UpdateLastIDL(aGrammarID);
   110 	iView.InsertL();
   111 	iView.SetColL(KGTColNumClientUID,iDatabase.ClientUid().iUid);
   112 	iView.SetColL(KGTColNumGrammarID,aGrammarID);
   113 	iView.PutL();
   114 	}
   115 	
   116 	
   117 TBool CSDDatabase::RSDGrammarTable::FindGrammarL(TGrammarID aGrammarID)
   118 	{
   119 	TBool found = EFalse;
   120 	for (iView.FirstL();iView.AtRow();iView.NextL())
   121 		{
   122 		iView.GetL();
   123 		if (iView.ColUint32(KGTColNumGrammarID)==aGrammarID)
   124 			{
   125 			found = true;
   126 			break;
   127 			}
   128 		}
   129 	return found;
   130 	}
   131 	
   132 	
   133 	
   134 void CSDDatabase::RSDGrammarTable::RemoveGrammarL(TGrammarID aGrammarID)
   135 	{
   136 	if (FindGrammarL(aGrammarID))
   137 		{
   138 		if (iView.ColUint32(KGTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)		
   139 			{
   140 			iDatabase.StartTransactionL();
   141 			iView.DeleteL();
   142 			}
   143 		else
   144 			User::Leave(KErrNotFound);//change to not owned
   145 		}
   146 	else
   147 		User::Leave(KErrNotFound);
   148 	}
   149 
   150 void CSDDatabase::RSDGrammarTable::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs)
   151 	{
   152 	aGrammarIDs.Reset();
   153 	for (iView.FirstL();iView.AtRow();iView.NextL())
   154 		{
   155 		iView.GetL();
   156 		TGrammarID grammarID = iView.ColUint32(KGTColNumGrammarID);
   157 		User::LeaveIfError(aGrammarIDs.Append(grammarID));
   158 		}
   159 	}
   160 	
   161 CSDDatabase::RSDLexiconTable::RSDLexiconTable(CSDDatabase& aDatabase)
   162 	: iDatabase(aDatabase)
   163 	{
   164 	
   165 	
   166 	}
   167 	
   168 void CSDDatabase::RSDLexiconTable::OpenL(TBool aOwnedByClient)
   169 	{
   170 	TBuf<256> query;
   171 	if (aOwnedByClient)	
   172 		query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
   173 	else	
   174 		query.Format(KSQLSelectFromTable,&KAllCols,&KTableLexicon,&KColClientUID,iDatabase.ClientUid());
   175 		
   176 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   177 	User::LeaveIfError(iView.EvaluateAll());
   178 	
   179 	}
   180 	
   181 void CSDDatabase::RSDLexiconTable::Close()
   182 	{
   183 	iView.Close();
   184 	}
   185 	
   186 void CSDDatabase::RSDLexiconTable::CreateLexiconL(TLexiconID& aLexiconID)
   187 	{
   188 	iDatabase.StartTransactionL();
   189 	aLexiconID = iDatabase.AllocNewIDL();	
   190 	iView.InsertL();
   191 
   192 	iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
   193 	iView.SetColL(KLTColNumLexiconID,aLexiconID);
   194 	iView.PutL();
   195 	}
   196 	
   197 void CSDDatabase::RSDLexiconTable::AddLexiconL(TLexiconID aLexiconID)
   198 	{
   199 	iDatabase.StartTransactionL();
   200 	iDatabase.UpdateLastIDL(aLexiconID);
   201 	iView.InsertL();
   202 	iView.SetColL(KLTColNumClientUID,iDatabase.ClientUid().iUid);
   203 	iView.SetColL(KLTColNumLexiconID,aLexiconID);
   204 	iView.PutL();
   205 	}
   206 	
   207 	
   208 TBool CSDDatabase::RSDLexiconTable::FindLexiconL(TLexiconID aLexiconID)
   209 	{
   210 	TBool found = EFalse;
   211 	for (iView.FirstL();iView.AtRow();iView.NextL())
   212 		{
   213 		iView.GetL();
   214 		if (iView.ColUint32(KLTColNumLexiconID)==aLexiconID)
   215 			{
   216 			found = true;
   217 			break;
   218 			}
   219 		}
   220 	return found;
   221 	}
   222 	
   223 	
   224 	
   225 void CSDDatabase::RSDLexiconTable::RemoveLexiconL(TLexiconID aLexiconID)
   226 	{
   227 	if (FindLexiconL(aLexiconID))
   228 		{
   229 		if (iView.ColUint32(KLTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)		
   230 			{
   231 			iDatabase.StartTransactionL();
   232 			iView.DeleteL();
   233 			}
   234 		else
   235 			User::Leave(KErrNotFound);//change to not owned
   236 		}
   237 	else
   238 		User::Leave(KErrNotFound);
   239 	}
   240 
   241 void CSDDatabase::RSDLexiconTable::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs)
   242 	{
   243 	aLexiconIDs.Reset();
   244 	for (iView.FirstL();iView.AtRow();iView.NextL())
   245 		{
   246 		iView.GetL();
   247 		TLexiconID lexiconID = iView.ColUint32(KLTColNumLexiconID);
   248 		User::LeaveIfError(aLexiconIDs.Append(lexiconID));
   249 		}
   250 	}
   251 	
   252 CSDDatabase::RSDModelBankTable::RSDModelBankTable(CSDDatabase& aDatabase)
   253 	: iDatabase(aDatabase)
   254 	{
   255 	
   256 	
   257 	}
   258 	
   259 void CSDDatabase::RSDModelBankTable::OpenL(TBool aOwnedByClient)
   260 	{
   261 	TBuf<256> query;
   262 	if (aOwnedByClient)	
   263 		query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
   264 	else	
   265 		query.Format(KSQLSelectFromTable,&KAllCols,&KTableModelBank,&KColClientUID,iDatabase.ClientUid());
   266 		
   267 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   268 	User::LeaveIfError(iView.EvaluateAll());
   269 	
   270 	}
   271 	
   272 void CSDDatabase::RSDModelBankTable::Close()
   273 	{
   274 	iView.Close();
   275 	}
   276 	
   277 TModelBankID CSDDatabase::RSDModelBankTable::CreateModelBankL()
   278 	{
   279 	iDatabase.StartTransactionL();
   280 	TModelBankID modelBankID;
   281 	modelBankID = iDatabase.AllocNewIDL();	
   282 	iView.InsertL();
   283 
   284 	iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
   285 	iView.SetColL(KMBTColNumModelBankID,modelBankID);
   286 	iView.PutL();
   287 	return modelBankID;
   288 	}
   289 	
   290 void CSDDatabase::RSDModelBankTable::AddModelBankL(TModelBankID aModelBankID)
   291 	{
   292 	iDatabase.StartTransactionL();
   293 	iDatabase.UpdateLastIDL(aModelBankID);
   294 	iView.InsertL();
   295 	iView.SetColL(KMBTColNumClientUID,iDatabase.ClientUid().iUid);
   296 	iView.SetColL(KMBTColNumModelBankID,aModelBankID);
   297 	iView.PutL();
   298 	}
   299 	
   300 	
   301 TBool CSDDatabase::RSDModelBankTable::FindModelBankL(TModelBankID aModelBankID)
   302 	{
   303 	TBool found = EFalse;
   304 	for (iView.FirstL();iView.AtRow();iView.NextL())
   305 		{
   306 		iView.GetL();
   307 		if (iView.ColUint32(KMBTColNumModelBankID)==aModelBankID)
   308 			{
   309 			found = true;
   310 			break;
   311 			}
   312 		}
   313 	return found;
   314 	}
   315 	
   316 	
   317 	
   318 void CSDDatabase::RSDModelBankTable::RemoveModelBankL(TModelBankID aModelBankID)
   319 	{
   320 	if (FindModelBankL(aModelBankID))
   321 		{
   322 		if (iView.ColUint32(KMBTColNumClientUID)==(TUint32)iDatabase.ClientUid().iUid)		
   323 			{
   324 			iDatabase.StartTransactionL();
   325 			iView.DeleteL();
   326 			}
   327 		else
   328 			User::Leave(KErrNotFound);//change to not owned
   329 		}
   330 	else
   331 		User::Leave(KErrNotFound);
   332 	}
   333 
   334 void CSDDatabase::RSDModelBankTable::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs)
   335 	{
   336 	aModelBankIDs.Reset();
   337 	for (iView.FirstL();iView.AtRow();iView.NextL())
   338 		{
   339 		iView.GetL();
   340 		TModelBankID modelBankID = iView.ColUint32(KMBTColNumModelBankID);
   341 		User::LeaveIfError(aModelBankIDs.Append(modelBankID));
   342 		}
   343 	}
   344 	
   345 
   346 CSDDatabase::RSDModelTable::RSDModelTable(CSDDatabase& aDatabase)
   347 	: iDatabase(aDatabase)
   348 	{
   349 	
   350 	
   351 	}
   352 	
   353 void CSDDatabase::RSDModelTable::OpenL(TModelBankID aModelBankID)
   354 	{
   355 	if (!iDatabase.ModelBankExistsL(aModelBankID))
   356 		User::Leave(KErrNotFound);
   357 
   358 	iModelBankID = aModelBankID;
   359 	TBuf<256> query;
   360 	query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableModel,&KColModelBankID,aModelBankID);		
   361 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   362 	User::LeaveIfError(iView.EvaluateAll());
   363 	
   364 	}
   365 	
   366 void CSDDatabase::RSDModelTable::Close()
   367 	{
   368 	iView.Close();
   369 	}
   370 	
   371 TModelID CSDDatabase::RSDModelTable::CreateModelL(TModelData aModelData)
   372 	{
   373 	iDatabase.StartTransactionL();
   374 	TModelID modelID = iDatabase.AllocNewIDL();	
   375 	iView.InsertL();
   376 	iView.SetColL(KMTColNumModelBankID,iModelBankID);
   377 	iView.SetColL(KMTColNumModelID,modelID);
   378 	iView.SetColL(KMTColNumUtteranceDurationMicroSeconds,aModelData.iUtteranceDurationMicroSeconds);
   379 	iView.PutL();
   380 	return modelID;
   381 	}
   382 	
   383 void CSDDatabase::RSDModelTable::AddModelL(TModelData aModelData)
   384 	{
   385 	iDatabase.StartTransactionL();
   386 	iDatabase.UpdateLastIDL(aModelData.iModelID);
   387 	iView.InsertL();
   388 	iView.SetColL(KMTColNumModelBankID,iModelBankID);
   389 	iView.SetColL(KMTColNumModelID,aModelData.iModelID);
   390 	iView.SetColL(KMTColNumUtteranceDurationMicroSeconds, aModelData.iUtteranceDurationMicroSeconds);
   391 	iView.PutL();
   392 	}
   393 
   394 void CSDDatabase::RSDModelTable::GetModelDataL(TModelID aModelID, TModelData& aModelData)
   395 	{
   396 	if (!FindModelL(aModelID))
   397 		User::Leave(KErrNotFound);
   398 
   399 	iView.GetL();
   400 	aModelData.iModelID = iView.ColUint32(KMTColNumModelID);
   401 	aModelData.iUtteranceDurationMicroSeconds = iView.ColUint32(KMTColNumUtteranceDurationMicroSeconds);
   402 	}
   403 
   404 	
   405 	
   406 TBool CSDDatabase::RSDModelTable::FindModelL(TModelID aModelID)
   407 	{
   408 	TBool found = EFalse;
   409 	for (iView.FirstL();iView.AtRow();iView.NextL())
   410 		{
   411 		iView.GetL();
   412 		if (iView.ColUint32(KMTColNumModelID)==aModelID) 
   413 			{
   414 			found = true;
   415 			break;
   416 			}
   417 		}
   418 	return found;
   419 	}
   420 	
   421 	
   422 	
   423 void CSDDatabase::RSDModelTable::RemoveModelL(TModelID aModelID)
   424 	{
   425 	if (FindModelL(aModelID))
   426 		{
   427 		iDatabase.StartTransactionL();
   428 		iView.DeleteL();
   429 		}
   430 	else
   431 		User::Leave(KErrNotFound);
   432 	}
   433 
   434 void CSDDatabase::RSDModelTable::GetAllModelIDsL(RArray<TModelID>& aModelIDs)
   435 	{
   436 	aModelIDs.Reset();
   437 	for (iView.FirstL();iView.AtRow();iView.NextL())
   438 		{
   439 		iView.GetL();
   440 		TModelID modelID = iView.ColUint32(KMTColNumModelID);
   441 		User::LeaveIfError(aModelIDs.Append(modelID));
   442 		}
   443 	}
   444 
   445 //------------------------------------------------------------------------------------------------
   446 CSDDatabase::RSDSettingsTable::RSDSettingsTable(CSDDatabase& aDatabase)
   447 	: iDatabase(aDatabase)
   448 	{
   449 	
   450 	
   451 	}
   452 	
   453 void CSDDatabase::RSDSettingsTable::OpenL()
   454 	{
   455 	TBuf<256> query;
   456 	query.Format(KSQLSelectFromTable,&KAllCols,&KTableSettings);		
   457 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   458 	User::LeaveIfError(iView.EvaluateAll());
   459 	}
   460 	
   461 void CSDDatabase::RSDSettingsTable::Close()
   462 	{
   463 	iView.Close();
   464 	}
   465 	
   466 TUint32 CSDDatabase::RSDSettingsTable::GetValueL(TUint32 aSettingID)
   467 	{
   468 	TUint32 value = 0;
   469 	TBool found = EFalse;
   470 	for (iView.FirstL();iView.AtRow();iView.NextL())
   471 		{
   472 		iView.GetL();
   473 		if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
   474 			{
   475 			value = iView.ColUint32(KSTColNumSettingsValue);	
   476 			found = ETrue;
   477 			break;
   478 			}
   479 
   480 		}
   481 	if (!found)
   482 		User::Leave(KErrNotFound);
   483 
   484 	return value;
   485 	}
   486 
   487 void CSDDatabase::RSDSettingsTable::SetValueL(TUint32 aSettingID, TUint32 aValue)
   488 	{
   489 	TBool found = EFalse;
   490 	for (iView.FirstL();iView.AtRow();iView.NextL())
   491 		{
   492 		iView.GetL();
   493 		if (iView.ColUint32(KSTColNumSettingsID)==aSettingID)
   494 			{
   495 			iView.UpdateL();
   496 			iView.SetColL(KSTColNumSettingsValue, aValue);	
   497 			iView.PutL();
   498 			found = ETrue;
   499 			break;
   500 			}
   501 
   502 		}
   503 	// if it wasn't found, add it
   504 	if (!found)
   505 		{
   506 		iView.InsertL();
   507 		iView.SetColL(KSTColNumSettingsID, aSettingID);	
   508 		iView.SetColL(KSTColNumSettingsValue, aValue);	
   509 		iView.PutL();
   510 		}
   511 	}
   512 	
   513 
   514 //------------------------------------------------------------------------------------------------
   515 
   516 CSDDatabase::RSDPronunciationTable::RSDPronunciationTable(CSDDatabase& aDatabase)
   517 	: iDatabase(aDatabase)
   518 	{
   519 	
   520 	
   521 	}
   522 	
   523 void CSDDatabase::RSDPronunciationTable::OpenL(TLexiconID aLexiconID)
   524 	{
   525 	if (!iDatabase.LexiconExistsL(aLexiconID))
   526 		User::Leave(KErrNotFound);
   527 
   528 	iLexiconID = aLexiconID;
   529 	TBuf<256> query;
   530 	query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTablePronunciation,&KColLexiconID,aLexiconID);		
   531 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   532 	User::LeaveIfError(iView.EvaluateAll());
   533 	
   534 	}
   535 	
   536 void CSDDatabase::RSDPronunciationTable::Close()
   537 	{
   538 	iView.Close();
   539 	}
   540 	
   541 TPronunciationID CSDDatabase::RSDPronunciationTable::CreatePronunciationL(TPronunciationData aPronunciationData)
   542 	{
   543 	TPronunciationID pronunciationID;
   544 	iDatabase.StartTransactionL();
   545 	pronunciationID = iDatabase.AllocNewIDL();
   546 	iView.InsertL();
   547 	iView.SetColL(KPTColNumLexiconID,iLexiconID);
   548 	iView.SetColL(KPTColNumPronunciationID,pronunciationID);
   549 	iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
   550 	iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
   551 	iView.PutL();
   552 	return pronunciationID;
   553 	}
   554 	
   555 void CSDDatabase::RSDPronunciationTable::AddPronunciationL(TPronunciationData aPronunciationData)
   556 	{
   557 	iDatabase.StartTransactionL();
   558 	iDatabase.UpdateLastIDL(aPronunciationData.iPronunciationID);
   559 	iView.InsertL();
   560 	iView.SetColL(KPTColNumLexiconID,iLexiconID);
   561 	iView.SetColL(KPTColNumPronunciationID,aPronunciationData.iPronunciationID);
   562 	iView.SetColL(KPTColNumModelBankID,aPronunciationData.iModelBankID);
   563 	iView.SetColL(KPTColNumModelID,aPronunciationData.iModelID);
   564 	iView.PutL();
   565 	}
   566 
   567 void CSDDatabase::RSDPronunciationTable::GetPronunciationDataL(TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
   568 	{
   569 	if (!FindPronunciationL(aPronunciationID))
   570 		User::Leave(KErrNotFound);
   571 
   572 	iView.GetL();
   573 	aPronunciationData.iPronunciationID = iView.ColUint32(KPTColNumPronunciationID);
   574 	aPronunciationData.iModelBankID = iView.ColUint32(KPTColNumModelBankID);
   575 	aPronunciationData.iModelID = iView.ColUint32(KPTColNumModelID);
   576 	}
   577 
   578 	
   579 	
   580 TBool CSDDatabase::RSDPronunciationTable::FindPronunciationL(TPronunciationID aPronunciationID)
   581 	{
   582 	TBool found = EFalse;
   583 	for (iView.FirstL();iView.AtRow();iView.NextL())
   584 		{
   585 		iView.GetL();
   586 		if (iView.ColUint32(KPTColNumPronunciationID)==aPronunciationID)
   587 			{
   588 			found = true;
   589 			break;
   590 			}
   591 		}
   592 	return found;
   593 	}
   594 	
   595 	
   596 	
   597 void CSDDatabase::RSDPronunciationTable::RemovePronunciationL(TPronunciationID aPronunciationID)
   598 	{
   599 	if (FindPronunciationL(aPronunciationID))
   600 		{
   601 		iDatabase.StartTransactionL();
   602 		iView.DeleteL();
   603 		}
   604 	else
   605 		User::Leave(KErrNotFound);
   606 	}
   607 
   608 void CSDDatabase::RSDPronunciationTable::GetAllPronunciationIDsL(RArray<TPronunciationID>& aPronunciationIDs)
   609 	{
   610 	aPronunciationIDs.Reset();
   611 	for (iView.FirstL();iView.AtRow();iView.NextL())
   612 		{
   613 		iView.GetL();
   614 		TPronunciationID modelID = iView.ColUint32(KPTColNumPronunciationID);
   615 		User::LeaveIfError(aPronunciationIDs.Append(modelID));
   616 		}
   617 	}
   618 //--------------------------------------------------------------------------------------------------
   619 
   620 CSDDatabase::RSDRuleTable::RSDRuleTable(CSDDatabase& aDatabase)
   621 	: iDatabase(aDatabase)
   622 	{
   623 	
   624 	
   625 	}
   626 	
   627 void CSDDatabase::RSDRuleTable::OpenL(TGrammarID aGrammarID)
   628 	{
   629 	if (!iDatabase.GrammarExistsL(aGrammarID))
   630 		User::Leave(KErrNotFound);
   631 
   632 	iGrammarID = aGrammarID;
   633 	TBuf<256> query;
   634 	query.Format(KSQLSelectFromTableWhereCondition,&KAllCols,&KTableRule,&KColGrammarID,aGrammarID);		
   635 	User::LeaveIfError(iView.Prepare(iDatabase.Database(),TDbQuery(query,EDbCompareNormal)));
   636 	User::LeaveIfError(iView.EvaluateAll());
   637 	
   638 	}
   639 	
   640 void CSDDatabase::RSDRuleTable::Close()
   641 	{
   642 	iView.Close();
   643 	}
   644 	
   645 TRuleID CSDDatabase::RSDRuleTable::CreateRuleL(TRuleData aRuleData)
   646 	{
   647 	iDatabase.StartTransactionL();
   648 	TRuleID ruleID = iDatabase.AllocNewIDL();	
   649 	iView.InsertL();
   650 	iView.SetColL(KRTColNumGrammarID,iGrammarID);
   651 	iView.SetColL(KRTColNumRuleID,ruleID);
   652 	iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
   653 	iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
   654 	iView.PutL();
   655 	return ruleID;
   656 	}
   657 	
   658 void CSDDatabase::RSDRuleTable::AddRuleL(TRuleData aRuleData)
   659 	{
   660 	iDatabase.StartTransactionL();
   661 	iDatabase.UpdateLastIDL(aRuleData.iRuleID);
   662 
   663 	iView.InsertL();
   664 	iView.SetColL(KRTColNumGrammarID,iGrammarID);
   665 	iView.SetColL(KRTColNumRuleID,aRuleData.iRuleID);
   666 	iView.SetColL(KRTColNumLexiconID,aRuleData.iLexiconID);
   667 	iView.SetColL(KRTColNumPronunciationID,aRuleData.iPronunciationID);
   668 	iView.PutL();
   669 	}
   670 	
   671 	
   672 TBool CSDDatabase::RSDRuleTable::FindRuleL(TRuleID aRuleID)
   673 	{
   674 	TBool found = EFalse;
   675 	for (iView.FirstL();iView.AtRow();iView.NextL())
   676 		{
   677 		iView.GetL();
   678 		if (iView.ColUint32(KRTColNumRuleID)==aRuleID)
   679 			{
   680 			found = true;
   681 			break;
   682 			}
   683 		}
   684 	return found;
   685 	}
   686 	
   687 TBool CSDDatabase::RSDRuleTable::IsRuleValidL(TRuleID aRuleID)
   688 	{
   689 	TBool valid = EFalse;
   690 	TBool found = FindRuleL(aRuleID);
   691 	if (found)
   692 		{
   693 		TLexiconID lexiconID = iView.ColUint32(KRTColNumLexiconID);
   694 		TPronunciationID pronunciationID = iView.ColUint32(KRTColNumPronunciationID);
   695 		if (iDatabase.LexiconExistsL(lexiconID) && 
   696 			iDatabase.PronunciationExistsL(lexiconID, pronunciationID))
   697 			{
   698 			valid = ETrue;
   699 			}
   700 		}
   701 	else
   702 		User::Leave(KErrNotFound);
   703 	return valid;
   704 	}
   705 	
   706 	
   707 void CSDDatabase::RSDRuleTable::RemoveRuleL(TRuleID aRuleID)
   708 	{
   709 	if (FindRuleL(aRuleID))
   710 		{
   711 		iDatabase.StartTransactionL();
   712 		iView.DeleteL();
   713 		}
   714 	else
   715 		User::Leave(KErrNotFound);
   716 	}
   717 
   718 void CSDDatabase::RSDRuleTable::GetAllRuleIDsL(RArray<TRuleID>& aRuleIDs)
   719 	{
   720 	aRuleIDs.Reset();
   721 	for (iView.FirstL();iView.AtRow();iView.NextL())
   722 		{
   723 		iView.GetL();
   724 		TRuleID modelID = iView.ColUint32(KRTColNumRuleID);
   725 		User::LeaveIfError(aRuleIDs.Append(modelID));
   726 		}
   727 	}
   728 //--------------------------------------------------------------------------------------------------
   729 
   730 
   731 CSDDatabase* CSDDatabase::NewL(const TDesC& aFileName, TBool aUseExisting)
   732 	{
   733 	CSDDatabase* self = new (ELeave) CSDDatabase;
   734 	CleanupStack::PushL(self);
   735 	self->ConstructL(aFileName, aUseExisting);
   736 	CleanupStack::Pop();
   737 	return self;	
   738 	}
   739 	
   740 	
   741 void CSDDatabase::SetClientUid(TUid aClientUid)
   742 	{
   743 	iClientUid = aClientUid;
   744 	}
   745 	
   746 void CSDDatabase::ConstructL(const TDesC& aFileName, TBool aUseExisting)
   747 	{
   748  	if (aUseExisting)
   749 		OpenDatabaseL(aFileName);
   750 	else
   751 		CreateDatabaseL(aFileName);
   752 	}
   753 	
   754 void CSDDatabase::OpenDatabaseL(const TDesC& aFileName)
   755 	{
   756 	RFs fsSession;
   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;
   762 	}
   763 	
   764 	
   765 void CSDDatabase::CreateDatabaseL(const TDesC& aFileName)
   766 	{
   767 	RFs fsSession;
   768 	User::LeaveIfError(fsSession.Connect());
   769 	iDbStore = CPermanentFileStore::ReplaceL(fsSession,aFileName,EFileRead|EFileWrite);
   770 	// Complete file store creation
   771 	iDbStore->SetTypeL(iDbStore->Layout());
   772 
   773 				// Create a database in the store
   774 	TStreamId id=iDatabase.CreateL(iDbStore);
   775 	iDbStore->SetRootL(id);
   776 
   777 				// Complete database creation by commiting the store
   778 	iDbStore->CommitL();
   779 
   780 	// create the CDs table
   781 	DoCreateTablesL();
   782 
   783 	// create an index
   784 	DoCreateIndexesL();
   785 
   786 	// add the inital settings
   787 	RSDSettingsTable settingsTable(*this);
   788 	settingsTable.OpenL();
   789 	CleanupClosePushL(settingsTable);
   790 	settingsTable.SetValueL(KSettingLastID, 0);
   791 	CleanupStack::PopAndDestroy(&settingsTable);
   792 	}
   793 
   794 CSDDatabase::CSDDatabase()
   795 	{
   796 	
   797 	}
   798 	
   799 CSDDatabase::~CSDDatabase()
   800 	{
   801 	if (iDatabaseOpened)
   802 		{
   803 		if (iDatabase.InTransaction())
   804 			{
   805 			iDatabase.Rollback();
   806 			if (iDatabase.IsDamaged())
   807 				iDatabase.Recover();
   808 			}
   809 		}
   810 	iDatabase.Close();		
   811 	delete iDbStore;
   812 	}
   813 	
   814 	
   815 void CSDDatabase::DoCreateTablesL()
   816 	{
   817 	CDbColSet* columns;
   818 	
   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);
   825 
   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);
   832 
   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);
   839 	
   840 	// create Rule Table
   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));
   846 
   847 	User::LeaveIfError(iDatabase.CreateTable(KTableRule,*columns));	
   848 	CleanupStack::PopAndDestroy(columns);
   849 
   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);
   858 
   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);
   866 
   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);
   873 	}
   874 	
   875 	
   876 void CSDDatabase::DoCreateIndexesL()
   877 	{
   878 	
   879 	
   880 	}
   881 	
   882 TGrammarID CSDDatabase::CreateGrammarL()
   883 	{
   884 	TGrammarID grammarID;
   885 	RSDGrammarTable grammarTable(*this);
   886 	CleanupClosePushL(grammarTable);
   887 	grammarTable.OpenL();
   888 	grammarTable.CreateGrammarL(grammarID);
   889 	CleanupStack::PopAndDestroy(&grammarTable);
   890 	return grammarID;
   891 	}
   892 void CSDDatabase::AddGrammarL(TGrammarID aGrammarID)
   893 	{
   894 	RSDGrammarTable grammarTable(*this);
   895 	CleanupClosePushL(grammarTable);
   896 	grammarTable.OpenL();
   897 	grammarTable.AddGrammarL(aGrammarID);
   898 	CleanupStack::PopAndDestroy(&grammarTable);
   899 	}
   900 	
   901 void CSDDatabase::RemoveGrammarL(TGrammarID aGrammarID)
   902 	{
   903 	RSDGrammarTable grammarTable(*this);
   904 	CleanupClosePushL(grammarTable);
   905 	grammarTable.OpenL();
   906 	grammarTable.RemoveGrammarL(aGrammarID);
   907 	CleanupStack::PopAndDestroy(&grammarTable);
   908 	}
   909 	
   910 void CSDDatabase::GetAllGrammarIDsL(RArray<TGrammarID>& aGrammarIDs, TBool aOwnedByClient)
   911 	{
   912 	RSDGrammarTable grammarTable(*this);
   913 	CleanupClosePushL(grammarTable);
   914 	grammarTable.OpenL(aOwnedByClient);
   915 	grammarTable.GetAllGrammarIDsL(aGrammarIDs);
   916 	CleanupStack::PopAndDestroy(&grammarTable);
   917 	}
   918 TBool CSDDatabase::GrammarExistsL(TGrammarID aGrammarID)
   919 	{
   920 	RSDGrammarTable grammarTable(*this);
   921 	CleanupClosePushL(grammarTable);
   922 	grammarTable.OpenL();
   923 	TBool found = grammarTable.FindGrammarL(aGrammarID);
   924 	CleanupStack::PopAndDestroy(&grammarTable);
   925 	return found;
   926 	}
   927 	
   928 TLexiconID CSDDatabase::CreateLexiconL()
   929 	{
   930 	TLexiconID lexiconID;
   931 	RSDLexiconTable lexiconTable(*this);
   932 	CleanupClosePushL(lexiconTable);
   933 	lexiconTable.OpenL();
   934 	lexiconTable.CreateLexiconL(lexiconID);
   935 	CleanupStack::PopAndDestroy(&lexiconTable);
   936 	return lexiconID;
   937 	}
   938 void CSDDatabase::AddLexiconL(TLexiconID aLexiconID)
   939 	{
   940 	RSDLexiconTable lexiconTable(*this);
   941 	CleanupClosePushL(lexiconTable);
   942 	lexiconTable.OpenL();
   943 	lexiconTable.AddLexiconL(aLexiconID);
   944 	CleanupStack::PopAndDestroy(&lexiconTable);
   945 	}
   946 	
   947 void CSDDatabase::RemoveLexiconL(TLexiconID aLexiconID)
   948 	{
   949 	RSDLexiconTable lexiconTable(*this);
   950 	CleanupClosePushL(lexiconTable);
   951 	lexiconTable.OpenL();
   952 	lexiconTable.RemoveLexiconL(aLexiconID);
   953 	CleanupStack::PopAndDestroy(&lexiconTable);
   954 	}
   955 	
   956 void CSDDatabase::GetAllLexiconIDsL(RArray<TLexiconID>& aLexiconIDs, TBool aOwnedByClient)
   957 	{
   958 	RSDLexiconTable lexiconTable(*this);
   959 	CleanupClosePushL(lexiconTable);
   960 	lexiconTable.OpenL(aOwnedByClient);
   961 	lexiconTable.GetAllLexiconIDsL(aLexiconIDs);
   962 	CleanupStack::PopAndDestroy(&lexiconTable);
   963 	}
   964 TBool CSDDatabase::LexiconExistsL(TLexiconID aLexiconID)
   965 	{
   966 	RSDLexiconTable lexiconTable(*this);
   967 	CleanupClosePushL(lexiconTable);
   968 	lexiconTable.OpenL();
   969 	TBool found = lexiconTable.FindLexiconL(aLexiconID);
   970 	CleanupStack::PopAndDestroy(&lexiconTable);
   971 	return found;
   972 	}
   973 	
   974 TModelBankID CSDDatabase::CreateModelBankL()
   975 	{
   976 	TModelBankID modelBankID;
   977 	RSDModelBankTable modelBankTable(*this);
   978 	CleanupClosePushL(modelBankTable);
   979 	modelBankTable.OpenL();
   980 	modelBankID = modelBankTable.CreateModelBankL();
   981 	CleanupStack::PopAndDestroy(&modelBankTable);
   982 	return modelBankID;
   983 	}
   984 void CSDDatabase::AddModelBankL(TModelBankID aModelBankID)
   985 	{
   986 	RSDModelBankTable modelBankTable(*this);
   987 	CleanupClosePushL(modelBankTable);
   988 	modelBankTable.OpenL();
   989 	modelBankTable.AddModelBankL(aModelBankID);
   990 	CleanupStack::PopAndDestroy(&modelBankTable);
   991 	}
   992 	
   993 void CSDDatabase::RemoveModelBankL(TModelBankID aModelBankID)
   994 	{
   995 	RSDModelBankTable modelBankTable(*this);
   996 	CleanupClosePushL(modelBankTable);
   997 	modelBankTable.OpenL();
   998 	modelBankTable.RemoveModelBankL(aModelBankID);
   999 	CleanupStack::PopAndDestroy(&modelBankTable);
  1000 	}
  1001 	
  1002 void CSDDatabase::GetAllModelBankIDsL(RArray<TModelBankID>& aModelBankIDs, TBool aOwnedByClient)
  1003 	{
  1004 	RSDModelBankTable modelBankTable(*this);
  1005 	CleanupClosePushL(modelBankTable);
  1006 	modelBankTable.OpenL(aOwnedByClient);
  1007 	modelBankTable.GetAllModelBankIDsL(aModelBankIDs);
  1008 	CleanupStack::PopAndDestroy(&modelBankTable);
  1009 	}
  1010 TBool CSDDatabase::ModelBankExistsL(TModelBankID aModelBankID)
  1011 	{
  1012 	RSDModelBankTable modelBankTable(*this);
  1013 	CleanupClosePushL(modelBankTable);
  1014 	modelBankTable.OpenL();
  1015 	TBool found = modelBankTable.FindModelBankL(aModelBankID);
  1016 	CleanupStack::PopAndDestroy(&modelBankTable);
  1017 	return found;
  1018 	}
  1019 	
  1020 	
  1021 //------------------------------------------------------------------------------------------
  1022 TModelID CSDDatabase::CreateModelL(TModelBankID aModelBankID, TModelData aModelData)
  1023 	{
  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;
  1032 	}
  1033 void CSDDatabase::AddModelL(TModelBankID aModelBankID, TModelData aModelData)
  1034 	{
  1035 	RSDModelTable modelTable(*this);
  1036 	CleanupClosePushL(modelTable);
  1037 	modelTable.OpenL(aModelBankID);
  1038 	modelTable.AddModelL(aModelData);
  1039 	CleanupStack::PopAndDestroy(&modelTable);
  1040 	}
  1041 	
  1042 void CSDDatabase::RemoveModelL(TModelBankID aModelBankID, TModelID aModelID)
  1043 	{
  1044 	RSDModelTable modelTable(*this);
  1045 	CleanupClosePushL(modelTable);
  1046 	modelTable.OpenL(aModelBankID);
  1047 	modelTable.RemoveModelL(aModelID);
  1048 	CleanupStack::PopAndDestroy(&modelTable);
  1049 	}
  1050 
  1051 void CSDDatabase::GetModelDataL(TModelBankID aModelBankID, TModelID aModelID, TModelData& aModelData)
  1052 	{
  1053 	RSDModelTable modelTable(*this);
  1054 	CleanupClosePushL(modelTable);
  1055 	modelTable.OpenL(aModelBankID);
  1056 	modelTable.GetModelDataL(aModelID, aModelData);
  1057 	CleanupStack::PopAndDestroy(&modelTable);
  1058 	}
  1059 
  1060 
  1061 void CSDDatabase::GetAllModelIDsL(TModelBankID aModelBankID, RArray<TModelID>& aModelIDs)
  1062 	{
  1063 	RSDModelTable modelTable(*this);
  1064 	CleanupClosePushL(modelTable);
  1065 	modelTable.OpenL(aModelBankID);
  1066 	modelTable.GetAllModelIDsL(aModelIDs);
  1067 	CleanupStack::PopAndDestroy(&modelTable);
  1068 	}
  1069 TBool CSDDatabase::ModelExistsL(TModelBankID aModelBankID, TModelID aModelID)
  1070 	{
  1071 	RSDModelTable modelTable(*this);
  1072 	CleanupClosePushL(modelTable);
  1073 	modelTable.OpenL(aModelBankID);
  1074 	TBool found = modelTable.FindModelL(aModelID);
  1075 	CleanupStack::PopAndDestroy(&modelTable);
  1076 	return found;
  1077 	}
  1078 //------------------------------------------------------------------------------------------
  1079 TPronunciationID CSDDatabase::CreatePronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
  1080 	{
  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;
  1088 	}
  1089 void CSDDatabase::AddPronunciationL(TLexiconID aLexiconID, TPronunciationData aPronunciationData)
  1090 	{
  1091 	RSDPronunciationTable pronunciationTable(*this);
  1092 	CleanupClosePushL(pronunciationTable);
  1093 	pronunciationTable.OpenL(aLexiconID);
  1094 	pronunciationTable.AddPronunciationL(aPronunciationData);
  1095 	CleanupStack::PopAndDestroy(&pronunciationTable);
  1096 	}
  1097 	
  1098 void CSDDatabase::RemovePronunciationL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
  1099 	{
  1100 	RSDPronunciationTable pronunciationTable(*this);
  1101 	CleanupClosePushL(pronunciationTable);
  1102 	pronunciationTable.OpenL(aLexiconID);
  1103 	pronunciationTable.RemovePronunciationL(aPronunciationID);
  1104 	CleanupStack::PopAndDestroy(&pronunciationTable);
  1105 	}
  1106 
  1107 void CSDDatabase::GetPronunciationDataL(TLexiconID aLexiconID, TPronunciationID aPronunciationID, TPronunciationData& aPronunciationData)
  1108 	{
  1109 	RSDPronunciationTable pronunciationTable(*this);
  1110 	CleanupClosePushL(pronunciationTable);
  1111 	pronunciationTable.OpenL(aLexiconID);
  1112 	pronunciationTable.GetPronunciationDataL(aPronunciationID, aPronunciationData);
  1113 	CleanupStack::PopAndDestroy(&pronunciationTable);
  1114 	}
  1115 	
  1116 void CSDDatabase::GetAllPronunciationIDsL(TLexiconID aLexiconID, RArray<TPronunciationID>& aPronunciationIDs)
  1117 	{
  1118 	RSDPronunciationTable pronunciationTable(*this);
  1119 	CleanupClosePushL(pronunciationTable);
  1120 	pronunciationTable.OpenL(aLexiconID);
  1121 	pronunciationTable.GetAllPronunciationIDsL(aPronunciationIDs);
  1122 	CleanupStack::PopAndDestroy(&pronunciationTable);
  1123 	}
  1124 TBool CSDDatabase::PronunciationExistsL(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
  1125 	{
  1126 	RSDPronunciationTable pronunciationTable(*this);
  1127 	CleanupClosePushL(pronunciationTable);
  1128 	pronunciationTable.OpenL(aLexiconID);
  1129 	TBool found = pronunciationTable.FindPronunciationL(aPronunciationID);
  1130 	CleanupStack::PopAndDestroy(&pronunciationTable);
  1131 	return found;
  1132 	}	
  1133 	
  1134 //------------------------------------------------------------------------------------------
  1135 TRuleID CSDDatabase::CreateRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
  1136 	{
  1137 	TRuleID ruleID;
  1138 	RSDRuleTable ruleTable(*this);
  1139 	CleanupClosePushL(ruleTable);
  1140 	ruleTable.OpenL(aGrammarID);
  1141 	ruleID = ruleTable.CreateRuleL(aRuleData);
  1142 	CleanupStack::PopAndDestroy(&ruleTable);
  1143 	return ruleID;
  1144 	}
  1145 void CSDDatabase::AddRuleL(TGrammarID aGrammarID, TRuleData aRuleData)
  1146 	{
  1147 	RSDRuleTable ruleTable(*this);
  1148 	CleanupClosePushL(ruleTable);
  1149 	ruleTable.OpenL(aGrammarID);
  1150 	ruleTable.AddRuleL(aRuleData);
  1151 	CleanupStack::PopAndDestroy(&ruleTable);
  1152 	}
  1153 	
  1154 void CSDDatabase::RemoveRuleL(TGrammarID aGrammarID, TRuleID aRuleID)
  1155 	{
  1156 	RSDRuleTable ruleTable(*this);
  1157 	CleanupClosePushL(ruleTable);
  1158 	ruleTable.OpenL(aGrammarID);
  1159 	ruleTable.RemoveRuleL(aRuleID);
  1160 	CleanupStack::PopAndDestroy(&ruleTable);
  1161 	}
  1162 	
  1163 void CSDDatabase::GetAllRuleIDsL(TGrammarID aGrammarID, RArray<TRuleID>& aRuleIDs)
  1164 	{
  1165 	RSDRuleTable ruleTable(*this);
  1166 	CleanupClosePushL(ruleTable);
  1167 	ruleTable.OpenL(aGrammarID);
  1168 	ruleTable.GetAllRuleIDsL(aRuleIDs);
  1169 	CleanupStack::PopAndDestroy(&ruleTable);
  1170 	}
  1171 TBool CSDDatabase::RuleExistsL(TGrammarID aGrammarID, TRuleID aRuleID)
  1172 	{
  1173 	RSDRuleTable ruleTable(*this);
  1174 	CleanupClosePushL(ruleTable);
  1175 	ruleTable.OpenL(aGrammarID);
  1176 	TBool found = ruleTable.FindRuleL(aRuleID);
  1177 	CleanupStack::PopAndDestroy(&ruleTable);
  1178 	return found;
  1179 	}	
  1180 
  1181 TUint32 CSDDatabase::AllocNewIDL()
  1182 	{
  1183 	RSDSettingsTable settingsTable(*this);
  1184 	CleanupClosePushL(settingsTable);
  1185 	settingsTable.OpenL();
  1186 	TUint32 lastID = settingsTable.GetValueL(KSettingLastID);
  1187 	lastID++;
  1188 	settingsTable.SetValueL(KSettingLastID, lastID);
  1189 	CleanupStack::PopAndDestroy(&settingsTable);
  1190 	return lastID;
  1191 	}
  1192 
  1193 void CSDDatabase::UpdateLastIDL(TUint32 aAddedID)
  1194 	{
  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();
  1202 	}
  1203 
  1204 	
  1205 //TUint32 CSDDatabase::iLastID = 100;
  1206 
  1207 TUid CSDDatabase::ClientUid()
  1208 	{
  1209 	return iClientUid;
  1210 	}
  1211 	
  1212 RDbDatabase& CSDDatabase::Database() 
  1213 	{
  1214 	return iDatabase;
  1215 	}
  1216 	
  1217 void CSDDatabase::CommitChangesL()
  1218 	{
  1219 	iDatabase.Commit();
  1220 	}
  1221 	
  1222 void CSDDatabase::StartTransactionL()
  1223 	{
  1224 	if (!iDatabase.InTransaction())
  1225 		iDatabase.Begin();
  1226 	}
  1227 	
  1228 void CSDDatabase::CreateTestDatabaseL()
  1229 	{
  1230 	TInt i,j;
  1231 	// Add Grammars
  1232 	for (i = 0;i<KNumGrammars;i++)
  1233 		AddGrammarL(KGrammarIDs[i]);
  1234 		
  1235 	// Add Lexicons
  1236 	for (i = 0;i<KNumLexicons;i++)
  1237 		AddLexiconL(KLexiconIDs[i]);
  1238 	
  1239 	// Add ModelBanks
  1240 	for (i = 0;i<KNumLexicons;i++)
  1241 		AddModelBankL(KModelBankIDs[i]);
  1242 	
  1243 	// Add Rules
  1244 	for (i = 0;i<KNumGrammars;i++)
  1245 		for (j = 0; j < KNumRules; j++)
  1246 			{
  1247 			TGrammarID grammarID = KGrammarIDs[i];
  1248 			TRuleData ruleData = KRuleIDs[i][j];
  1249 			AddRuleL(grammarID, ruleData);
  1250 			}
  1251 		
  1252 	// Add Pronunciations
  1253 	for (i = 0;i<KNumLexicons;i++)
  1254 		for (j = 0; j < KNumPronunciations; j++)
  1255 			{
  1256 			TLexiconID lexiconID = KLexiconIDs[i];
  1257 			TPronunciationData pronunciationData = KPronunciationIDs[i][j];
  1258 			AddPronunciationL(lexiconID, pronunciationData);
  1259 			}
  1260 			
  1261 	// Add Models
  1262 	for (i = 0;i<KNumModelBanks;i++)
  1263 		for (j = 0; j < KNumModels; j++)
  1264 			{
  1265 			TModelData modelData = KModelIDs[i][j];
  1266 			TModelBankID modelBankID = KModelBankIDs[i];
  1267 			AddModelL(modelBankID, modelData);
  1268 			}
  1269 	CommitChangesL();
  1270 	}
  1271 
  1272