|
C++ Builder 초보입니다.
현재 개발하고 있는 애플리케이션내에서 화면으로 조회하는 모든 데이타는 CSV File로 저장할
수 있습니다.
그런데...데이타 건수가 많아지면 Performance에 문제가 생기며,
또하나 새로운 문제는 엑셀에서는 데이타가 4-5만건(?)이상일 때는 불러들일 수 없는 줄로 알고
있습니다.
현재 데이타가 만건이 넘으면 Application이 응답이 없는 중대한 문제가 있구요.
고수님들의 노하우를 듣고 싶습니다.
첫째, 데이타를 쪼개어서 각기 연속된 파일로 저장하는 방법과
둘째, DBGrid의 각 셀마다 구분자','를 주게되는데, 이로인해 발생되는 Performance문제...를
해결할 수 있는가...
고수님들은 이런 경험이 없으신지요?
여기저기 이에 관한 정보를 찾고자 검색을 했지만 찾을 수가 없습니다.
도와주시겠습니까?
참고로...제 Source를 보여드리겠습니다.
void __fastcall TMainForm::CommaSeparatedFile()
{
/*
Helper function to parse the current form's data into
a CSV format file
*/
TForm* TheForm=ActiveMDIChild;
if (!TheForm) return;
SaveDialog->FileName=TheForm->Caption;
SaveDialog->Filter = "CSV File (*.csv)|*.csv";
String fName = SaveDialog->FileName;
fName += ".csv";
bool bMore=true;
while (bMore)
{
if (!SaveDialog->Execute()) return;
if (FileExists(fName))
{
int nResponse=MessageDlg("Overwrite the Existing file?", mtWarning, TMsgDlgButtons() << mbYes << mbNo << mbCancel, 0);
if (mrYes==nResponse)
bMore=false;
else if (mrCancel==nResponse)
return;
} else bMore=false;
}
TQuery *pqDisplay=GetQueryForTheForm(TheForm);
TDBGrid *pdbgDisplay=NULL;
for (int i=0; pdbgDisplay==NULL && i<TheForm->ControlCount; i++)
if (TheForm->Controls[i]->Name=="dbgDisplay")
pdbgDisplay=(TDBGrid*) TheForm->Controls[i];
if (pdbgDisplay==NULL || pqDisplay==NULL)
return;
int nFileHandle=FileCreate(fName);
if (nFileHandle==-1) return;
TCursor oldCursor=Screen->Cursor;
Screen->Cursor=crHourGlass; // Show hourglass cursor
String str1="";
for (int i=0; i<pqDisplay->FieldCount-1; i++)
str1+=pdbgDisplay->Columns[0].Items[i]->Title->Caption + ",";
str1+="\r\n";
// Write out the number of rows and columns in the grid.
FileWrite(nFileHandle, (char*) str1.c_str(), str1.Length());
DWORD dw1=GetTickCount();
TWindowState wsOldWindowState=TheForm->WindowState;
//This fixes the RecordCount = -1 problem
String sSQL = pqDisplay->SQL->Text;
sSQL = strstr(sSQL.c_str(), " FROM ");
if (sSQL == NULL)
sSQL = strstr(sSQL.c_str(), " from ");
sSQL = "select COUNT(*) as COUNT " + sSQL;
qUpdate->SQL->SetText(sSQL.c_str());
qUpdate->Open();
String strCount=
qUpdate->FieldByName("COUNT")->AsString;
int currCount = StrToInt(strCount);
//if (pqDisplay->RecordCount>100)
if (currCount>100)
{
TheForm->WindowState=wsMinimized;
pdbgDisplay->Visible=false;
}
pqDisplay->First();
//This fixes the RecordCount = -1 problem
//for (int i=0; i<pqDisplay->RecordCount; i++)
int i=0;
while (!pqDisplay->Eof)
{
str1="";
String str2="";
for(int j = 1+1; j < pqDisplay->FieldCount; j++)
{
str2=pqDisplay->Fields->Fields[j]->AsString;
if (0!=str2.Pos(",") && 0!=str2.Pos("\""))
{
String str3="";
for (int i=1; i<str2.Length(); i++)
{
if (str2[i]=='\"')
str3+='\"';
str3+=str2[i];
}
str2=str3;
}
if (0!=str2.Pos(","))
str1+="\"";
str1+=str2;
if (0!=str2.Pos(","))
str1+="\"";
str1+=",";
}
str1+="\r\n";
str2="";
str2.sprintf("Processing: %d/%d", i+1, currCount);
StatusLine->Panels->Items[0]->Text =str2;
FileWrite(nFileHandle,
(char*) str1.c_str(),
str1.Length());
// Write out the number of rows and columns in the grid.
pqDisplay->Next();
i++;
}
pqDisplay->First();
StatusLine->Panels->Items[0]->Text =GetTickCount()-dw1;
pdbgDisplay->Visible=true;
TheForm->WindowState=wsOldWindowState;
FileClose(nFileHandle);
Screen->Cursor=oldCursor; // always restore the cursor
MessageDlg("Done, Results in the File: " + fName, mtInformation, TMsgDlgButtons() << mbOK, 0);
}
|