⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lb_dbase.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// LB_DBASE.CPP
//
// Copyright (c) 1997-2002 Symbian Ltd. All rights reserved.

#include <s32file.h>
#include <opcodes.h>
#include <opldoc.h>
#include "dbpriv.h"
#include <opldb.h>
#include "oplutil.h"

#pragma message("lb_dbase.cpp: Need to up LBC for dbase use???")

void OpCode::Create(CStack& , COplRuntime& aRuntime, CFrame*)
/* At the IP: Logicalnumber, field(1) type, field (1) lbc for name, field(1)name, field(2),... -1
Types -1 end, 0 int, 1 long, 2 double, 3 string */
	{
 	aRuntime.DbManager()->OpenL(EDbCreate,ETrue);
	aRuntime.ClearTrap();
	}

void OpCode::Open(CStack& , COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenL(EDbOpen,ETrue);
	aRuntime.ClearTrap();
	}
void OpCode::OpenR(CStack& , COplRuntime& aRuntime, CFrame* )
	{
	aRuntime.DbManager()->OpenL(EDbOpen,EFalse);
	aRuntime.ClearTrap();
	}

void OpCode::FieldRightSideInt(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	COplRowSet* oplRs;
	TInt ordinal=aRuntime.DbManager()->GetRightSideRowSet(oplRs);
	if(oplRs->AccessDbRowSet()->AtRow())
		aStack.Push(oplRs->AccessDbRowSet()->ColInt16(ordinal));
	else
		aStack.Push(TInt16(0));
	}

void OpCode::FieldRightSideLong(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	COplRowSet* oplRs;
	TInt ordinal=aRuntime.DbManager()->GetRightSideRowSet(oplRs);
	if(oplRs->AccessDbRowSet()->AtRow())
		aStack.Push(oplRs->AccessDbRowSet()->ColInt32(ordinal));
	else
		aStack.Push(TInt32(0));
	}

void OpCode::FieldRightSideFloat(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	COplRowSet* oplRs;
	TInt ordinal=aRuntime.DbManager()->GetRightSideRowSet(oplRs);
	if(oplRs->AccessDbRowSet()->AtRow())
		aStack.Push(oplRs->AccessDbRowSet()->ColReal64(ordinal));
	else
		aStack.Push(TReal64(0));
	}

void OpCode::FieldRightSideString(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	COplRowSet* oplRs;
	TInt ordinal=aRuntime.DbManager()->GetRightSideRowSet(oplRs);
	if(oplRs->AccessDbRowSet()->AtRow())
		aStack.Push(oplRs->AccessDbRowSet()->ColDes(ordinal));
	else
		aStack.Push(KNullDesC);
	}

TInt COplDbManager::GetRightSideRowSet(COplRowSet*& aOplRs)
	{
	TInt log(iRuntime.IP8());
	aOplRs=(iLogicalNames->FindRowSet(log));
	if (aOplRs==NULL)
		User::Leave(KOplErrClosed);
	if(!aOplRs->InAppendOrUpdate() && !aOplRs->InModifyOrInsert() && aOplRs->AccessDbRowSet()->AtRow())
		aOplRs->AccessDbRowSet()->GetL();
	return(aOplRs->GetOrdinal(iStack.PopString()));
	}

EXPORT_C TInt COplRowSet::GetOrdinal(const TDesC& aOplFieldName)
	{
	return(iMap->ScanForOrdinal(aOplFieldName));
	}

void OpCode::FieldLeftSide(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->LeftSide(aRuntime.IP8());
	}

void FuncOpCode::Find(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->FindString(aStack.PopString());
	}

void FuncOpCode::FindField(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->FindField();
	}

void OpCode::Last(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->LastL();
	aRuntime.ClearTrap();
	}

void OpCode::First(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
 	aRuntime.DbManager()->FirstL();
	aRuntime.ClearTrap();
	}

void OpCode::Next(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->NextL();
	aRuntime.ClearTrap();
	}

void OpCode::Back(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->BackL();
	aRuntime.ClearTrap();
	}
	
void OpCode::Erase(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->Erase();
	aRuntime.ClearTrap();
	}

void OpCode::Close(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->Close();
	aRuntime.ClearTrap();
	}

void OpCode::Use(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->UseLog(aRuntime.IP8());
	aRuntime.ClearTrap();
	}

void FuncOpCode::Count(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	COplRowSet* r=aRuntime.DbManager()->TheCurrentOplRs(); 
	if(r->InModifyOrInsert() || r->InAppendOrUpdate())
		User::Leave(KOplErrIncompatibleUpdateMode);
	aStack.Push(TInt16(aRuntime.DbManager()->Count()));
	}

void OpCode::Position(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CancelIfUpdate();
	aRuntime.DbManager()->PositionL(TUint(aStack.PopInt16()));
	aRuntime.ClearTrap();
	} // moves

void FuncOpCode::Pos(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->PosL(); // findout
	}

void FuncOpCode::Eof(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aStack.Push(TInt16(aRuntime.DbManager()->EOF() ? -1 : 0));
	}

void OpCode::Update(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->UpdateL(); 
	aRuntime.ClearTrap();
	}
	
void OpCode::Append(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->AppendL();
	aRuntime.ClearTrap();
	}

void FuncOpCode::Space(CStack& aStack, COplRuntime& aRuntime, CFrame*)
/*
Returns LONG of bytes left on the device where the current logical name is from
  */
	{
	// just fix stack for now
	aRuntime.DbManager()->OpenCheckL();
	aStack.Push(aRuntime.DbManager()->Space());
	}

void FuncOpCode::Bookmark(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aStack.Push(TInt16(aRuntime.DbManager()->Bookmark()));
	aRuntime.ClearTrap();
	}

