数据库课程设计说明书 创建和修改表的定义.doc_第1页
数据库课程设计说明书 创建和修改表的定义.doc_第2页
数据库课程设计说明书 创建和修改表的定义.doc_第3页
数据库课程设计说明书 创建和修改表的定义.doc_第4页
数据库课程设计说明书 创建和修改表的定义.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

课程设计说明书设计题目: 创建和修改表的定义 _专 业: 计算机科学与技术 班 级: _设 计 人: _山东科技大学2012年 06月 20 日课程设计任务书学院 信息科学与工程学院 专业 计算机科学与技术 班级 姓名一、 课程设计题目:(1) 创建和修改表的定义 二、 课程设计主要参考资料:(1) 数据库系统概论 (2) c语言程序设计 (3) 数据结构 三、 课程设计应解决的主要问题:1.选择一种高级语言实现一个简单的dbms主要功能: 实现:create table (, ) 实现:alter table add dropmodify 要求:(1)设计实现表的物理存储结构;(2)语句以命令行和图形化界面两种形式实现;(3)提交课程设计报告。四、 课程设计相关附件(如:图纸、软件等):(1) (2) (3) 五、 任务发出日期: 课程设计完成日期: 指导教师签字: 系主任签字: 指导教师对课程设计的评语指导教师签字: 2012年 月 日山东科技大学学生课程设计一、 设计要求:(1)设计实现表的物理存储结构;(2)语句以命令行和图形化界面两种形式实现;(3)提交课程设计报告。二、 需求分析:1.选择一种高级语言实现一个简单的dbms 设计实现表的物理存储结构;语句以命令行和图形化界面两种形式实现;三、 设计思想:(1) 由命令行输入sql语句, 通过对语句进行语法分析,分离关键字,语句以分号作为结束符号; (2) 以 *.txt 文件存放建立的表,一张表对应一个 *.txt 文件;(3) 用户可直接输入create table 语句和alter语句, 程序自动解析和查错, output语句输出表的相关信息。四、 主要源程序:/源程序在codeblocks 10.05下运行通过#include#include#include#include#include#include#include#includeusing namespace std;#define max 1000#define n 100/表中每个域的结构:struct field char namen; char typen; int len; char conditionn; field() len = 0; name0 = type0 = condition0 = 0; ;/读入的语句字符串char sqlmax,sqltmpmax;/将输入的大写字母转化为小写字母void tolower(char *s) int len = strlen(s); for(int i = 0; i = a & si = z) si += 32; /读入sql语句,并进行格式化分离单词, 以分号结束, esc退出整个程序int read() char c; int i; for(i = 0; c = getch(); i+) if(c = ;) break; if(c = 27) exit(0); if(c = 8) i -= 2; if(i -1) i = -1; system(cls); printf(:nplease input the sql sentence:nn); for(int j = 0; j tmp; if( 0 != strcmp(tmp,create) error = true; printf(nthe word create maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; int len = strlen(table_name); strcat(table_name, .txt); if(access(table_name, 0) = 0) printf(the table already exist! over it?y/nn); char c; c = getchar(); if(c = n) return false; else remove(table_name); while(true) field field; ss tmp; if(tmp0 = ,) add(field, table_name); continue; if(strcmp(tmp, ;) = 0) break; strcpy(, tmp); if(!(ss tmp) break; if(tmp0 = ,) add(field, table_name); continue; bool flg = false; for(int i = 0; i tmp; if(tmp0 = ,) add(field, table_name); continue; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(tmp0 = ,) add(field, table_name); continue; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); break; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); add(field, table_name); return (!error);/修改表函数bool alter() char tmpn; char table_namen; bool error = false; char type610= char,int,float,double,time,date; stringstream ss(sql); ss tmp; if( 0 != strcmp(tmp,alter) error = true; printf(nthe word alter maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; strcat(table_name, .txt); if(access(table_name, 0) = -1) printf(the table do not exist!n); return false; ss tmp; if(strcmp(tmp, add) = 0) ss tmp; field field; strcpy(, tmp); ss tmp; bool flg = false; for(int i = 0; i tmp; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); return false; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); file *fp = fopen(table_name, a); fwrite(&field, sizeof(field), 1, fp); fclose(fp); else if(strcmp(tmp, drop) = 0) ss tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 != strcmp(st,key) error = true; printf(the word key maybe error!n); return false; else strcat(tmp, key); field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); printf(%dn, len); for(int i = 0; i len; +i) if(strcmp(fieldi.condition, tmp) = 0) fieldi.condition0 = 0; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i tmp; ss tmp; char stn; int sum = 0; ss st; bool flg = false; for(int i = 0; i t; bool flg = true; int len = strlen(t); for(int i = 0; i 58 | ti 48) flg = false; break; else sum = sum * 10 + ti - 0; if(!flg) error = true; printf(nthe length of the type maybe error!n); return false; field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); for(int i = 0; i len; +i) if(strcmp(, tmp) = 0) strcpy(fieldi.type, st); fieldi.len = sum; break; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i len; +i) fp = fopen(table_name, a); fwrite(&fieldi, sizeof(field), 1, fp); fclose(fp); return (!error);/输出表的相关信息void output(char *s) if(access(s, 0) = -1) printf(the table do not exist!n); return ; printf(*n); printf( name type length conditionn); printf(*n); file *fp = fopen(s, r); field field; while(fread(&field, sizeof(field), 1, fp) != 0) printf(%10s, ); if(field.type0 != 0) printf( %10s, field.type); else printf( ); if(field.len != 0) printf( %10d, field.len); else printf( ); if(field.condition0 != 0) printf( %10s, field.condition); else printf( ); puts(); fclose(fp); printf(*n);/程序主函数,循环读入, 直到读到escint main() while(true) printf(:nplease input the sql sentence:nn); read(); stringstream ss(sql); char sn; ss s; if(strcmp(s, create) = 0) if(create() printf(create successful!n); else printf(create failed!n); else if(strcmp(alter, s) = 0) if(alter() printf(alter successful!n); else printf(alter failedn); else if(strcmp(output, s) = 0) ss s; strcat(s, .txt); output(s); ret

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论