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

LAFFDB (obsolete)
plus

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

Look for Certain Number in a Field and Retrieve Line

Keywords: 	  LAFFDB binary indexing

Question:

Presently, I have a tab delimited file (Security log dumpel file) that I look for a curtain number in the 5th field (event), then retrieve the entire line. Now, I would like to load this file into a memory buffer, search for this event (this 3 digit number can also exist in other fields, so I need to be able to search in the 5th field only) and then retrieve the entire line into a variable. Any suggestion?

Answer:

Well, I would SUGGEST taking a look at the LAFFDB extender. What you really have there is a Light ascii flat file database. that's exactly what the extender is made for. Example of winding loop - dbfindrecord returns a -1 when there's no more matches
while @true
	linenumber = dbfindrecord(...search criteria...)
	if linenumber = -1 then break
	dbgetentirerecord(...details of the record...)
	gosub Deal_with_the_record
endwhile

Here is a more useful example:
Addextender("LAFFD34i.DLL")

db_fn        = "Security log dump file.log"
db_create    = 0 ; file should exist
db_model     = 2 ; traditional
db_cols      = 0 ; use the number of columns in the first line of the file
db_format    = 0 ; delimiter based
db_delimiter = @tab
db_options   = "" ; don't bother

hnd_db = dbopen(db_fn,db_create,db_model,db_cols,db_format,db_delimit,db_option)

db_colcount = dbgetcolumncount(hnd_db)

for a = 1 to db_colcount
        
        dbbindcol(hnd_db,a,VAR%a%)
        
next

search_flags = 1 + 4          ; use and return fixed record nums (note that fixed record nums are 1 based), and search forward
search_col   = 5              ; this is the column you wanted to skim
search_value = curtain_number ; this is what you wanted to search for
search_case  = 0              ; not case sensitive
search_start = 0              ; start at zero to actually search record #1
get_flags    = 1              ; get a fixed record num (needs to match search flag)

linenumber = search_start ; need to init the variable
while @true
        
        linenumber = dbfindrecord(hnd_db,linenumber,search_flags,search_col,search_value,search_case)) ;returns -1 if no more matches
        if linenumber < 0 then break ; breaks on done searching OR error (because error is -42424242)
        dbgetentirerecord(hnd_db,linenumber,get_flags)
        gosub Deal_with_the_record
        
endwhile

dbclose(hnd_db)

exit


;---------------------------------------------------------------------------------------------------------
:Deal_with_the_record
        
        ; here is where you will do whatever you want.. 
        ; the variables will be named var1, var2, var3, var4... etc
        ; this routine will run once for each matching line in your file
        ; have at it...
        
return
;---------------------------------------------------------------------------------------------------------



Article ID:   W15056
File Created: 2002:09:05:13:49:22
Last Updated: 2002:09:05:13:49:22