📄 attribute.cpp
字号:
// Attribute.cpp: implementation of the CAttribute class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Database.h"
#include "Attribute.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAttribute::CAttribute()
{
tree=NULL;
}
CAttribute::CAttribute(CString s,CString t,UINT le,bool unique
,bool pk,bool nll,UINT rr,WORD ra)
{
idx=0;
unq=unique;
ispk=BYTE(pk);///////////////////////////////////////9.16
can_null=BYTE(nll);///////////////////////////////////9.16
tree=NULL;
IndexMainFile=0;
offset=0;
if(s.GetLength()>10)
{
name=s.Left(10);
name_length=(10+1);
}
else
{
name=s;
name_length=(s.GetLength()+1);
}
rf_relationship=rr;
rf_Attribute=ra;
if(!t.CompareNoCase("int"))
{
type=INT_TYPE;
length=4;
}
else if(!t.CompareNoCase("float"))
{
type=FLOAT_TYPE;
length=4;
}
else if(!t.CompareNoCase("char"))
{
type=CHAR_TYPE;
length=le;
}
else if(!t.CompareNoCase("varchar"))
{
type=VARCHAR_TYPE;
length=le;
}
else if(!t.CompareNoCase("date"))
{
type=DATE_TYPE;
length=11;
}
else if(!t.CompareNoCase("time"))
{
type=TIME_TYPE;
length=9;
}
//else 出错
}
/*CAttribute::CAttribute(BYTE nl,CString s,BYTE t,UINT le,UINT rr,UINT ra)
{
tree=NULL;
if(nl<=10)
{
name=s;
name_length=nl;
}
else
{
name=s.Left(10);
name_length=(10+1);
}
rf_relationship=rr;
rf_Attribute=ra;
type=t;
length=le;
}*/
CAttribute::~CAttribute()
{
if(tree)
{
ASSERT(idx==1);
delete tree;
}
}
void CAttribute::SetIndex(UINT IdxFlNo)
{
this->IndexMainFile=IdxFlNo;
}
WORD CAttribute::GetLength()//得到字段信息的长度
{
return (6*sizeof(BYTE)+2*sizeof(WORD)+3*sizeof(UINT)+name_length);
}
CAttribute & CAttribute::operator =(const CAttribute &A)
{
idx=A.idx;
IndexMainFile=A.IndexMainFile;
length=A.length;
name=A.name;
name_length=A.name_length;
offset=A.offset;
rf_Attribute=A.rf_Attribute;
rf_relationship=A.rf_relationship;
type=A.type;
unq=A.unq;
ispk=A.ispk;
can_null=A.can_null;
if(A.tree)
{
delete(tree);
tree=new CBplusTree;
*tree=*(A.tree);
}
else
tree=NULL;
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -