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:
Beta 18 (1997)
Emailer and encryption (1997)
maximum characters in [username]? (2002)
[ot] Any One Want A WebDNA Billing Program? (2003)
Separate SSL Server (1997)
Bug Report, maybe (1997)
Unique SKUs (2000)
Nested tags count question (1997)
Stats (2004)
WebCat2 several catalogs? (1997)
URL encoding (1998)
WebCat2b14MacPlugIn - [include] doesn't hide the search string (1997)
sorting and grouping (1998)
PCS Frames (1997)
Setting up shop (1997)
webcat license???? (1997)
Multiple Domains with 1 Shopping Cart (2008)
Cart Transfer from Un-Secure to Secure (2000)
Help! Missing [showif] or [hideif] (2000)
[Fwd: Rotating Banners ... (was LinkExchange)] (1997)