Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
124
Src/nde/android/Record.cpp
Normal file
124
Src/nde/android/Record.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
/* ---------------------------------------------------------------------------
|
||||
Nullsoft Database Engine
|
||||
--------------------
|
||||
codename: Near Death Experience
|
||||
--------------------------------------------------------------------------- */
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
|
||||
Record Class
|
||||
|
||||
--------------------------------------------------------------------------- */
|
||||
|
||||
//#include "record.h"
|
||||
#include "../nde.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void RecordBase::Retain()
|
||||
{
|
||||
ref_count++;
|
||||
}
|
||||
|
||||
void RecordBase::Release()
|
||||
{
|
||||
if (--ref_count == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
RecordBase::RecordBase()
|
||||
{
|
||||
ref_count = 1;
|
||||
InsertionPoint = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
Record::Record(int RecordPos, int insertionPoint, VFILE *TableHandle, Table *ParentTable)
|
||||
{
|
||||
InsertionPoint = insertionPoint;
|
||||
Record *columns = ParentTable->GetColumns();
|
||||
int max=columns ? columns->Fields.size() : 128;
|
||||
if (RecordPos != 0)
|
||||
{
|
||||
int n=0;
|
||||
uint32_t ThisPos = RecordPos;
|
||||
while (ThisPos)
|
||||
{
|
||||
if (n >= max)
|
||||
break;
|
||||
Vfseek(TableHandle, ThisPos, SEEK_SET);
|
||||
Field Entry (ThisPos);
|
||||
Field *TypedEntry = Entry.ReadField(ParentTable, ThisPos, &ThisPos);
|
||||
|
||||
if (!TypedEntry) break; // some db error?
|
||||
|
||||
AddField(TypedEntry);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
RecordBase::~RecordBase()
|
||||
{
|
||||
Fields.deleteAll();
|
||||
}
|
||||
|
||||
ColumnField *Record::GetColumnByName(const char *name)
|
||||
{
|
||||
for (FieldList::iterator itr=Fields.begin();itr!=Fields.end();itr++)
|
||||
{
|
||||
ColumnField *p = (ColumnField *)*itr;
|
||||
if (!strcasecmp(p->GetFieldName(), name))
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
int Record::WriteFields(Table *ParentTable, int RecordIndex)
|
||||
{
|
||||
Field *previous = 0;
|
||||
for (FieldList::iterator itr=Fields.begin();itr!=Fields.end();itr++)
|
||||
{
|
||||
Field *p = *itr;
|
||||
p->WriteField(ParentTable, previous, (Field *)p->next);
|
||||
previous = p;
|
||||
}
|
||||
return WriteIndex(ParentTable, RecordIndex);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
int Record::WriteIndex(Table *ParentTable, int RecordIndex)
|
||||
{
|
||||
int P=0;
|
||||
if (RecordIndex == NEW_RECORD)
|
||||
RecordIndex = ParentTable->index->Insert(InsertionPoint);
|
||||
if (!Fields.empty())
|
||||
{
|
||||
Field *f = *Fields.begin();
|
||||
P=f->GetFieldPos();
|
||||
}
|
||||
return ParentTable->index->Update(RecordIndex, P, this, FALSE);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void Record::Delete(Table *ParentTable, int RecordIndex)
|
||||
{
|
||||
ParentTable->index->Delete(RecordIndex, ParentTable->index->Get(RecordIndex), this);
|
||||
}
|
||||
|
||||
void Record::WalkFields(FieldsWalker callback, void *context)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
for (FieldList::iterator itr=Fields.begin();itr!=Fields.end();itr++)
|
||||
{
|
||||
if (!callback(this, *itr, context))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue