WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Large Database Query Example


The attached script builds a .csv file in 'chunks'. It uses filewrite() and IntControl 53 to not leave a 'blank' line after each chunk. I used this technique on 6-7 million row DB2 queries to get Long-Distance Call Detail Records.
;Winbatch 2006C - write rows to csv file in chunks
;                 useful for large queries (millions of rows)
;
;Stan Littlefield June 21, 2006
;//////////////////////////////////////////////////////////////////

;substitute your own datasource and provider
cMDB=StrCat(DirScript(),"wmi.mdb")
If ! FileExist(cMDB) Then Exit
cOut=StrCat(DirScript(),"wmi.csv")
If FileExist(cOut) Then FileDelete(cOut)
cConn = "Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%cMDB%"

oRS = CreateObject("ADODB.Recordset")
oRS.CursorLocation=3

;adjustable number of records per page
nRecs = 40
oRS.CacheSize = nRecs

;basic forward-only cursor, substitute for your datasource
oRS.Open("SELECT * FROM Classes",cConn,0,1,1)

;hopefully your provider supports this
rCount = oRS.RecordCount

nPos=1
oRS.MoveFirst()
h=FileOpen(cOut,"WRITE")
IntControl(53,0,0,0,0)
While (nPos<=rCount) && !oRS.eof
  FileWrite( h,oRS.GetString(2,nRecs,",",@CRLF,"") )
  nPos=nPos+nRecs
EndWhile
:End
oRS.Close()
FileClose(h)
oRS=0
Exit
;/////////////////////////////////////////////////////////////



Article ID:   W17113
File Created: 2007:07:03:14:28:20
Last Updated: 2007:07:03:14:28:20