metadataengine/server/src/mdssqldbmaintenance.cpp
changeset 0 c53acadfccc6
child 40 910a23996aa0
child 54 a3cc46f37772
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  SQL database startup routines*
       
    15 */
       
    16 
       
    17 // INCLUDE FILES
       
    18 #include "mdssqldbmaintenance.h"
       
    19 #include "mdccommon.h"
       
    20 #include "mdspreferences.h"
       
    21 
       
    22 // ========================= MEMBER FUNCTIONS ==================================
       
    23 
       
    24 CMdSSqlDbMaintenance* CMdSSqlDbMaintenance::NewL()
       
    25     {
       
    26     CMdSSqlDbMaintenance* self = CMdSSqlDbMaintenance::NewLC();
       
    27     CleanupStack::Pop( self );
       
    28     return self;
       
    29     }
       
    30 
       
    31 CMdSSqlDbMaintenance* CMdSSqlDbMaintenance::NewLC()
       
    32     {
       
    33     CMdSSqlDbMaintenance* self = new ( ELeave ) CMdSSqlDbMaintenance();
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     return self;
       
    37     }
       
    38 
       
    39 void CMdSSqlDbMaintenance::ConstructL( )
       
    40     {
       
    41     }
       
    42 
       
    43 CMdSSqlDbMaintenance::CMdSSqlDbMaintenance()
       
    44     {
       
    45     }
       
    46 
       
    47 CMdSSqlDbMaintenance::~CMdSSqlDbMaintenance()
       
    48     {
       
    49     }
       
    50 
       
    51 TBool CMdSSqlDbMaintenance::ValidateL(  )
       
    52     {
       
    53     _LIT( KValidateTableExistence, "SELECT COUNT(*) FROM MdE_Preferences;" );
       
    54 
       
    55     RMdsStatement validationQuery;
       
    56     CleanupClosePushL( validationQuery );
       
    57     RRowData emptyRowData;
       
    58     CleanupClosePushL( emptyRowData );
       
    59     CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
       
    60 	TRAPD( test, connection.ExecuteQueryL( KValidateTableExistence, validationQuery, emptyRowData ) );
       
    61 	CleanupStack::PopAndDestroy( 2, &validationQuery );
       
    62     return ( test == KErrNone );
       
    63     }
       
    64 
       
    65 
       
    66 void CMdSSqlDbMaintenance::CreateDatabaseL()
       
    67     {
       
    68     _LIT( KCreateTblMdE_Preferences, // Table for metadata engine use
       
    69     	"CREATE TABLE MdE_Preferences(Key TEXT,Value NONE,ExtraValue LARGEINT,UNIQUE(Key,Value));");
       
    70 
       
    71     _LIT( KCreateTblMdS_Medias, // Table for metadata engine use
       
    72 		"CREATE TABLE MdS_Medias(MediaId INTEGER PRIMARY KEY,Drive INTEGER,PresentState INTEGER,Time LARGEINT);");
       
    73     
       
    74     RRowData emptyRowData;
       
    75     CleanupClosePushL( emptyRowData );
       
    76 
       
    77     // Create ontology tables
       
    78     CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
       
    79 
       
    80     connection.ExecuteL( KCreateTblMdE_Preferences, emptyRowData );
       
    81 
       
    82     connection.ExecuteL( KCreateTblMdS_Medias, emptyRowData );
       
    83 
       
    84     TInt majorVersion = KMdSServMajorVersionNumber;
       
    85 	TInt64 minorVersion = KMdSServMinorVersionNumber;
       
    86     MMdsPreferences::InsertL( KMdsDBVersionName, MMdsPreferences::EPreferenceBothSet,
       
    87     						  majorVersion, minorVersion );
       
    88 
       
    89 	CleanupStack::PopAndDestroy( &emptyRowData );
       
    90     }
       
    91