📄 data.cpp
字号:
aCol.iMaxLength = length;
else if (type <= EDbColDateTime)
{
if (1 < length)
User::Leave(KOplErrSyntax);
if (length == 1)
aCol.iAttributes = TDbCol::ENotNull;
}
iDbColSet->AddL(aCol);
iOplAPI.Push(0.0);
}
void COpxOplDb::DbCreateTable()
{
TPtrC aTableName = iOplAPI.PopString();
TPtrC aFileName = iOplAPI.PopString();
CDbasePtr* dbase = CDbasePtr::NewLC(iOplAPI, aFileName, ETrue, ETrue);
dbase->Dbase().CreateTable(aTableName, *iDbColSet);
delete iDbColSet;
iDbColSet = NULL;
CleanupStack::PopAndDestroy(); // dbase
iOplAPI.Push(0.0);
}
void COpxOplDb::DbCount() const
{
iOplAPI.OpenCheckL();
COplDbManager* dbManager = iOplAPI.DbManager();
COplRowSet* aOplRs=dbManager->TheCurrentOplRs();
if (aOplRs==NULL)
User::Leave(KOplErrClosed);
TInt32 aCount = aOplRs->AccessDbRowSet()->CountL();
iOplAPI.Push(aCount);
}
void COpxOplDb::DbSeek(TInt aProcNum) const
{
RDbTable::TComparison aComparison = RDbTable::TComparison(iOplAPI.PopInt32());
TPtrC anIndexName = iOplAPI.PopString();
TPtrC aTableName = iOplAPI.PopString();
iOplAPI.OpenCheckL();
COplDbManager* dbManager = iOplAPI.DbManager();
COplRowSet* aOplRs=dbManager->TheCurrentOplRs();
if (aOplRs==NULL)
User::Leave(KOplErrClosed);
RDbStoreDatabase &aDbase = aOplRs->ParentDbase()->StoreDbase();
RDbTable aTable;
User::LeaveIfError(aTable.Open(aDbase, aTableName)); //, RDbRowSet::EReadOnly));
User::LeaveIfError(aTable.SetIndex(anIndexName));
TDbSeekKey aKey;
switch (aProcNum)
{
case EODbSeekInt:
aKey.Add(TInt(iOplAPI.PopInt32()));
break;
case EODbSeekWord:
aKey.Add(TUint(iOplAPI.PopInt32()));
break;
case EODbSeekReal:
aKey.Add(TReal64(iOplAPI.PopReal64()));
break;
case EODbSeekText:
aKey.Add(iOplAPI.PopString());
break;
case EODbSeekDateTime:
aKey.Add(TTime(*((TDateTime*) iOplAPI.PopInt32())));
break;
}
TBool aSeekResult = aTable.SeekL(aKey, aComparison);
if (!aSeekResult)
{
// Not found
aTable.Close();
iOplAPI.Push(TInt32(0));
return;
}
// Found
TDbBookmark aBookMark = aTable.Bookmark();
aTable.Close();
aOplRs->AccessDbRowSet()->GotoL(aBookMark);
iOplAPI.Push(TInt32(1));
}
void COpxOplDb::DbGet(TInt aProcNum) const
{
TInt ind = iOplAPI.PopInt32();
iOplAPI.OpenCheckL();
COplDbManager* dbManager = iOplAPI.DbManager();
COplRowSet* aOplRs=dbManager->TheCurrentOplRs();
if (aOplRs==NULL)
User::Leave(KOplErrClosed);
if(!aOplRs->InAppendOrUpdate() && !aOplRs->InModifyOrInsert() && aOplRs->AccessDbRowSet()->AtRow())
aOplRs->AccessDbRowSet()->GetL();
RDbRowSet* aRowSet = aOplRs->AccessDbRowSet();
switch (aProcNum)
{
case EODbGetLength:
iOplAPI.Push(TInt32(aRowSet->ColLength(ind)));
break;
case EODbGetInt:
iOplAPI.Push(aRowSet->ColInt32(ind));
break;
case EODbGetReal:
iOplAPI.Push(aRowSet->ColReal64(ind));
break;
case EODbGetString:
iOplAPI.PushL(aRowSet->ColDes(ind));
break;
case EODbGetReal32:
iOplAPI.Push(TReal64(aRowSet->ColReal32(ind)));
break;
case EODbGetWord:
iOplAPI.Push(TInt32(aRowSet->ColUint32(ind)));
break;
case EODbGetDateTime:
{
TDateTime* dtime = (TDateTime*) iOplAPI.PopInt32();
*dtime = aRowSet->ColTime(ind).DateTime();
iOplAPI.Push(0.0);
}
break;
case EODbGetLong:
{
RDbColReadStream longStream;
longStream.OpenLC(*aRowSet, ind);
TInt32 length = iOplAPI.PopInt32();
TUint8* buf = iOplAPI.OffsetToAddrL(iOplAPI.PopInt32(), 2);
while (length--)
{
longStream >> *buf++;
}
CleanupStack::PopAndDestroy();
iOplAPI.Push(0.0);
}
break;
}
}
void COpxOplDb::DbPut(TInt aProcNum) const
{
TInt ind = iOplAPI.PopInt32();
iOplAPI.OpenCheckL();
COplDbManager* dbManager = iOplAPI.DbManager();
COplRowSet* aOplRs=dbManager->TheCurrentOplRs();
if (aOplRs==NULL)
User::Leave(KOplErrClosed);
RDbRowSet* aRowSet = aOplRs->AccessDbRowSet();
switch (aProcNum)
{
case EODbPutEmpty:
aRowSet->SetColNullL(ind);
break;
case EODbPutInt:
aRowSet->SetColL(ind, iOplAPI.PopInt32());
break;
case EODbPutReal:
aRowSet->SetColL(ind, iOplAPI.PopReal64());
break;
case EODbPutString:
aRowSet->SetColL(ind, iOplAPI.PopString());
break;
case EODbPutReal32:
aRowSet->SetColL(ind, TReal32(iOplAPI.PopReal64()));
break;
case EODbPutWord:
aRowSet->SetColL(ind, TUint32(iOplAPI.PopInt32()));
break;
case EODbPutDateTime:
{
TDateTime* dtime = (TDateTime*) iOplAPI.PopInt32();
aRowSet->SetColL(ind, TTime(*dtime));
}
break;
case EODbPutLong:
{
RDbColWriteStream longStream;
longStream.OpenLC(*aRowSet, ind);
TInt32 length = iOplAPI.PopInt32();
TUint8* buf = iOplAPI.OffsetToAddrL(iOplAPI.PopInt32(), 2);
while (length--)
{
longStream << *buf++;
}
longStream.CommitL();
CleanupStack::PopAndDestroy(); // longstream
}
break;
}
iOplAPI.Push(0.0);
}
const TInt KOplFindForward = 0x01;
const TInt KOplFindFromAnEnd = 0x02;
const TInt KOplFindCaseDependent = 0x10;
const TInt KOplFindFieldMask = KOplFindForward|KOplFindFromAnEnd|KOplFindCaseDependent;
TInt COpxOplDb::DbFindWhere() const
{
TInt flag=iOplAPI.PopInt16();
TPtrC string=iOplAPI.PopString();
// 0 -> not , 1 -> dependant
TDbTextComparison caseDependancy(EDbCompareFolded);
RDbRowSet::TDirection direction;
iOplAPI.OpenCheckL();
COplDbManager* dbManager = iOplAPI.DbManager();
COplRowSet* aOplRs=dbManager->TheCurrentOplRs();
if (aOplRs==NULL)
User::Leave(KOplErrClosed);
RDbRowSet* aRowSet = aOplRs->AccessDbRowSet();
if (flag&KOplFindForward)
{
direction=RDbRowSet::EForwards;
if (flag&KOplFindFromAnEnd)
dbManager->FirstL();// use dbms , NO
if (!aRowSet->AtRow())
{
aOplRs->SetPos(aRowSet->CountL()+1);
return 0;
}
}
else
{
direction=RDbRowSet::EBackwards;
if ((flag&KOplFindFromAnEnd) || (!aRowSet->AtRow()))
dbManager->LastL();
}
if (flag&KOplFindCaseDependent)
caseDependancy=EDbCompareNormal;
TDbQuery dbQuery(string, caseDependancy);
TInt iterations=aRowSet->FindL(direction, dbQuery);
if (iterations==KErrNotFound)
{
if(direction==RDbRowSet::EForwards)
aOplRs->SetPos(aRowSet->CountL()+1);
else
dbManager->FirstL();
return 0;
}
else
{
aOplRs->SetPosRelative(direction==RDbRowSet::EForwards ? iterations : -iterations);
return aOplRs->GetPos();
}
}
void COpxOplDb::DbUse() const
{
TInt32 aLog = iOplAPI.PopInt32();
iOplAPI.DbManager()->UseLog(aLog);
iOplAPI.Push(0.0);
}
//
// The members of COpxOplDb which are not language extension procedures
//
COpxOplDb::COpxOplDb(OplAPI& aOplAPI) : COpxBase(aOplAPI), iDbColSet(NULL)
{
// __DECLARE_NAME(_S("COpxOplDb"));
}
COpxOplDb* COpxOplDb::NewLC(OplAPI& aOplAPI)
{
COpxOplDb* This=new(ELeave) COpxOplDb(aOplAPI);
CleanupStack::PushL(This);
This->ConstructL();
return This;
}
void COpxOplDb::ConstructL()
{
// Do whatever is required to construct component members in COpxOplDb
}
COpxOplDb::~COpxOplDb()
{
delete iDbColSet;
// Required so that Tls is set to zero on unloading the OPX in UNLOADM
Dll::FreeTls();
}
//
// COpxBase implementation
//
void COpxOplDb::RunL(TInt aProcNum)
// Run a language extension procedure
{
switch (aProcNum)
{
case EODbGetTableCount:
DbGetTableCount();
break;
case EODbGetTableName:
DbGetTableName();
break;
case EODbGetIndexCount:
DbGetIndexCount();
break;
case EODbGetIndexName:
DbGetIndexName();
break;
case EODbGetIndexDescription:
DbGetIndexDescription();
break;
case EODbGetFieldCount:
DbGetFieldCount();
break;
case EODbGetFieldName:
case EODbGetFieldType:
case EODbGetFieldSize:
case EODbGetCanBeEmpty:
DbGetField(aProcNum);
break;
case EODbOpenR:
DbOpen(EFalse);
break;
case EODbOpen:
DbOpen(ETrue);
break;
case EODbStartTable:
DbStartTable();
break;
case EODbTableField:
DbTableField();
break;
case EODbCreateTable:
DbCreateTable();
break;
case EODbGetLength:
case EODbGetInt:
case EODbGetReal:
case EODbGetString:
case EODbGetWord:
case EODbGetReal32:
case EODbGetDateTime:
case EODbGetLong:
DbGet(aProcNum);
break;
case EODbPutEmpty:
case EODbPutInt:
case EODbPutReal:
case EODbPutString:
case EODbPutWord:
case EODbPutReal32:
case EODbPutDateTime:
case EODbPutLong:
DbPut(aProcNum);
break;
case EODbFindWhere:
iOplAPI.Push(TInt16(DbFindWhere()));
break;
case EODbFindSql:
iOplAPI.Push(TInt32(DbFindWhere()));
break;
case EODbUse:
DbUse();
break;
case EODbSeekInt:
case EODbSeekWord:
case EODbSeekText:
case EODbSeekReal:
case EODbSeekDateTime:
DbSeek(aProcNum);
break;
case EODbCount:
DbCount();
break;
default:
User::Leave(KOplErrOpxProcNotFound);
}
}
TBool COpxOplDb::CheckVersion(TInt aVersion)
// To check whether the opx is a compatible version
{
if ((aVersion & 0xff00)>(KOpxDataVersion & 0xff00)) // Major version must be <= OPX's version
return EFalse; // Bad version
else
return ETrue; // OK
}
EXPORT_C COpxBase* NewOpxL(OplAPI& aOplAPI)
// Creates a COpxBase instance as required by the OPL runtime
// This object is to be stored in the OPX's TLS as shown below
{
COpxOplDb* tls=((COpxOplDb*)Dll::Tls());
// tls is NULL on loading an OPX DLL (also after unloading it)
if (tls==NULL)
{
tls=COpxOplDb::NewLC(aOplAPI);
User::LeaveIfError(Dll::SetTls(tls));
CleanupStack::Pop(); // tls
}
return (COpxBase*)tls;
}
EXPORT_C TUint Version()
{
return KOpxDataVersion;
}
GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
{
return(KErrNone);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -