저장 하는 코드를 보면서 간단하게 이해를 해 보겠습니다.


생략...


FILE *fp, *_temp_fp;


// Insert Table

if ((fp = fopen(tablefileName, "a+b")) == NULL)

{

printf("Could not open file.\n");

fclose(fp);

exit(0);

}


table_info* table_info;

table_info = get_table_info(tablename);


생략...


else // General Insertion

{

records++;


for (int i = 0; i < value_num; i++)

{

if (table_info->col.at(i).type == 0)

{

int value_of_int = atoi(value[i]);

fwrite(&value_of_int, sizeof(int), 1, fp);

}

else

{

char value_of_char[100] = "\0";

strcpy(value_of_char, value[i]);

fwrite(&value_of_char, sizeof(char), table_info->col.at(i).size, fp);

}

}

if (update_records(tablename, 0) == false) printf("Could not update schema.\n");

}


파일 오픈(Binary) 후 type 에 맞게 fwrite 로 저장합니다. type 에 따라 저장방식이 조금 다를 뿐 구조는 똑같습니다.

조금 자세하게 들여다 보려 했으나, 저장하는 부분만 보여져도 충분할것 같아 다른 옵션(?) 코드들은 전부 삭제했습니다.


 

'Computer Science > DB' 카테고리의 다른 글

C++ <vector>, Database 만들기  (0) 2012.05.12
ORACLE - 테이블 join 이 잘안돼...  (0) 2009.09.16
ORACLE - SYSDATE 로 시간구하기  (6) 2009.05.20
ORACLE - 문자열 추출 (substr)  (0) 2009.03.03
ORACLE DUMP()  (0) 2008.10.24
페이스북 댓글
티스토리 댓글

+ Recent posts