📄 show.cpp
字号:
/******************************************************************
** 文件名: Show.cpp
** Copyright (c) 2001-2002 计算机99F MiniSQL开发小组其一
** 创建人: 王淮
** 日 期: 2001-12_10
** 修改人: 王淮
** 日 期: 2002-01-07
** 描 述: 定义了MiniSQL Intepretor模块中需要对磁盘文件操作的类和结构
** 版 本: 1.00
******************************************************************/
#include"show.h"
#include"iostream"
#include <afx.h>
#include <stdlib.h>
#include<direct.h>
extern char CurLocation[256]; //<---存有当前正在使用的表的相对路径,
// 如"../data/db1/"下存有book这张表
extern char CurRelationName[33]; //<---存当前表的表名
extern char CurDB[33];
void ShowTable()
{
CFileFind finder;
int iRowN = 0;
char loc[256];
CString Dbn(CurDB);
int iNameLen = 0,iTemp = 0;
std::cout<<'\n';
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
std::cout<<"| Tables in ";
std::cout << (LPCTSTR) Dbn;
int strNum = Dbn.GetLength();
for(iTemp = 19 - iNameLen-strNum;iTemp != 0;iTemp--)
std::cout<<' ';
std::cout <<"|"<<'\n';
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
strcpy(loc,CurLocation);
strcat(loc,"*.dbf");
int bWorking = finder.FindFile(loc);
while(bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
iRowN++;
CString str = finder.GetFileTitle();
//打出|--------------|的效果
iNameLen = str.GetLength();
std::cout <<"| "<< (LPCTSTR) str;
for(iTemp = 29 - iNameLen;iTemp != 0;iTemp--)
std::cout<<' ';
std::cout <<"|"<<'\n';
}
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
std::cout<<iRowN<<" rows in set!";
finder.Close();
}
void ShowDB()
{
/*产生如下的效果
+-------------+
| Database |
+-------------+
| 007 |
| SnowEagle |
| appletree |
+-------------+
*/
CFileFind finder;
int iRowN = 0;
int iNameLen = 0,iTemp = 0;
std::cout<<"These are all the databases !\n";
int bWorking = finder.FindFile("..\\Data\\*.*");
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
std::cout<<"| Database |"<<'\n';
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
while(bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
{
iRowN++;
CString str = finder.GetFileTitle();
iNameLen = str.GetLength();
std::cout <<"| "<< (LPCTSTR) str;
for(iTemp = 29 - iNameLen;iTemp != 0;iTemp--)
std::cout<<' ';
std::cout <<"|"<<'\n';
}
}
std::cout<<"+------------------------------+"<<'\n';//<---计32个字符
std::cout<<iRowN<<" rows in set!";
finder.Close();
}
int CheckDB(char* pDb)
{
CFileFind finder;
char loc[256];
strcpy(loc,"..\\Data\\");
strcat(loc,pDb);
int bWorking = finder.FindFile(loc);
int iNameLen = 0,iTemp = 0;
return bWorking;
}
int CheckTB(char* pTb) //<---检查tb是否存在
{
CFileFind finder;
char loc[256];
strcpy(loc,"..\\Data\\");
strcat(loc,CurDB);
strcat(loc,"\\");
strcat(loc, pTb); //<---该目录下所有的文件
strcat(loc , ".idx"); //<---该目录下所有的文件
int bWorking = finder.FindFile(loc);
int iNameLen = 0,iTemp = 0;
return bWorking;
}
void DelDB(char* pDb)
{
char loc[256];
char locfile[256];
CFileFind finder;
strcpy(locfile,pDb); //<---所要删除的目录的路径
strcpy(loc,pDb); //<---所要删除的目录的路径
strcat(locfile , "\\*.*"); //<---该目录下所有的文件
int bWorking = finder.FindFile(locfile);
while(bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
{
CString str = finder.GetFilePath();
CFile::Remove( str );
}
}
finder.Close();
//删除空目录--->
if( _rmdir( loc ) == 0 )
std::cout<<"Directory "<<loc<<" was successfully removed\n";
else
std::cout<<"Problem removing database"<<loc<<"\n";
ResetDBinfo(); //<---删除数据库之后将全局路径重新设置
}
void ResetDBinfo()
{
strcpy(CurLocation,"..\\data\\");
strcpy(CurRelationName,"");
strcpy(CurDB,"");
}
void DelTB(char* pTb)
{ char loc[256];
char locfile[256];
CFileFind finder;
strcpy(locfile,pTb); //<---locfile为所要删除的table的目录
strcpy(loc,locfile); //<---locfile为所要删除的table的目录
strcat(locfile , ".idx"); //<---该目录下所有的文件
int bWorking = finder.FindFile(locfile);
while(bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
{
CString str = finder.GetFilePath();
CFile::Remove( str );
}
}
finder.Close();
strcat(loc , ".dbf"); //<---该目录下所有的文件
bWorking = finder.FindFile(loc);
while(bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
{
CString str = finder.GetFilePath();
CFile::Remove( str );
}
}
finder.Close();
}
void CreateDB(char* pDb)
{
char loc[256]; //<---所要创建的目录的路径
CFileFind finder;
strcpy(loc,"..\\Data\\");
strcat(loc,pDb);
//建目录--->
if( _mkdir( loc ) == 0 )
std::cout<<"database "<<pDb<<" was successfully created\n";
else
std::cout<<"Problem creating database "<<pDb<<"\n";
finder.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -