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