www.pudn.com > 使用ADO执行存储过程.zip > ByteImport.cpp
#include#include "ByteImport.h" ByteImport::ByteImport(char *pcFile,char *pcDelimiter) { m_bIsopen = false; try { f.open(pcFile,ios::nocreate ); } catch(CException e) { TCHAR szCause[255]; e.GetErrorMessage(szCause, 255); AfxMessageBox(_T(szCause)); return; } m_bIsopen = (f.is_open()==1? true:false) ; ByteImport::pcDelimiter = pcDelimiter; iValidRecords = iInvalidRecords = 0; ttStop = ttStart = (time_t) 0; } ByteImport::~ByteImport() { f.close(); } int ByteImport::isNumeric(char *pcBuffer) { for (int ii=0; pcBuffer[ii]; ii++) if ( ! isdigit(pcBuffer[ii]) ) return 0; return 1; } time_t ByteImport::ElapsedTime() { static char caBuffer[256]; time_t ttEnd = ttStop; if ( (time_t) 0 == ttEnd ) time(&ttEnd); return ttEnd - ttStart; } void ByteImport::parse() { iBufferStatus = Invalid; pcDate = strtok(caBuffer,"\t"); if ( NULL == pcDate ) return; pcURL = strtok(NULL,"\t"); if ( NULL == pcURL ) return; pcTop = strtok(NULL,"\t"); if ( NULL == pcTop ) return; pcQueryString = strtok(NULL,"\t"); if ( NULL == pcQueryString ) return; pcBytes = strtok(NULL,"\t"); if ( NULL == pcBytes || (! isNumeric(pcBytes)) ) return; iBytes = atoi(pcBytes); pcRequests = strtok(NULL,"\t"); if ( NULL == pcRequests || (! isNumeric(pcRequests)) ) return; iRequests = atoi(pcRequests); iBufferStatus = Valid; } int ByteImport::next() { if ( ! ttStart ) time(&ttStart); if ( f.getline(caBuffer,sizeof(caBuffer)) ) { parse(); if ( isValidRecord() ) { strcpy(pcSQL,"execute sp_AddAccountingInfo 30,'"); strcat(pcSQL,pcDate); strcat(pcSQL,"','"); strcat(pcSQL,pcURL); strcat(pcSQL,"','"); strcat(pcSQL,pcTop); strcat(pcSQL,"',"); strcat(pcSQL,pcBytes); strcat(pcSQL,","); strcat(pcSQL,pcRequests); ++iValidRecords; } else { ++iInvalidRecords; } return 1; } else { time(&ttStop); return 0; } }