📄 relview.cpp
字号:
// RelView.cpp: implementation of the CRelView class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Database.h"
#include "RelView.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRelView::CRelView()
{
}
CRelView::CRelView(CString n,UINT id,WORD an,UINT FN,UINT rno1,UINT rno2)
:attr_num(an),DataFileNo(FN),RelNo1(rno1),RelNo2(rno2)
{
wtag=1;
rcd_len=0;//辅助
if(n.GetLength()<=10)
{
name=n;
name_length=n.GetLength()+1;
}
else
{
name=n.Left(10);
name_length=10+1;
}
time=CMemory::GetTime();
at=new CAttribute[attr_num+1];
length=GetHeadLength();//易出错
}
void CRelView::AddAttribute(USHORT index,CAttribute &a)
{
ASSERT(index>=1&&index<=attr_num);
a.offset=rcd_len;
at[index]=a;
length+=(a.GetLength());
if(a.type==CHAR_TYPE)
rcd_len+= (a.length+1);
else if(a.type==VARCHAR_TYPE)
rcd_len+= (a.length+2);
else
rcd_len+= a.length;
}
WORD CRelView::GetHeadLength()
{
return (2*sizeof(BYTE)+2*sizeof(WORD)+sizeof(int)
+4*sizeof(UINT)+name_length+sizeof(PDB));
}
/***********************************************************************
/* BYTE exist;
/* WORD length;
/* BYTE name_length;
/* CString name;
/* UINT RelNo1;//所属关系号
/* UINT RelNo2;
/* int time;//时间戳
/* UINT DataFileNo;
/* PDB db_addr;
/* UINT rcd_len;//辅助
/* WORD attr_num;
/************************************************************************
/* CAttribute *at;
以上写入文件*************************************************************/
void CRelView::WriteBack()
{
WORD i;
CString filename("");
BYTE exist=1;
UINT offset=UINT(db_addr&0xFFFFFFFF);
UINT fileno=UINT(db_addr>>32);
filename.Format("D:\\DB\\%d.vscm",fileno);
CViewSchemaFile vscmf(LPCTSTR(filename),CFile::modeReadWrite);
vscmf.Seek(offset,CFile::begin);
vscmf.Write(&exist,sizeof(BYTE));
vscmf.Write(&length,sizeof(WORD));
vscmf.Write(&name_length,sizeof(BYTE));
vscmf.Write(LPCTSTR(name),name_length);
vscmf.Write(&RelNo1,sizeof(UINT));
vscmf.Write(&RelNo2,sizeof(UINT));
vscmf.Write(&time,sizeof(int));
vscmf.Write(&DataFileNo,sizeof(UINT));
vscmf.Write(&db_addr,sizeof(PDB));
vscmf.Write(&rcd_len,sizeof(UINT));
vscmf.Write(&attr_num,sizeof(WORD));
//写CAttribute
for(i=1;i<=attr_num;i++)
{
vscmf.Write(&at[i].name_length,sizeof(BYTE));
vscmf.Write(LPCTSTR(at[i].name),at[i].name_length);
vscmf.Write(&at[i].type,sizeof(BYTE));
vscmf.Write(&at[i].idx,sizeof(BYTE));
vscmf.Write(&at[i].unq,sizeof(BYTE));
vscmf.Write(&at[i].rf_relationship,sizeof(UINT));
vscmf.Write(&at[i].rf_Attribute,sizeof(WORD));///!!!!!!!!!!!!!!!!
vscmf.Write(&at[i].length,sizeof(WORD));
vscmf.Write(&at[i].IndexMainFile,sizeof(UINT));
vscmf.Write(&at[i].offset,sizeof(UINT));
}
}
CRelView::~CRelView()
{
delete []at;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -