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:
creator code (1997)
Execute Applescript (1997)
WebCatalog: Server Will not Stay up & running (2001)
[Q] Novice's question (1997)
WebCatalog on Linux (2000)
Pass Thru Page? (1998)
Problems adding stuff to the shopping cart. (1997)
Secure Server (1997)
[WebDNA] Internal [ipaddress] ? (2009)
Bug? (1997)
SQL Error 22003 : Found the workaround (2001)
update on wn searching (1997)
Plugin or CGI or both (1997)
[ShowIf] and empty fields (1997)
WC2b12: Yes, Formulas.db is for real (1997)
Problems with emailer cutting off carriage returns (Crossplatform issue?) (1999)
Session ID Equivalent (2003)
Generating unique SKU from [cart] - Still Stumped... (1997)
Public beta 5 of WebCatalog 4.0 is now available (2000)
Improper naming convections? (2004)