📄 update_index.cpp
字号:
#include "min.h"
void sql::update_index( Table* table)
{
try
{
int number = table->num;
Col* col;
col = table->collist;
int cth = -1;
while ( col->next )
{
col = col->next;
cth ++;
/*--------------ch-----------*/
for ( int mm=0; mm<subsbf; mm++ )
subbuf[mm] = '\0';
/*--------------ch-----------*/
if ( col->indexname != "" )
{
istrstream inb( buf[page], sbf );
fileload = table->name+ "_" + col->indexname + ".idx";
inb.ignore(1000,'\n');
int thn;
int head = 0 ;
ostrstream out( subbuf,subsbf );
if ( col->type=='#' ) //属性为int
{
int idx = 0;
int num=number;
while (num-- )
{
for ( ; head<=strlen(buf[page]) ; head++)
if( buf[page][head]=='\n' )
break;
head++;
for ( thn=cth; thn; thn-- )
inb.ignore(1000,'\t' );
string c_idx;
inb >> c_idx;
while ( c_idx.at(0)=='*' )
{
inb.ignore(1000,'\n');
for ( thn=cth; thn; thn-- )
inb.ignore(1000,'\t' );
inb >> c_idx;
}
for ( int p=0; p<c_idx.size(); p++ )
idx = idx*10 + c_idx.at(p) - '0';
out << idx << ' ' << head << '\t';
idx = 0;
inb.ignore(1000,'\n');
}
}
else//属性为char;
{
char ind[256];
int num=number;
while ( num-- )
{
for ( ; head <= strlen(buf[page]) ; head++)
if( buf[page][head]=='\n' )
break;
head++;
for ( thn=cth; thn; thn-- )
inb.ignore(1000,'\t' );
inb >> ind;
while ( ind[0]=='*' )
{
inb.ignore(1000,'\n');
for ( thn=cth; thn; thn-- )
inb.ignore(1000,'\t' );
/*---------ch---------*/ inb >> ind;
}
out << ind << ' ' << head << '\t';
for ( int k=0; k<256; k++ )
ind[k] = '\0';
inb.ignore(1000,'\n');
}
}
out << '\0';
ofstream file;
file.open( fileload.c_str(),ios::trunc);
if( !file )
throw 5;
file.write(subbuf, strlen(subbuf));
file.close();
}
}
}
catch( int i )
{
switch (i)
{
case 5: cout << "无法更新索引文件" << endl;
break;
}
}
catch( bool ex )
{
if(ex)
cout << "索引已存在" << endl;
else
cout << "表名不存在!" << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -