254 |
254 |
255 if (!namespaceDef->GetTableStoredInDB()) |
255 if (!namespaceDef->GetTableStoredInDB()) |
256 { |
256 { |
257 // add base objectdef[number] |
257 // add base objectdef[number] |
258 clause->BufferL().Format( KBaseObjectDefinition, &MdeConstants::Object::KBaseObject, namespaceDefId ); |
258 clause->BufferL().Format( KBaseObjectDefinition, &MdeConstants::Object::KBaseObject, namespaceDefId ); |
259 TRAP_IGNORE( connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
259 connection.ExecuteL( clause->ConstBufferL(), emptyRowData ); |
260 |
260 |
261 // add relations[number] |
261 // add relations[number] |
262 clause->BufferL().Format( KCreateRelationsTable, namespaceDefId ); |
262 clause->BufferL().Format( KCreateRelationsTable, namespaceDefId ); |
263 TRAPD( errRel, connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
263 TRAPD( errRel, connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
264 if( errRel == KErrNone ) |
264 if( errRel == KErrNone ) |
318 EMdERelationFlagNotPresent | EMdERelationFlagDeleted, namespaceDefId ); |
318 EMdERelationFlagNotPresent | EMdERelationFlagDeleted, namespaceDefId ); |
319 connection.ExecuteL( clauseTrigger->ConstBufferL(), emptyRowData ); |
319 connection.ExecuteL( clauseTrigger->ConstBufferL(), emptyRowData ); |
320 |
320 |
321 // add updateremovedrelations[number] |
321 // add updateremovedrelations[number] |
322 clauseTrigger->ReserveSpaceL( KMdsTriggerUpdateRemovedRelation().Size() + ( KMaxUintValueLength * 5 ) ); |
322 clauseTrigger->ReserveSpaceL( KMdsTriggerUpdateRemovedRelation().Size() + ( KMaxUintValueLength * 5 ) ); |
323 clauseTrigger->BufferL().Format( KMdsTriggerUpdateRemovedRelation, namespaceDefId, namespaceDefId, EMdERelationFlagNotPresent | EMdERelationFlagDeleted, EMdERelationFlagNotPresent | EMdERelationFlagDeleted, namespaceDefId ); |
323 clauseTrigger->BufferL().Format( KMdsTriggerUpdateRemovedRelation, namespaceDefId, namespaceDefId, |
|
324 EMdERelationFlagNotPresent | EMdERelationFlagDeleted, EMdERelationFlagNotPresent | EMdERelationFlagDeleted, namespaceDefId ); |
324 connection.ExecuteL( clauseTrigger->ConstBufferL(), emptyRowData ); |
325 connection.ExecuteL( clauseTrigger->ConstBufferL(), emptyRowData ); |
325 |
326 |
326 // add relationleftobjectidindex[number] |
327 // add relationleftobjectidindex[number] |
327 clauseTrigger->ReserveSpaceL( KMdsIndexRelationLeftObjectId().Size() + ( KMaxUintValueLength * 2 ) ); |
328 clauseTrigger->ReserveSpaceL( KMdsIndexRelationLeftObjectId().Size() + ( KMaxUintValueLength * 2 ) ); |
328 clauseTrigger->BufferL().Format( KMdsIndexRelationLeftObjectId, namespaceDefId, namespaceDefId ); |
329 clauseTrigger->BufferL().Format( KMdsIndexRelationLeftObjectId, namespaceDefId, namespaceDefId ); |
355 AddObjectToSqlClauseL( objectDef, clause, EFalse ); |
356 AddObjectToSqlClauseL( objectDef, clause, EFalse ); |
356 // add text properties at end |
357 // add text properties at end |
357 AddObjectToSqlClauseL( objectDef, clause, ETrue ); |
358 AddObjectToSqlClauseL( objectDef, clause, ETrue ); |
358 |
359 |
359 clause->AppendL( KMdsSqlClauseObjTableEnd ); |
360 clause->AppendL( KMdsSqlClauseObjTableEnd ); |
360 TRAP_IGNORE( connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
361 connection.ExecuteL( clause->ConstBufferL(), emptyRowData ); |
361 |
362 |
362 objectDef->SetTableStoredInDB(); |
363 objectDef->SetTableStoredInDB(); |
363 } |
364 } |
364 |
365 |
365 const TInt objectPropertyCount = objectDef->iPropertyDefs.Count(); |
366 const TInt objectPropertyCount = objectDef->iPropertyDefs.Count(); |
391 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
392 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
392 RRowData emptyRowData; |
393 RRowData emptyRowData; |
393 CleanupClosePushL( emptyRowData ); |
394 CleanupClosePushL( emptyRowData ); |
394 clause->BufferL().Format( KMdsPropertyIndexCreate, &aTableName, &aPropertyName, aNamespaceId, |
395 clause->BufferL().Format( KMdsPropertyIndexCreate, &aTableName, &aPropertyName, aNamespaceId, |
395 &aTableName, aNamespaceId, &aPropertyName ); |
396 &aTableName, aNamespaceId, &aPropertyName ); |
|
397 // Ignore possible SQL error, MDS can still live without this index |
396 TRAP_IGNORE( connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
398 TRAP_IGNORE( connection.ExecuteL( clause->ConstBufferL(), emptyRowData ) ); |
397 CleanupStack::PopAndDestroy( 2, clause ); // emptyRowData, clause |
399 CleanupStack::PopAndDestroy( 2, clause ); // emptyRowData, clause |
398 } |
400 } |
399 |
401 |
400 void CMdsSchema::StoreToDBL() |
402 void CMdsSchema::StoreToDBL() |
406 |
408 |
407 StoreNamespacesAndBaseObjectL(); |
409 StoreNamespacesAndBaseObjectL(); |
408 CreateObjectTablesL(); |
410 CreateObjectTablesL(); |
409 StoreSchemaToDBL(); |
411 StoreSchemaToDBL(); |
410 CreateCol2PropTableL(); |
412 CreateCol2PropTableL(); |
411 |
|
412 transaction.CommitL(); |
|
413 CleanupStack::PopAndDestroy( &transaction ); |
|
414 |
413 |
415 TUint propertyCount = iProperties.Count(); |
414 TUint propertyCount = iProperties.Count(); |
416 for ( TUint i = 0; i < propertyCount; ++i ) |
415 for ( TUint i = 0; i < propertyCount; ++i ) |
417 { |
416 { |
418 TPropertyInfo& propertyInfo = iProperties[i]; |
417 TPropertyInfo& propertyInfo = iProperties[i]; |
419 CreatePropertyIndexL( propertyInfo.iPropertyName, propertyInfo.iTableName, |
418 CreatePropertyIndexL( propertyInfo.iPropertyName, propertyInfo.iTableName, |
420 propertyInfo.iNamespaceId ); |
419 propertyInfo.iNamespaceId ); |
421 } |
420 } |
|
421 |
|
422 transaction.CommitL(); |
|
423 CleanupStack::PopAndDestroy( &transaction ); |
|
424 |
422 iProperties.Reset(); |
425 iProperties.Reset(); |
423 } |
426 } |
424 |
427 |
425 void CMdsSchema::AddCol2PropObjectL( CMdsObjectDef* aObject, CMdsObjectDef* aChildObject, |
428 void CMdsSchema::AddCol2PropObjectL( CMdsObjectDef* aObject, CMdsObjectDef* aChildObject, |
426 TUint32& aPropertyColumnCounter, TBool aText ) |
429 TUint32& aPropertyColumnCounter, TBool aText ) |
562 |
565 |
563 TInt error; |
566 TInt error; |
564 for (TUint i = 0; i < KNumClauses; i++) |
567 for (TUint i = 0; i < KNumClauses; i++) |
565 { |
568 { |
566 TRAP( error,connection.ExecuteL( (*descarray)[i], emptyRowData ) ); |
569 TRAP( error,connection.ExecuteL( (*descarray)[i], emptyRowData ) ); |
567 if ( error != KErrNone && error != KSqlErrGeneral ) |
570 if ( error != KErrNone ) |
568 { |
571 { |
569 User::Leave( error ); |
572 User::Leave( error ); |
570 } |
573 } |
571 } |
574 } |
572 descarray->Reset(); |
575 descarray->Reset(); |
573 CleanupStack::PopAndDestroy( descarray ); |
576 CleanupStack::PopAndDestroy( descarray ); |
574 |
577 |
575 const TInt count = iNamespaceDefs.Count(); |
578 const TInt count = iNamespaceDefs.Count(); |
576 |
579 |
|
580 RMdSTransaction transaction( connection ); |
|
581 CleanupClosePushL(transaction); |
|
582 const TInt beginError( transaction.Error() ); |
|
583 if( beginError != KErrNone ) |
|
584 { |
|
585 CleanupStack::PopAndDestroy( &transaction ); |
|
586 } |
|
587 |
577 // add only namespaceDef to DB |
588 // add only namespaceDef to DB |
578 for( TInt i = 0; i < count; ++i ) |
589 for( TInt i = 0; i < count; ++i ) |
579 { |
590 { |
580 iNamespaceDefs[i]->StoreToDBL( ETrue ); |
591 iNamespaceDefs[i]->StoreToDBL( ETrue ); |
581 } |
592 } |
582 |
593 |
|
594 if( beginError == KErrNone ) |
|
595 { |
|
596 transaction.CommitL(); |
|
597 CleanupStack::PopAndDestroy( &transaction ); |
|
598 } |
|
599 |
583 CleanupStack::PopAndDestroy( &emptyRowData ); |
600 CleanupStack::PopAndDestroy( &emptyRowData ); |
584 } |
601 } |
585 |
602 |
586 void CMdsSchema::StoreSchemaToDBL() |
603 void CMdsSchema::StoreSchemaToDBL() |
587 { |
604 { |
588 _LIT( KMdsSqlClauseDeleteBoFromOd, "DELETE FROM ObjectDef WHERE ObjectDefId=?;" ); |
605 _LIT( KMdsSqlClauseDeleteBoFromOd, "DELETE FROM ObjectDef WHERE ObjectDefId=?;" ); |
589 _LIT( KMdsSqlClauseDeleteBoFromPd, "DELETE FROM PropertyDef WHERE ObjectDefId=?;" ); |
606 _LIT( KMdsSqlClauseDeleteBoFromPd, "DELETE FROM PropertyDef WHERE ObjectDefId=?;" ); |
590 |
607 |
|
608 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
|
609 |
|
610 RMdSTransaction transaction( connection ); |
|
611 CleanupClosePushL(transaction); |
|
612 const TInt beginError( transaction.Error() ); |
|
613 if( beginError != KErrNone ) |
|
614 { |
|
615 CleanupStack::PopAndDestroy( &transaction ); |
|
616 } |
|
617 |
591 iBaseObject->StoreToDBL( KNoDefId ); |
618 iBaseObject->StoreToDBL( KNoDefId ); |
592 |
619 |
593 const TInt count = iNamespaceDefs.Count(); |
620 const TInt count = iNamespaceDefs.Count(); |
594 |
621 |
595 // add namespaceDef to DB |
622 // add namespaceDef to DB |
596 for( TInt i = 0; i < count; ++i ) |
623 for( TInt i = 0; i < count; ++i ) |
597 { |
624 { |
598 iNamespaceDefs[i]->StoreToDBL(); |
625 iNamespaceDefs[i]->StoreToDBL(); |
599 } |
626 } |
600 |
627 |
|
628 if( beginError == KErrNone ) |
|
629 { |
|
630 transaction.CommitL(); |
|
631 CleanupStack::PopAndDestroy( &transaction ); |
|
632 } |
|
633 |
601 RRowData removeBo; |
634 RRowData removeBo; |
602 CleanupClosePushL( removeBo ); |
635 CleanupClosePushL( removeBo ); |
603 removeBo.AppendL( TColumn( KBaseObjectDefId ) ); |
636 removeBo.AppendL( TColumn( KBaseObjectDefId ) ); |
604 |
637 |
605 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
|
606 TRAPD( err, connection.ExecuteL( KMdsSqlClauseDeleteBoFromOd, removeBo ) ); |
638 TRAPD( err, connection.ExecuteL( KMdsSqlClauseDeleteBoFromOd, removeBo ) ); |
607 TRAP ( err, connection.ExecuteL( KMdsSqlClauseDeleteBoFromPd, removeBo ) ); |
639 TRAP ( err, connection.ExecuteL( KMdsSqlClauseDeleteBoFromPd, removeBo ) ); |
608 |
640 |
609 CleanupStack::PopAndDestroy( &removeBo ); |
641 CleanupStack::PopAndDestroy( &removeBo ); |
610 } |
642 } |