ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:18.48KB ,
资源ID:22770247      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/22770247.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(ubase 第5部分答案Word下载.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

ubase 第5部分答案Word下载.docx

1、 Doing QU_Select endl; Status status; AttrDesc *attrs,attrDesc; int i,offset=0; attrs=new AttrDesc projCnt; /属性的转换 for(i=0;igetInfo(projNamesi.relName,projNamesi.attrName,attrsi); if(status!=OK) return status; offset+=attrsi.attrLen; if(attr-relName!=NULL) attrCat-getInfo(attr-relName,attr-attrName,

2、attrDesc); else strcpy(attrDesc.relName,projNames0.relName); attrDesc.attrOffset=0; attrDesc.attrLen=0; attrDesc.attrType=int(STRING); attrValue=NULL; /调用ScanSelect() 查找 if(status=ScanSelect(result,projCnt,attrs,&attrDesc,op,attrValue,offset)! delete attrs; return OK; result, const int projCnt, cons

3、t AttrDesc projNames,const AttrDesc *attrDesc, const Operator op, const char *filter, const int reclen)Doing HeapFileScan Selection using ScanSelect() HeapFileScan *hfs; InsertFileScan *ifs; char *record; RID rid1,rid2; Record rec1,rec2; hfs=new HeapFileScan(attrDesc-relName,status); /对文件扫描(原表) if(a

4、ttrDesc-attrType=INTEGER) int intv; intv=atoi(filter); /atoi()将char* 转换成整型 hfs-startScan(attrDesc-attrOffset,attrDesc-attrLen,INTEGER,(char*)(&intv),op); attrType=STRING) hfs-attrLen,STRING,filter,op);attrType=FLOAT) float floatv; floatv=(float)atof(filter); /atof()将char* 转换成浮点型attrLen,FLOAT,(char*)

5、(&floatv),op); /插入result表 ifs=new InsertFileScan(result,status); /创建插入临时表的指针 while(status=hfs-scanNext(rid1)!=FILEEOF) hfs-getRecord(rec1); offset=0; record=new charreclen; /暂存临时表的记录 for(i=0;i+) memcpy(&recordoffset,(char*)rec1.data+projNamesi.attrOffset,projNamesi.attrLen); offset+=projNamesi.attrL

6、en; rec2.data=record; rec2.length=reclen; if(status=ifs-insertRecord(rec2,rid2)! delete record; /delete record; delete hfs; delete ifs;2、insert.C/ * Inserts a record into the specified relation. * Returns: * OK on success * an error code otherwise */*将给定的数据作为记录插入关系,属性的值由参数attrList提供,用户提供的字段和值的列表可以为任

7、意顺序,插入前你必须按AttrCat中的顺序对其重新排序,一可以用memcpy函数将他们按合适的偏移量拷贝到一个临时数组,然后调用insertRecord方法。如果属性值不全,禁止插入,因为UBase尚未实现NULL。const Status QU_Insert(const string & relation, const int attrCnt, const attrInfo attrList) Status status; InsertFileScan * ifs; Record rec; RID rid; RelDesc rd; AttrDesc ad; int i; relCat-ge

8、tInfo(relation,rd); /得到属性个数 if(rd.attrCnt!=attrCnt) printf(Error: attribute number mismatchn); rec.length=0;attrCnt;getInfo(attrListi.relName,attrListi.attrName,ad); rec.length+=ad.attrLen; record=new char rec.length; /暂时存放记录 if(status=attrCat-getInfo(attrListi.relName,attrListi.attrName,ad)!=OK) pr

9、intf( return status;recordad.attrOffset,(char*)attrListi.attrValue,ad.attrLen); rec.data=record; ifs=new InsertFileScan(relation,status);insertRecord(rec,rid)!=OK)return status; delete record; printf(n1 record inserted!n3、select.C result, const int projCnt, const AttrDesc projNames,const AttrDesc *a

10、ttrDesc, const Operator op, const char *filter, const int reclen);/* Selects records from the specified relation. /* 选择是通过带过滤条件的堆文件扫描(HeapFileScan)实现的。投影列表由参数projCnt和projNames指定,在每一条记录加入 结果表时就要完成投影处理。过滤条件中的常量总是通过attrValue以字符形式出现,你可以用atoi() 函数将char*转换为整型,用atof()将char*转换为符点型, 如果attr参数为 NULL,意味着执行无条件的扫

11、描。 result, const int projCnt, const attrInfo projNames,const attrInfo *attr, const Operator op, const char *attrValue) attrCat- strcpy(attrDesc.relName,projNames0.relName); const AttrDesc *attrDesc, const Operator op, const char *filter, const int reclen) if(attrDesc.attrType=INTEGER) /atoi()将char*

12、转换成整型 if(attrDesc.attrType=STRING) if(attrDesc.attrType=FLOAT) /atof()将char* 转换成浮点型 4、Update.C/* Deletes records from a specified relation.const Status QU_Update(const string & relation, const int attrCnt, const attrInfo attrList, const string & attrName, const Operator op, const Datatype type, cons

13、t char *attrValue) RelDesc record1; AttrDesc record2; AttrDesc *attrs ; int relationattrCnt; int attrCntlen=0; char *updatedata ; int intval,intval1 ; float flval,flval1 ; Record rec ; HeapFileScan *hfs ; int recnum = 0 ; / check the valid of relation; status = relCat-getInfo( relation,record1) ; if

14、 (status != OK) return status ; / check the valiad of attrlist;在属性列表中找到相应的字段 for( int i = 0; i getInfo( relation, attrListi.attrName, record2) != OK) return status ; / count attrName of the relation if (attrCat-getRelInfo( relation, relationattrCnt, attrs)!=OK) return status ; if (status = attrCat-g

15、etInfo( relation, attrName, record2) != OK) delete attrs ; for ( int i = 0; relationattrCnt; i+) attrCntlen = attrCntlen + attrsi.attrLen ; updatedata = new charattrCntlen ; for (int i = 0; attrCntlen ; i+) updatedatai = -1; hfs = new HeapFileScan( relation, status) ; delete updatedata ; if (type =

16、INTEGER) intval = atoi(attrValue) ;startScan( record2.attrOffset, record2.attrLen,(Datatype)record2.attrType, (char *)&intval, op) ; if (type = FLOAT) flval =(float)atof(attrValue) ;startScan( record2.attrOffset, record2.attrLen, (Datatype)record2.attrType, (char *)&flval, op) ; if (type = STRING)st

17、artScan( record2.attrOffset, record2.attrLen,(Datatype)record2.attrType, attrValue, op) ; /扫描记录并更新记录的值 while(hfs-scanNext(rid)!= FILEEOF)getRecord(rec) ; memcpy( updatedata, rec.data, rec.length) ; for (int j = 0; j j+) if (strcmp(attrsi.attrName, attrListj.attrName) = 0) if (attrsi.attrType = INTEGER) intval1 = atoi(char *)attrListj.attrValue) ; memcpy( updatedata + attrsi.attrOffset, &intval1, attrsi.attrLen) ; if (attrsi.attrType = FLOAT) flval1 = (float)atof(char *)attrListj.attrValue) ;flval1, attrsi.attrLen) ; if (attrsi.attrType = STRING) memcpy( updatedata + a

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1