Esempio n. 1
0
char* CAppConfig::LoadGameL(midend *aME, const game *aGame) {
    TPtrC8 name((const TUint8*)aGame->name);
    RDbTable table;
    TDbSeekKey seekKey(name);
    char *errmsg = "";
    
    User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EReadOnly));

    CleanupClosePushL(table);

    User::LeaveIfError(table.SetIndex(KAutosaveIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt saveColNo = colSet->ColNo(KAutosaveSaveCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        RDbColReadStream stream;
        stream.OpenLC(table,saveColNo);
        
        errmsg = midend_deserialise(aME, read_game, &stream);
        
        CleanupStack::PopAndDestroy(&stream);
    }
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
    
    return errmsg;
}
Esempio n. 2
0
void CAppConfig::GetConfigL(const TDesC &aKey, const TConfig &aConfig) {
    RDbTable table;
    TDbSeekKey seekKey(aKey);
    
    User::LeaveIfError(table.Open(iDb, KConfigTable, table.EReadOnly));

    CleanupClosePushL(table);

    User::LeaveIfError(table.SetIndex(KConfigIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt valueColNo = colSet->ColNo(KConfigValueCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        TPtrC value = table.ColDes(valueColNo);
        
        switch (aConfig.iType) {
            case EConfigBool:
                *aConfig.iValue.iBool = value.Compare(KBoolTrue) == 0 ? ETrue : EFalse;
                break;
                
            case EConfigInt: {
                TLex lex(value);
                TInt lvalue;
                if (lex.Val(lvalue) == KErrNone) {
                    *aConfig.iValue.iInt = lvalue;
                }
                break;
            }
            
            case EConfigText:
                if (aConfig.iValue.iText->MaxLength() > value.Length()) {
                    aConfig.iValue.iText->Copy(value.Left(aConfig.iValue.iText->MaxLength()));
                } else {
                    aConfig.iValue.iText->Copy(value);
                }
                break;
                
            case EConfigText8:
                if (aConfig.iValue.iText8->MaxLength() > value.Length()) {
                    aConfig.iValue.iText8->Copy(value.Left(aConfig.iValue.iText8->MaxLength()));
                } else {
                    aConfig.iValue.iText8->Copy(value);
                }
                break;
        }
    }
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
}
Esempio n. 3
0
void CAppConfig::SetConfigL(const TDesC &aKey, const TConfig &aConfig) {
    TBuf<KConfigValueMaxLength> value;
    switch (aConfig.iType) {
        case EConfigBool:
            if (*aConfig.iValue.iBool) {
                value.Copy(KBoolTrue);
            } else {
                value.Copy(KBoolFalse);
            }
            break;
        case EConfigInt:
            value.Num(*aConfig.iValue.iInt);
            break;
        case EConfigText:
            value.Copy(*aConfig.iValue.iText);
            break;
        case EConfigText8:
            value.Copy(*aConfig.iValue.iText8);
            break;
    }
    
    RDbTable table;
    TDbSeekKey seekKey(aKey);
    
    User::LeaveIfError(table.Open(iDb, KConfigTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KConfigIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt keyColNo = colSet->ColNo(KConfigKeyCol);
    TInt valueColNo = colSet->ColNo(KConfigValueCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
        table.SetColL(valueColNo, value);
    } else {
        table.InsertL();
        table.SetColL(keyColNo, aKey);
        table.SetColL(valueColNo, value);
    }
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
}
Esempio n. 4
0
void CAppConfig::SaveGameL(midend *aME, const game *aGame) {
    TPtrC8 name((const TUint8*)aGame->name);
    RDbTable table;
    TDbSeekKey seekKey(name);
    
    User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KAutosaveIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt nameColNo = colSet->ColNo(KAutosaveNameCol);
    TInt saveColNo = colSet->ColNo(KAutosaveSaveCol);
    TInt dateColNo = colSet->ColNo(KAutosaveDateCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
    } else {
        table.InsertL();
        table.SetColL(nameColNo, name);
    }
    TTime now;
    now.HomeTime();
    table.SetColL(dateColNo, now);
    
    RDbColWriteStream stream;
    stream.OpenL(table, saveColNo);
    CleanupClosePushL(stream);
    
    midend_serialise(aME, save_game, &stream);
    CleanupStack::PopAndDestroy(&stream);
    
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
    
    iDb.Compact();
}
// ---------------------------------------------------------------------------
// CIRNmsLogDb:AddNmsLogStartL()
// adds the NmsLog log entry into data base
// ---------------------------------------------------------------------------
//
void CIRNmsLogDb::AddNmsLogStartL( CIRNmsLogger& aNmsLog )
    {
    IRLOG_DEBUG( "CIRNmsLogDb::AddNmsLogStartL" );
    OpenDbL();
    RDbTable nmsLogtable;
    TInt error=nmsLogtable.Open( iNmsLogDb, KNmsLogTable, nmsLogtable.
        EUpdatable );
    CleanupClosePushL( nmsLogtable );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    
    //! arrange the presets in incresing order of index
    nmsLogtable.SetIndex( KNmsLogIndex );
    nmsLogtable.Reset();

    //if NmsLog log is greater or equal to than 5
    if ( nmsLogtable.CountL() >= KMaxNoNmsLog )
        {
        //first row is selected
        nmsLogtable.FirstL();
        //the current row is selected
        nmsLogtable.GetL();
        //delete that entry
        nmsLogtable.DeleteL();
        }    
    CleanupStack::PopAndDestroy( &nmsLogtable );
    //Algorithm : else condition need not handle seperatly
    //Algorithm : add NmsLogid and informations like
    //starttime,connectedfrom,NmsLogid,connectiontype,channelid
    //currentnetwork,homenetwork,NmsLogtable 
    //Algorithm: if no. of NmsLog is greater than 5

    _LIT( query, "SELECT * FROM %S" );    
    HBufC* sqlStr=HBufC::NewLC( query().Length() + KNmsLogTable().Length() );
    sqlStr->Des().Format( query, &KNmsLogTable );
    
    // Create a view on the database
    RDbView view;     
    error = view.Prepare( iNmsLogDb, *sqlStr );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CleanupStack::PopAndDestroy( sqlStr );     
    CleanupClosePushL( view );
    error = view.EvaluateAll();
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CDbColSet* columns = view.ColSetL();
    CleanupStack::PushL( columns );
    
    RDbColWriteStream writeStream;
    TRAP( error, //trap start
       // Insert a row. Column order matches sql select statement
        view.InsertL();
        //get index
        view.SetColL( columns->ColNo( KID ), aNmsLog.NmsLogId() );    
        //!open stream
        writeStream.OpenLC( view, columns->ColNo( KNmsLogCol ) );
        aNmsLog.ExternalizeL( writeStream );
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
         );