void OpCode::GotoMark(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->GotoMark(aStack.PopInt16());
	aRuntime.ClearTrap();
	}

void OpCode::KillMark(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->KillMark(aStack.PopInt16());
	aRuntime.ClearTrap();
	}

void OpCode::Rollback(CStack& , COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->Rollback();
	}

void OpCode::CommitTrans(CStack& , COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->CommitTrans();
	}

void OpCode::BeginTrans(CStack& , COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->BeginTrans();
	}

void FuncOpCode::InTrans(CStack& aStack,COplRuntime& aRuntime,CFrame *)
	{
	aRuntime.DbManager()->OpenCheckL();
	aStack.Push(TInt16(aRuntime.DbManager()->InTrans()));
	}

void OpCode::Compact(CStack& aStack, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->CompactL(aStack.PopString());
	}

void OpCode::Modify(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->ModifyL();
	aRuntime.ClearTrap();
	}

void OpCode::Insert(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->InsertL();
	aRuntime.ClearTrap();
	}

void OpCode::Put(CStack&, COplRuntime& aRuntime, CFrame*)
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->PutL();
	aRuntime.ClearTrap();
	}

void OpCode::Cancel(CStack&, COplRuntime& aRuntime, CFrame*)		
	{
	aRuntime.DbManager()->OpenCheckL();
	aRuntime.DbManager()->Cancel();
	}

void OpCode::DeleteTable(CStack& aStack, COplRuntime& aRuntime, CFrame* /*  */)
/*
In:	stack0  = table$
	stack1  = dbase$
*/
	{
	TPtrC table=aStack.PopString();
	TPtrC dbase=aStack.PopString();
	aRuntime.DbManager()->DeleteTable(table,dbase);
	aRuntime.ClearTrap();
	}

/**************************************
  CONSTRUCTORS / DESTRUCTORS
**************************************/

COplDbManager* COplDbManager::NewL(COplRuntime& aRuntime,CStack& aStack)
	{
	COplDbManager* self= new (ELeave) COplDbManager(aRuntime,aStack);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

COplDbManager::COplDbManager(COplRuntime& aRuntime,CStack& aStack)
	:iRuntime(aRuntime), iStack(aStack),iBookmarkArray(KBookmarkGranularity),iFs(aRuntime.ConEnv()->FsSession())
	{
	}

void COplDbManager::ConstructL()
	{
	iLogicalNames=CLogicalNames::NewL();
	iOplDbCollection=COplDbCollection::NewL();
//	TOplBookmark p;
//	p.KillMark();
//	for(TInt ii=0;ii<KBookmarkGranularity;ii++)
//		iBookmarkArray.AppendL(p);
	}
	
COplDbManager::~COplDbManager()
	{
	if (iLogicalNames)
		{
		iLogicalNames->CancelAllUpdates();
		delete (iLogicalNames);
		}
	delete (iOplDbCollection);
	}

COplDbCollection* COplDbCollection::NewL()
	{
	COplDbCollection* self= new (ELeave) COplDbCollection;
	return self;
	}

COplDbCollection::COplDbCollection()
	:iOplDb(KMaxLogName)
	{
	}

COplDbCollection::~COplDbCollection()
	{
	for (TInt ii=0;ii<iOplDb.Count();ii++)
		{
		iOplDb[ii]->Close();
		delete iOplDb[ii];
		}
	}

COplDb* COplDb::NewLC(const TDesC& aName)
	{
	COplDb* self= new (ELeave) COplDb(aName);
	CleanupStack::PushL(self);
	return self;
	}

COplDb::COplDb(const TDesC& aName) 
	{
	iName=aName;
	iStore=NULL;
	iDataApp=EFalse;
	}

COplDb::~COplDb()
	{
	delete iStore;
	}

EXPORT_C CLogicalNames* CLogicalNames::NewL()
	{
	CLogicalNames* self= new (ELeave) CLogicalNames;
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

void CLogicalNames::ConstructL()
	{
	COplRowSet* p=NULL;
	for (TInt ii=0;ii<KMaxLogName;ii++)
		iLogNames.AppendL(p);
	}

CLogicalNames::CLogicalNames()
	:iLogNames(KMaxLogName)
	{
	iCurrLogName=EDbNone;
	iCount=0;
	} 

EXPORT_C CLogicalNames::~CLogicalNames()
	{
	for(TInt ii=0;ii<KMaxLogName;ii++)
		{
		if(iLogNames[ii]&&iLogNames[ii]->InAppendOrUpdate())
			{
			iLogNames[ii]->AccessDbRowSet()->Cancel();
			iLogNames[ii]->AccessDbRowSet()->Close();
			iLogNames[ii]->AppendOrUpdate(EFalse);
			}
		}
	iLogNames.ResetAndDestroy();
	}

COplFieldMap::COplFieldMap(TInt aCount)
	:iFieldInfoArray(aCount)
	{
	}

EXPORT_C COplFieldMap* COplFieldMap::NewLC(TInt fCount)
	{
	COplFieldMap* self= new (ELeave) COplFieldMap(fCount);
	CleanupStack::PushL(self);
	return self;
	}

COplRowSet::COplRowSet(COplDbCollection& aDbCollect)
	:iDbCollect(aDbCollect)
	{
	}

void COplRowSet::ConstructL(RFs& aFs,const TDesC& aDatabase,COplFieldMap* aFieldMap,TOplDbOpenMode aMode, TBool allowUpdates)
	{
	iRowsWereAbsent=EFalse;
	TLex lex(aDatabase);
	TFileName dbName;
	TParse parser;

	lex.SkipSpaceAndMark();
	if (lex.Peek()=='"')
		{
		TInt posA=aDatabase.Locate('"');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -