Re: [WebDNA] Repeated Task [reworking a DB)
This WebDNA talk-list message is from 2015
It keeps the original formatting.
numero = 112112
interpreted = N
texte = > I have no problem in making a duplicate of the DB.Great!> Do you have any suggestion/best practise ...Rather than change existing values I'll give you instructions andcode that enters incremental values into a new field:1- After you duplicate the db, append a tab character then "ix" tothe first line of the db (or your .hdr file). This will be thefield for your new incremental numbers.2- Put this code in a new template then request it ONCE:[text]go=[elapsedtime][/text][math show=f]last=0[/math][loop start=1&end=99999][commitdatabase theCopy.db][waitforfile file=thisFileWillNeverExist&timeout=10][/waitforfile][search db=theCopy.db&eqixdatarq=[blank]&rank=off&max=500][replacefounditems]ix=[math]last=last+1[/math][/replacefounditems][showif [numfound]=0][break][/showif][/search][/loop]Processing took [math]([elapsedtime]-[go])/60[/math] seconds.This code will process 500 records at a time, wait 10 secondsbefore processing the next batch of 500 records, and stopautomatically when it has processed every record in the db.The timeout is there to limit the amount of resources consumed bythis thread while it is processing the db. It should allow plentyof time for other threads to do their work without causing theserver to grind to a halt.When processing is done, just replace the original db with thisone. Then in your append contexts use "autonumber=ix" so newrecords will have incremental values. And when you want to sortin reverse db order use "deixsort=1&ixtype=num".NOTES:1- You may want to run this code with [loop start=1&end=1] firstto see if it works. If it does, you'll also have to ...2- Change the zero in "[math show=f]last=0[/math]" to the largestnumber in the "ix" field (otherwise you'll get duplicates with"ix" values of 1-500) ... then use [loop start=1&end=99999] beforeyou run the code again.Regards,Kenneth GromeWebDNA Solutionshttp://www.webdnasolutions.comWeb Database Systems and Linux Server Management
Associated Messages, from the most recent to the oldest:
> I have no problem in making a duplicate of the DB.Great!> Do you have any suggestion/best practise ...Rather than change existing values I'll give you instructions andcode that enters incremental values into a new field:1- After you duplicate the db, append a tab character then "ix" tothe first line of the db (or your .hdr file). This will be thefield for your new incremental numbers.2- Put this code in a new template then request it ONCE:
[text]go=
[elapsedtime][/text][math show=f]last=0[/math][loop start=1&end=99999][commitdatabase theCopy.db][waitforfile file=thisFileWillNeverExist&timeout=10][/waitforfile][search db=theCopy.db&eqixdatarq=[blank]&rank=off&max=500]
[replacefounditems]ix=
[math]last=last+1[/math][/replacefounditems][showif [numfound]=0][break][/showif][/search][/loop]Processing took
[math](
[elapsedtime]-[go])/60[/math] seconds.This code will process 500 records at a time, wait 10 secondsbefore processing the next batch of 500 records, and stopautomatically when it has processed every record in the db.The timeout is there to limit the amount of resources consumed bythis thread while it is processing the db. It should allow plentyof time for other threads to do their work without causing theserver to grind to a halt.When processing is done, just replace the original db with thisone. Then in your append contexts use "autonumber=ix" so newrecords will have incremental values. And when you want to sortin reverse db order use "deixsort=1&ixtype=num".NOTES:1- You may want to run this code with [loop start=1&end=1] firstto see if it works. If it does, you'll also have to ...2- Change the zero in "[math show=f]last=0[/math]" to the largestnumber in the "ix" field (otherwise you'll get duplicates with"ix" values of 1-500) ... then use [loop start=1&end=99999] beforeyou run the code again.Regards,Kenneth GromeWebDNA Solutionshttp://www.webdnasolutions.comWeb Database Systems and Linux Server Management
Kenneth Grome
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
HELP WITH DATES (1997)
WebCat2b14MacPlugIn - [include] doesn't hide the search string (1997)
More on the email templates (1997)
Initiating NewCart (1997)
WebCat2b15MacPlugIn - [authenticate] not [protect] (1997)
OT - royalty free images (2002)
WC2b15 File Corruption (1997)
Triggers (2005)
process SSI (1998)
WebCatalog not running after upgrade (2000)
Major Security Hole (solution with Welcome) (1998)
WebCat2: Items xx to xx shown, etc. (1997)
Multiple cart additions (1997)
Setting a text Var inside an orderfile (2002)
[include] affect on filepaths for links? (1997)
[WebDNA] Encode cookies ONLY via "method=Base64" (2008)
[WebDNA] Problem saving returned value as a variable (2012)
Database Crash (2001)
taxRate is fine but taxTotal isn't (1997)
Can't find templaes (1997)