📄 lb_dbase.cpp
字号:
EXPORT_C void COplDbManager::Erase()
{
if (iCurrDbRowSet->AtRow())
{
SafetyDeleteL();
iCurrDbRowSet->NextL();
}
else
User::Leave(KOplErrEof);
}
EXPORT_C void COplDbManager::LeftSide(TInt log)
// Leaves with KOplErrClosed if logical file not open
// To be stacked:
// logical file name (byte at IP)
// ELeftSideField as integer
//
{
COplRowSet* rs;
if ((rs=iLogicalNames->FindRowSet(log))==NULL)
User::Leave(KOplErrClosed);
iStack.Push(TInt16(log));
iStack.Push(TInt16(ELeftSideField));
}
EXPORT_C void COplRowSet::InsertBlankL()
{ // insert zero filled field as last record
iDbRowSet->InsertL();
iDbRowSet->PutL();
SetPos(iDbRowSet->CountL());
}
EXPORT_C void COplRowSet::CopyCurrRowToEnd()
{
// current row remembered and copied to end
SetPosBeforeInsert(iDbRowSet->Bookmark());
iDbRowSet->InsertCopyL();
}
EXPORT_C void COplRowSet::PrepareForUpdate()
{
// Gets row set being aasigned to, copies (if necessary)
// the current row to the end of
// rowSet, locks this row ready for updating
if(!InAppendOrUpdate())
{
if(!iDbRowSet->CountL())
iRowsWereAbsent=ETrue;
if(iDbRowSet->AtRow())
CopyCurrRowToEnd();
else
iDbRowSet->InsertL();
AppendOrUpdate(ETrue);
}
}
RDbRowSet& COplDbManager::PreAssign(TDbColNo& aField)
// T.O.Stack = TInt16 logicalFileName (0)
// next = OplString fieldName
// NOT NECESSARILY CURRENT ROWset
{
COplRowSet* oplRs=iLogicalNames->FindRowSet(iStack.PopInt16());
aField=oplRs->GetOrdinal(iStack.PopString());
if(!oplRs->InModifyOrInsert())
{
oplRs->PrepareForUpdate();
return *oplRs->AccessDbRowSet();
}
else
return *iCurrDbRowSet;
}
void COplDbManager::Assign(TInt16 aVal)
{
TDbColNo field;
RDbRowSet& row=PreAssign(field);
row.SetColL(field,aVal);
}
void COplDbManager::Assign(TInt32 aVal)
{
TDbColNo field;
RDbRowSet& row=PreAssign(field);
row.SetColL(field,aVal);
}
void COplDbManager::Assign(TReal64 aReal)
{
TDbColNo field;
RDbRowSet& row=PreAssign(field);
row.SetColL(field,aReal);
}
void COplDbManager::Assign(TDesC& aString)
{
TDbColNo field;
RDbRowSet& row=PreAssign(field);
row.SetColL(field,aString);
}
EXPORT_C void COplDbManager::CancelIfUpdate()
{
if (iLogicalNames->Count())
{
if (iCurrOplRowSet->InAppendOrUpdate())
{
iCurrDbRowSet->Cancel();
iCurrOplRowSet->AppendOrUpdate(EFalse);
iCurrOplRowSet->ResetRowsAbsent();
}
if (iCurrOplRowSet->InModifyOrInsert())
{
iCurrDbRowSet->Cancel();
iCurrOplRowSet->ModifyOrInsert(EFalse);
}
}
}
EXPORT_C void CLogicalNames::CancelAllUpdates()
{
if (iCount!=0)
{
for(TInt ii=0;ii<iCount;ii++)
{
while(iLogNames[ii]==NULL)
ii++;
iLogNames[ii]->AccessDbRowSet()->Cancel();
iLogNames[ii]->AppendOrUpdate(EFalse);
}
}
}
EXPORT_C void COplDbManager::ModifyL()
{
if(!iCurrDbRowSet->AtRow())
User::Leave(KOplErrEof);
if ((!iCurrOplRowSet->InAppendOrUpdate()) && (!iCurrOplRowSet->InModifyOrInsert()))
{
iCurrOplRowSet->ModifyOrInsert(ETrue); // set mode if in neither
iCurrDbRowSet->UpdateL();
}
else
User::Leave(KOplErrIncompatibleUpdateMode); // error if in any mode already
}
EXPORT_C void COplDbManager::InsertL()
{
if ((!iCurrOplRowSet->InAppendOrUpdate()) && (!iCurrOplRowSet->InModifyOrInsert()))
{
iCurrDbRowSet->InsertL();
iCurrOplRowSet->ModifyOrInsert(ETrue); // set mode if in neither
iCurrOplRowSet->InsertMode(ETrue);
}
else
User::Leave(KOplErrIncompatibleUpdateMode); // error if in any mode already
}
EXPORT_C void COplDbManager::PutL()
{
if(!iCurrOplRowSet->InModifyOrInsert() || iCurrOplRowSet->InAppendOrUpdate())
User::Leave(KOplErrIncompatibleUpdateMode);// cant append if in wrong mode
SafelyPutL();
iCurrOplRowSet->ModifyOrInsert(EFalse);
if(iCurrOplRowSet->InInsertMode())
{
iCurrOplRowSet->SetPos(iCurrDbRowSet->CountL());
iCurrOplRowSet->InsertMode(EFalse);
}
}
EXPORT_C void COplDbManager::SafelyPutL()
{
TRAPD(err,iCurrDbRowSet->PutL());
if (err)
{
Cancel();
User::Leave(err);
}
}
EXPORT_C void COplDbManager::SafetyDeleteL()
{
TRAPD(err,iCurrDbRowSet->DeleteL());
if (err)
{
HandleAutoTransactionRollback();
User::Leave(err);
}
}
EXPORT_C void COplDbManager::Cancel()
{
iCurrDbRowSet->Cancel();
HandleAutoTransactionRollback();
iCurrOplRowSet->AppendOrUpdate(EFalse);
iCurrOplRowSet->ModifyOrInsert(EFalse);
iCurrOplRowSet->InsertMode(EFalse);
}
EXPORT_C void COplDbManager::HandleAutoTransactionRollback()
{
if(iCurrOplRowSet->ParentDbase()->StoreDbase().InTransaction())
return;
TRAPD(err,iCurrDbRowSet->CountL(RDbRowSet::EQuick));
if (err==KErrNotReady)
ResetRelatedViews();
}
EXPORT_C void COplDbManager::ResetRelatedViews()
{
TPtrC parentName=iCurrOplRowSet->ParentDbase()->Name();
for(TInt ii=0;ii<KMaxLogName;ii++)
{
COplRowSet* temp=(*(iLogicalNames->RowSetArray()))[ii];
if (temp!=NULL)
{
if(temp->ParentDbase()->Name()==parentName)
{
RDbRowSet* tempRowset=temp->AccessDbRowSet();
TDbBookmark mark=tempRowset->Bookmark();
tempRowset->Reset();
TRAPD(err,tempRowset->GotoL(mark));
if (err)
temp->SetPos(1);
}
}
}
}
EXPORT_C void COplDbManager::AppendL()
{
if (iCurrOplRowSet->InModifyOrInsert())
User::Leave(KOplErrIncompatibleUpdateMode); // Can't append if in wrong mode
else
{
if (iCurrOplRowSet->InAppendOrUpdate())
{
iCurrOplRowSet->AppendOrUpdate(EFalse); // set false changes be altered
iCurrOplRowSet->ResetRowsAbsent();
SafelyPutL();
iCurrOplRowSet->SetPos(iCurrDbRowSet->CountL());
}
else if(!EOF()) //eof insert blank at end
{
iCurrOplRowSet->CopyCurrRowToEnd(); // Come straight but allowable
SafelyPutL();
iCurrOplRowSet->SetPos(iCurrDbRowSet->CountL());
}
else
iCurrOplRowSet->InsertBlankL();
}
}
EXPORT_C void COplDbManager::UpdateL()
{
if (iCurrOplRowSet->InModifyOrInsert())
User::Leave(KOplErrIncompatibleUpdateMode); // cant update if in wrong mode
if (iCurrOplRowSet->InAppendOrUpdate()) // if something inserted at EOF
{
iCurrOplRowSet->AppendOrUpdate(EFalse);
if(!iCurrOplRowSet->RowsAbsent()) // if there were rows before app/up
{
SafelyPutL();
iCurrDbRowSet->GotoL(iCurrOplRowSet->GetPosBeforeInsert());
SafetyDeleteL(); //remove updated
LastL();
}
else
{ // have been updating an empty row
iCurrOplRowSet->ResetRowsAbsent();
iCurrDbRowSet->Cancel();
User::Leave(KOplErrEof);
}
}
else
{ // calling updating with no insert
if(!EOF()) // empty -> error
{ // copy current to end and current
iCurrOplRowSet->CopyCurrRowToEnd();
SafelyPutL();
iCurrDbRowSet->GotoL(iCurrOplRowSet->GetPosBeforeInsert());
SafetyDeleteL();
LastL();
}
else
User::Leave(KOplErrEof);
}
}
EXPORT_C TBool COplDbManager::EOF()
{
return iCurrDbRowSet->AtEnd();
}
EXPORT_C TBool COplDbManager::SOF(RDbRowSet* aRs)
{
return aRs->AtBeginning();
}
EXPORT_C TBool COplDbManager::SOF()
{
return iCurrDbRowSet->AtBeginning();
}
EXPORT_C void COplDbManager::BackL()
// Back 1 record but Stays if at row 1 already
{
if (!iCurrDbRowSet->AtBeginning())
{
iCurrDbRowSet->PreviousL();
iCurrOplRowSet->SetPosRelative(-1);
}
if (iCurrDbRowSet->AtBeginning())
{
iCurrDbRowSet->NextL();
iCurrOplRowSet->SetPos(1);
}
}
EXPORT_C void COplDbManager::FirstL()
{
iCurrDbRowSet->FirstL();
iCurrOplRowSet->SetPos(1);
}
EXPORT_C void COplDbManager::NextL()
{
if(!iCurrDbRowSet->AtEnd())
{
iCurrDbRowSet->NextL();
iCurrOplRowSet->SetPosRelative(+1);
}
}
EXPORT_C void COplDbManager::LastL()
{
iCurrDbRowSet->LastL();
iCurrOplRowSet->SetPos(iCurrDbRowSet->CountL());
if(iCurrDbRowSet->AtBeginning())
{
iCurrDbRowSet->NextL();
iCurrOplRowSet->SetPos(1);
}
}
EXPORT_C void COplDbManager::PositionL(TUint aPos)
{
PosL();
TInt currPos(Stack().PopInt16());
TUint count=TUint(iCurrDbRowSet->CountL());
if (aPos==0)
aPos=1;
if (count+1<aPos)
aPos=count+1;
TInt steps=aPos-currPos;
TInt loopTo(0);
TBool direction(ETrue);
if (steps>0) // going forward
{
TInt stepsToHalfWayToEnd=(count+1-currPos)/2; // test if destination is closer to EOF
if (stepsToHalfWayToEnd>steps)
{
loopTo=steps;
direction=ETrue;
}
else // go to end and move back
{
iCurrDbRowSet->LastL();
iCurrDbRowSet->NextL(); //EOF
loopTo=(count+1-currPos-steps);
direction=EFalse;
}
}
if (steps<0)
{
TInt StepsToHalfWayToStart=(currPos)/2;
if (StepsToHalfWayToStart>(-steps)) // move backwards
{
loopTo=-steps;
direction=EFalse;
}
else // go to start and move forwards
{
iCurrDbRowSet->FirstL();
loopTo=aPos-1;
direction=ETrue;
}
}
for(TInt pp=0;pp<loopTo;pp++)
{
if (direction)
iCurrDbRowSet->NextL();
else
iCurrDbRowSet->PreviousL();
}
iCurrOplRowSet->SetPos(aPos);
}
EXPORT_C void COplDbManager::PosL()
{
iStack.Push(TInt16(iCurrOplRowSet->GetPos()));
}
EXPORT_C void COplDbManager::Close()
// close rowSet
{
iCurrDbRowSet->Close();
COplRowSet* newRs=iLogicalNames->CloseOplRowSet();
iCurrOplRowSet=newRs;
if (newRs)
iCurrDbRowSet=newRs->AccessDbRowSet();
else
iCurrDbRowSet = NULL; // cached copy
}
EXPORT_C COplRowSet* CLogicalNames::CloseOplRowSet()
{
delete iLogNames[iCurrLogName];
COplRowSet* newRs=NULL; // cached copy
iLogNames[iCurrLogName]=newRs;
iCurrLogName=EDbNone;
TInt ii=0;
iCount--;
if (iCount!=0)
{
while(iLogNames[ii]==NULL)
ii++;
newRs=iLogNames[ii];
iCurrLogName=TOplCurrRowSet(ii);
}
return newRs;
}
EXPORT_C void COplDbCollection::CloseDbIfNotInUseL(COplDb* aParent,COplRuntime& aRuntime)
// decrease access count,if zero close dbase and remove from collection
{
if (--aParent->AccessCount()==0)
{
aParent->Close();
TInt count=iOplDb.Count();
TFileName file=aParent->Name();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -