bool KS_YKT_Clt::HasMoreRecord() { if(record_count_ <= 0) { if(!GetRecordCount(handler_,&record_count_)) { return false; } if(record_count_ <= 0) return false; } if(resp_read_row_ <= record_count_ && resp_row_ < resp_read_row_ ) { resp_read_row_ = resp_row_ + 1; return true; } else if(!HaveNextPack(handler_)) { return false; } else if(!SendNextRequest()) { return false; } else if(!GetRecordCount(handler_,&record_count_)) { return false; } else if(resp_read_row_ <= record_count_ && resp_row_ < resp_read_row_) { resp_read_row_ = resp_row_ + 1; return true; } else return false; }
/* µ±nStale=1ʱ ×Ö·û×ֶηµ»Ø×Ö·û×ֶΠµ±nStale=2ʱ ÊýÖµ×ֶηµ»Ø×Ö·û×ֶΠµ±nStale=3ʱ ÈÕÆÚ×ֶηµ»Ø×Ö·û×ֶΠ*/ CString RxADO::FieldToOtherField(CString cDataBaseName, CString cFieldName, CString cValue, CString cReturnField, int nStale=1) { CString sSQL,sRTValue; _RecordsetPtr Fieldrst; Fieldrst.CreateInstance(__uuidof(Recordset)); Fieldrst.CreateInstance(__uuidof(Recordset)); if(nStale==1) //×Ö·û×ֶηµ»Ø×Ö·û×ֶΠsSQL.Format("SELECT * FROM %s WHERE %s='%s'",cDataBaseName,cFieldName,cValue); if(nStale==2)//ÊýÖµ×ֶηµ»Ø×Ö·û×ֶΠsSQL.Format("SELECT * FROM %s WHERE %s=%s",cDataBaseName,cFieldName,cValue); if(nStale==3)//ÈÕÆÚ×ֶηµ»Ø×Ö·û×ֶΠsSQL.Format("SELECT * FROM %s WHERE %s=#%s#",cDataBaseName,cFieldName,cValue); try{ Fieldrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText); } catch(_com_error&e) { GetADOErrors(e); return ""; } if(GetRecordCount(Fieldrst)<=0) return ""; _variant_t vValue=Fieldrst->GetCollect((_bstr_t)cReturnField); if(vValue.vt==VT_EMPTY) return ""; sRTValue=(char*)(_bstr_t)vValue; sRTValue.TrimRight(); sRTValue.TrimLeft(); return sRTValue; }
bool DataManager::HasRecord(std::wstring recordType) { if ( L"" == GetCurrentDevice() ) return true; return GetRecordCount(recordType) != 0; }
/********************************************************************* * SaveToFile() * * 保存所有信息到文件 * * 说明: *********************************************************************/ void SEU_QQwry::SaveToFile(CString Name) { FILE *out; CString str1,str2; out=fopen(Name+".txt","wb"); int ioff; m_buf.Format("Total %d\r\n",GetRecordCount());//得到总记录 fwrite(m_buf,1,m_buf.GetLength(),out);//输出 for(m_i=0;m_i<GetRecordCount();m_i++) { ioff=GetStartIPInfo(m_i);//得到开始的IP信息 str1.Format("%d.%d.%d.%d",m_ipoff.b3,m_ipoff.b2,m_ipoff.b1,m_ipoff.b0);//开始IP str2.Format("%d.%d.%d.%d",m_ei.b3,m_ei.b2,m_ei.b1,m_ei.b0);//结束IP m_buf.Format("%-15s %-15s %s\r\n", str1,str2,GetCountryLocal(m_ei.bMode,ioff+4)); fwrite(m_buf,1,m_buf.GetLength(),out); } fclose(out); }
int NL_QQwry::GetIndex(CString szIP) { int index=-1; DWORD dwInputIP; DWORD dwStartIP; dwInputIP=IP2DWORD(szIP); // //利用半跳方法速度快一些 // int iT; int iB,iE; iB=0; iE=GetRecordCount()-1; iT=iE/2; while(iB<iE) { dwStartIP=GetSIP(iT); if(dwInputIP==dwStartIP) { index =iT; break; } if((iE-iB)<=1) { for(int i=iB;i<=iE;i++) { dwStartIP=GetSIP(i); if(dwStartIP<=dwInputIP && dwInputIP<=m_dwLastIP) { index=i; break; } } break; } if(dwInputIP>dwStartIP) { iB=iT; } else { iE=iT; } iT=iB+(iE-iB)/2; } return index; }
void NL_QQwry::SaveToFile() { // //在内存中操作可能速度更快一些 //利用缓存,就这样了,提高速度就自己解决了 // FILE *out; CString str1,str2; out=fopen("out.txt","wb"); int ioff; m_buf.Format("Total %d\r\n",GetRecordCount()); fwrite(m_buf,1,m_buf.GetLength(),out); for(m_i=0;m_i<GetRecordCount();m_i++) { ioff=GetStartIPInfo(m_i); str1.Format("%d.%d.%d.%d",m_ipoff.b3,m_ipoff.b2,m_ipoff.b1,m_ipoff.b0); str2.Format("%d.%d.%d.%d",m_ei.b3,m_ei.b2,m_ei.b1,m_ei.b0); m_buf.Format("%-15s %-15s %s\r\n", str1,str2,GetCountryLocal(m_ei.bMode,ioff+4)); fwrite(m_buf,1,m_buf.GetLength(),out); } fclose(out); }
vector<vector<UUID>> RecordManager::SelectRecord(uint table, uint *attributes) { vector<Record*> records; vector<uint> tables; UUID underEvaluateUUID[currentTablesCount]; // TODO // optimization can be done here, to reorder the table order for (int i=0; i<currentTablesCount; i++) { underEvaluateUUID[i] = FIRSTUUID; } bool isDone = false; while (1) { records.clear(); tables.clear(); for (int i=0; i<currentTablesCount; i++) { records.push_back(GetRecord(currentTables[i], underEvaluateUUID[i])); tables.push_back(currentTables[i]); Debug("record of table "<<currentTables[i]<<" uuid "<<underEvaluateUUID[i]-1<<" transfered"); // no carry if((++underEvaluateUUID[i] - FIRSTUUID) < GetRecordCount(currentTables[i])){ break; } // carry else{ if(i == currentTablesCount-1) isDone = true; // highest carry underEvaluateUUID[i] = FIRSTUUID; } } if(pyEvaluator.Evaluate(tables, records, tableRecordDataTypes)) { Debug("evaluation finished early"); break; } if(isDone) { Debug("evaluation finished by feeding all records"); break; } } return pyEvaluator.GetResult(); }
DWORD NL_QQwry::GetSIP(int index) { DWORD ip; BYTE b[3]; int ioff; if(!m_bOpen)return -1; if(index>GetRecordCount()-1)return -1; if(index<0)return -1; ioff=m_be.uBOff+index*7; m_file.Seek(ioff,CFile::begin); m_file.Read(&ip,4); m_file.Read(b,3); ioff=b[0]+b[1]*256+b[2]*256*256; m_file.Seek(ioff,CFile::begin); m_file.Read(&m_dwLastIP,4); return ip; }
CString CADORecordset::GetString(LPCTSTR lpCols, LPCTSTR lpRows, LPCTSTR lpNull, long numRows) { _bstr_t varOutput; _bstr_t varNull(""); _bstr_t varCols("\t"); _bstr_t varRows("\r"); if(strlen(lpCols) != 0) varCols = _bstr_t(lpCols); if(strlen(lpRows) != 0) varRows = _bstr_t(lpRows); if(numRows == 0) numRows =(long)GetRecordCount(); varOutput = m_pRecordset->GetString(adClipString, numRows, varCols, varRows, varNull); return (LPCTSTR)varOutput; }
CString NL_QQwry::Test() { /* CString str,str1,str2; int ioff = 0; m_buf.Format("Total %d\r\n",GetRecordCount()); for(m_i=0;m_i<GetRecordCount();m_i++) { ioff=GetStartIPInfo(m_i); str1.Format("%d.%d.%d.%d",m_ipoff.b3,m_ipoff.b2,m_ipoff.b1,m_ipoff.b0); str2.Format("%d.%d.%d.%d",m_ei.b3,m_ei.b2,m_ei.b1,m_ei.b0); str.Format("%-15s %-15s %s\r\n", str1,str2,GetCountryLocal(m_ei.bMode,ioff+4)); m_buf+=str; } return m_buf;*/ int ioff; CString str; m_buf.Format("Total %d\r\n",GetRecordCount()); for(m_i=0;m_i<1000;m_i++) { ioff=GetStartIPInfo(m_i); if(m_ei.bMode>=1 && m_ei.bMode<=8) { str.Format("%6d %03d.%03d.%03d.%03d " "%03d.%03d.%03d.%03d %d %06X ", m_i, m_ipoff.b3, m_ipoff.b2, m_ipoff.b1, m_ipoff.b0, m_ei.b3, m_ei.b2, m_ei.b1, m_ei.b0, m_ei.bMode, ioff); m_buf+=str; str=GetCountryLocal(m_ei.bMode,ioff+4); str+="\r\n"; } else { str.Format("%6d %03d.%03d.%03d.%03d " "%03d.%03d.%03d.%03d (%d) %06X ", m_i, m_ipoff.b3, m_ipoff.b2, m_ipoff.b1, m_ipoff.b0, m_ei.b3, m_ei.b2, m_ei.b1, m_ei.b0, m_ei.bMode, ioff); m_buf+=str; str.Format("%02X-%02X-%02X-%02X-%02X " "%02X-%02X-%02X-%02X-%02X " "%02X-%02X-%02X-%02X-%02X " "%02X-%02X-%02X-%02X-%02X\r\n", m_ei.buf[0], m_ei.buf[1], m_ei.buf[2], m_ei.buf[3], m_ei.buf[4], m_ei.buf[5], m_ei.buf[6], m_ei.buf[7], m_ei.buf[8], m_ei.buf[9], m_ei.buf[10], m_ei.buf[11], m_ei.buf[12], m_ei.buf[13], m_ei.buf[14], m_ei.buf[15], m_ei.buf[16], m_ei.buf[17], m_ei.buf[18], m_ei.buf[19]); } m_buf+=str; } return m_buf; }
CString NL_QQwry::GetCountryLocal(int index) { if(index<0 || index>GetRecordCount()-1) return "没有查到"; return GetCountryLocal(m_ei.bMode,GetStartIPInfo(index)+4); }
BOOL CEdRptDoc::GetDataFromDB() { CDatabase db; BOOL bRet = FALSE; try { if (m_szODBCLink.IsEmpty()) { ShowMessage(m_hWnd, "没有给定数据库指针,也没有指定链接字!"); return FALSE; } if (!db.OpenEx(m_szODBCLink, CDatabase::openReadOnly | CDatabase::noOdbcDialog)) { ShowMessage(m_hWnd, "无法打开数据库连接 %s", m_szODBCLink); return FALSE; } m_nRecCount = GetRecordCount(db); CRecordset rc(&db); CString szSQL = m_szSQL; CString csHeadRight = m_szHeadRight; if (m_nRecCount > (int)m_nMaxRecordNum) { CString str; str.Format(_T("共有 %d 条记录,但模版设计最大记录数为 %d,\n是否只 %d 条记录?\n" "注意:如何选否,会给数据库很大压力,甚至取消操作!"), m_nRecCount, m_nMaxRecordNum, m_nMaxRecordNum); UINT ulSelect = IDNO; if (m_hWnd) ulSelect = MessageBox(m_hWnd, str, _T("BSRpter"), MB_YESNOCANCEL); if (ulSelect == IDNO) ; else if (ulSelect == IDCANCEL) return FALSE; else // IDYES { csHeadRight.Format(_T(" %d条记录未打印"), m_nRecCount - m_nMaxRecordNum); m_nRecCount = m_nMaxRecordNum; CString csDBDrv = getDBDriver(m_szODBCLink); csDBDrv.MakeLower(); if (csDBDrv.Find("oracle") >= 0) { CString szTmp = szSQL; szTmp.MakeLower(); int nFind = szTmp.Find(" where "); if (nFind > 0) { szTmp.Format("ROWNUM <= %d AND ", m_nMaxRecordNum); szSQL.Insert(nFind + (int)_tcslen(" where "), (LPCSTR)szTmp); } else { szTmp.Format(" WHERE ROWNUM <= %d ", m_nMaxRecordNum); szSQL += szTmp; } } else if (csDBDrv.Find("mysql") >= 0) { CString szTmp; szTmp.Format(" Limit 0, %d ", m_nMaxRecordNum); szSQL += szTmp; } else { CString str; str.Format(_T("[ %s ] 数据库无法使用修改SQL的方法限制记录个数," "而打开大数据集可能会出现异常\n,是否先修改查询条件,再进行打印?") , csDBDrv); if (m_hWnd != NULL && MessageBox(m_hWnd, str,_T("EdFc"), MB_YESNO) == IDYES) return FALSE; } } } rc.Open(CRecordset::forwardOnly, szSQL); m_nFieldCount = rc.GetODBCFieldCount(); while (m_ColFmt.GetSize() > m_nFieldCount && m_nFieldCount > 1) m_ColFmt.RemoveAt(m_ColFmt.GetSize() - 1); COLFMT cf; while (m_ColFmt.GetSize() < m_nFieldCount) m_ColFmt.Add(cf); m_Grid.DeleteAllItems(); int nRowCount = m_nRecCount + (m_bFootSum ? 2 : 1); m_Grid.SetRowCount(nRowCount); m_Grid.SetColumnCount(m_nFieldCount); // set ColumName; GV_ITEM Item; Item.mask = GVIF_TEXT|GVIF_FORMAT; Item.row = 0; Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX; for (Item.col = 0; Item.col < m_nFieldCount; Item.col++) { m_Grid.SetColumnWidth(Item.col, m_ColFmt[Item.col].width); Item.szText = m_ColFmt[Item.col].name; if (m_ColFmt[Item.col].name.IsEmpty()) { CODBCFieldInfo fi; rc.GetODBCFieldInfo(Item.col, fi); Item.szText = fi.m_strName; } m_Grid.SetItem(&Item); } if (m_hWnd != NULL && m_nRecCount > 0) ::SendMessage(m_hWnd, WM_CREATEPROGRESS, m_nRecCount, 0); CDBVariant varValue; Item.mask = GVIF_TEXT|GVIF_FORMAT; Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX; for(int row = 0; row < m_nRecCount; row ++) { for (int col = 0; col < m_nFieldCount; col ++) { rc.GetFieldValue(col, varValue); Item.row = row + 1; Item.col = col; Item.szText = GetVarStr(&varValue, m_ColFmt[col].format); m_Grid.SetItem(&Item); varValue.Clear(); } if (m_hWnd != NULL) ::SendMessage(m_hWnd, WM_STEPPROGRESS, m_nRecCount, row); rc.MoveNext(); } if (m_bFootSum) GetStaticData(rc); rc.Close(); if (m_hWnd != NULL) ::SendMessage(m_hWnd, WM_DESTROYPROGRESS, 0, 0); bRet = TRUE; } catch(CException *edb) { static TCHAR lpszError[MAX_PATH]; CString csError; if (edb->GetErrorMessage(lpszError, MAX_PATH)) csError = lpszError; if (csError.GetLength() <= 0) csError = _T("无法获得数据!"); ShowMessage(m_hWnd, csError); edb->Delete(); } catch(...) { ShowMessage(m_hWnd, _T("无法获得数据!")); } return bRet; }
/* µ±nStyle=1ʱ Éú³ÉÊý×Ö±àºÅ µ±nStyle=2ʱ Éú³ÉÁ÷Ë®ÕʺŠµ±nStyle=3ʱ Éú³ÉÈÕÆÚʱ¼ä±àºÅ */ CString RxADO::AutoNumber(CString sTable, CString sFieldName, CString sCode, int nStyle) { _RecordsetPtr AutoNumberrst; CString sTempNewNumber,sNewNumber,sSQL,sMaxNumber,sOldNumber; AutoNumberrst.CreateInstance(__uuidof(Recordset)); sSQL.Format("SELECT MAX(%s) as ×î´ó±àºÅ FROM %s",sFieldName,sTable); try{ AutoNumberrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText); } catch(_com_error & e) { GetADOErrors(e); } if(nStyle==1) //Êý×Ö±àºÅ { if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("1"); else { AutoNumberrst->MoveFirst(); _variant_t vtext; vtext=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(vtext.vt==VT_EMPTY||vtext.vt==VT_NULL) { sNewNumber.Format("1"); goto end; } sMaxNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ"); sNewNumber.Format("%d",atoi(sMaxNumber)+1); } } if(nStyle==2)//Á÷Ë®ÕʺŠ{ if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("%s00000001",sCode); else { AutoNumberrst->MoveFirst(); _variant_t _bOldNumber=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(_bOldNumber.vt==VT_NULL || _bOldNumber.vt==VT_EMPTY) { sNewNumber.Format("%s00000001",sCode); goto end; } sOldNumber=(char*)(_bstr_t) _bOldNumber; sMaxNumber=sOldNumber.Mid(3); sTempNewNumber.Format("%d",atoi(sMaxNumber)+1); sNewNumber.Format("%s%s",sCode,Padl(sTempNewNumber,8,"0",1)); } } if(nStyle==3)//ÈÕÆÚʱ¼ä±àºÅ { int nYear,nDay,nMonth; CString sYear,sDay,sMonth; CTime tTime; tTime=tTime.GetCurrentTime(); nYear=tTime.GetYear(); nDay=tTime.GetDay(); nMonth=tTime.GetMonth(); sYear.Format("%d",nYear); sDay.Format("%d",nDay); sMonth.Format("%d",nMonth); sYear=sYear.Mid(2); sDay=Padl(sDay,2,"0",1); sMonth=Padl(sMonth,2,"0",1); if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); else { _variant_t bh=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(bh.vt==VT_EMPTY||bh.vt==VT_NULL) { sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); goto end; } CString sOldDate,sNewDate; AutoNumberrst->MoveFirst(); sOldNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ"); sOldDate=sOldNumber.Mid(2,6); sNewDate.Format("%s%s%s",sYear,sMonth,sDay); if(sOldDate==sNewDate) { sMaxNumber=sOldNumber.Mid(9); sTempNewNumber.Format("%d",atoi(sMaxNumber)+1); sNewNumber.Format("%s%s%s%s-%s",sCode,sYear,sMonth,sDay,Padl(sTempNewNumber,6,"0",1)); } else sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); } } end: return sNewNumber; }