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.

RemoveDups


;**************************************************
;** This sample Removes Duplicates. In this case it adds the
;** sample database to itself. It will create a resulting database 
;** with a duplicate record of every record in the source database.
;**************************************************
ret = AddExtender("Laffd34i.dll")
;**************************************************
;**   dbOpen - open the test database A 
;**************************************************
inputfilename = "C:\Temp\table1.txt"
if !FileExist(inputfilename)
   str = "Make sure the database exists before attempting to run this example."
   str2 = "See the dbOpen example in this help file, it will create the example database for you."
   Message("Database doesn't exist", StrCat(str, @CRLF,str2))
	exit
Endif
delimiter = ","
bCreateOK = 0
model = 2     ;Traditional
numcols = -1  ;Number of columns match first line, names them, starts reading at 2nd line
format = 0    ;Delimiter based 
optionstring = ""
handleA = dbOpen (inputfilename, bCreateOK, model, numcols, format, delimiter, optionstring)
if handleA == @LAFFDBERROR
    err = dbGetLastError()
	 Message("Error Opening the database A specified", err)
	 exit
Endif


outputfilename = "C:\Temp\RemovedDups.txt"
path = filepath(outputfilename)
if !DirExist(path)
   Message("Note",strcat("Creating the directory ", path))
	DirMake(path)
endif
if FileExist(outputfilename) then FileDelete(outputfilename)


operation =  5 ;Remove Duplicates from A. C = A - duplicates
flags = 0
columnlayout = "ID,ID,ID Name,Name,Name Description,Description,Description"  ;!!!!!CHANGE TO REFLECT YOUR COLUMN NAMES
matchingcriteria = "e * *" ;check FIRST column for 'Exact character, case insensitive match'.
handle = dbCookDatabases ( outputfilename, model, format, delimiter, optionstring, handleA, 0, operation, flags, columnlayout, matchingcriteria)
if handle == @LAFFDBERROR
	 err = dbGetLastError()
	 Message("Error Cooking the database", err)
endif

;**************************************************
;**   dbDebug - to view the database with the column removed
;**************************************************
ret = dbDebug(handle)
if ret == 0
	 err = dbGetLastError()
	 Message("Error using dbDebug", err)
endif
ret = AskYesNo('Do you want to save changes to the sample database?', 'if so, please press "YES"')
if ret == @YES 
	 saveas = AskFileName("SelectFile", "C:\Temp", "All Files|*.*", "RemovedDups.txt", 0)
   ;**************************************************
   ;**   Saves Changes 
   ;**************************************************
   ret = dbSave (handle, saveas, "")
   if ret == 0
   	 err = dbGetLastError()
   	 Message("Error Saving the database", err)
   endif
endif
;**************************************************
;**   Closes Database handles
;**************************************************
ret = dbClose(handleA)
if ret == @LAFFDBERROR
	 err = dbGetLastError()
	 Message("Error Closing the database", err)
endif

exit

TABLE1.TXT

ID,Name,Description
01,"Hansen Ola","Sales"
02,"Svendso Tove","Support"
03,"Svendson Stephen","Management"
03,"Flintstone Fred","Support"
04,"Pettersen Kari","Sales"


Article ID:   W15841
File Created: 2004:03:30:15:41:04
Last Updated: 2004:03:30:15:41:04