mirror of
https://github.com/WinampDesktop/winamp.git
synced 2024-12-18 22:35:51 +01:00
125 lines
2.8 KiB
C++
125 lines
2.8 KiB
C++
/* ---------------------------------------------------------------------------
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|