Example for adding an autonumber field to a database

This WebDNA talk-list message is from

2006


It keeps the original formatting.
numero = 63847
interpreted = N
texte = I wrote a simple fix for some databases I had that needed a SKU or ID field that is autonumbered. First I fixed the code where I appended records to include autonumbering, then I ran code below to add the field and autonumber it. I'm posting the code because it might help someone else. If there's a better way, please let me know. Thanks, Bill [!] ADD AN AUTONUMBERED FIELD TO A DATABASE SPECIFY THE DATABASE and THE INCREMENTFIELD [/!] [!]MAKE THE NEW.DB WITH NEW AND OLD FIELDS USING TABS[/!] [!]START SPECIFY THESE[/!] [text]olddb=DATABASE.db[/text] [text]incrementfield=SKU[/text] [!]END SPECIFY THESE[/!] [text]newdb=new_[olddb][/text][!]MAKE SURE THIS IS NOT AN EXISTING DATABASE[/!] [!]VALIDATION[/!] [if "[fileinfo file=[olddb]][exists][/fileinfo]"!"T"] [then] [text]errordetected=MISSING DATABASE[/text] [/then] [else] [listfields db=[olddb]] [showif [fieldname]=[incrementfield]] [text]errordetected=FIELD USED[/text] [/showif] [/listfields] [/else] [/if] [if "[errordetected]"="[raw][errordetected][/raw]"] [then] [writefile file=[newdb]][incrementfield][listfields db=[olddb]] [fieldname][/listfields] [/writefile] [!]COPY OLD RECORDS TO NEW.DB[/!] [search db=[olddb][listfields db=[olddb]]&ne[fieldname]datarq= [findall][/listfields]] [founditems] [append db=[newdb]&autonumber=[incrementfield]][listfields db= [olddb]]&[fieldname]=[interpret][[fieldname]][/interpret][/listfields] [/append] [/founditems] [/search] [!]ARCHIVE OLD AND SWAP IN NEW FILE[/!] [text]dbarchivefolder=dbarchive/[/text] [showif [fileinfo file=[dbarchive]][exists][/fileinfo]!T] [createfolder path=[dbarchivefolder]] [/showif] [exclusivelock db=[olddb]&db=[newdb]] [closedatabase db=[olddb]] [closedatabase db=[newdb]] [movefile from=[olddb]&to=[dbarchivefolder][olddb]_[math]{[date]}[/ math]_[math]{[time]}[/math]] [movefile from=[newdb]&to=[olddb]] [/exclusivelock]

[olddb] has been updated

[/then] [else]

[errordetected]

[/else] [/if] ------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ Associated Messages, from the most recent to the oldest:

    
  1. Example for adding an autonumber field to a database ( William DeVaul 2006)
I wrote a simple fix for some databases I had that needed a SKU or ID field that is autonumbered. First I fixed the code where I appended records to include autonumbering, then I ran code below to add the field and autonumber it. I'm posting the code because it might help someone else. If there's a better way, please let me know. Thanks, Bill [!] ADD AN AUTONUMBERED FIELD TO A DATABASE SPECIFY THE DATABASE and THE INCREMENTFIELD [/!] [!]MAKE THE NEW.DB WITH NEW AND OLD FIELDS USING TABS[/!] [!]START SPECIFY THESE[/!] [text]olddb=DATABASE.db[/text] [text]incrementfield=SKU[/text] [!]END SPECIFY THESE[/!] [text]newdb=new_[olddb][/text][!]MAKE SURE THIS IS NOT AN EXISTING DATABASE[/!] [!]VALIDATION[/!] [if "[fileinfo file=[olddb]][exists][/fileinfo]"!"T"] [then] [text]errordetected=MISSING DATABASE[/text] [/then] [else] [listfields db=[olddb]] [showif [fieldname]=[incrementfield]] [text]errordetected=FIELD USED[/text] [/showif] [/listfields] [/else] [/if] [if "[errordetected]"="[raw][errordetected][/raw]"] [then] [writefile file=[newdb]][incrementfield][listfields db=[olddb]] [fieldname][/listfields] [/writefile] [!]COPY OLD RECORDS TO NEW.DB[/!] [search db=[olddb][listfields db=[olddb]]&ne[fieldname]datarq= [findall][/listfields]] [founditems] [append db=[newdb]&autonumber=[incrementfield]][listfields db= [olddb]]&[fieldname]=[interpret][[fieldname]][/interpret][/listfields] [/append] [/founditems] [/search] [!]ARCHIVE OLD AND SWAP IN NEW FILE[/!] [text]dbarchivefolder=dbarchive/[/text] [showif [fileinfo file=[dbarchive]][exists][/fileinfo]!T] [createfolder path=[dbarchivefolder]] [/showif] [exclusivelock db=[olddb]&db=[newdb]] [closedatabase db=[olddb]] [closedatabase db=[newdb]] [movefile from=[olddb]&to=[dbarchivefolder][olddb]_[math]{[date]}[/ math]_[math]{[time]}[/math]] [movefile from=[newdb]&to=[olddb]] [/exclusivelock]

[olddb] has been updated

[/then] [else]

[errordetected]

[/else] [/if] ------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ William DeVaul

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:

Some Questions (1997) emailer on Windows Beta 18 (1997) WebCat vs. ASP (1999) WebCat2b13MacPlugIn - [include] doesn't allow creator (1997) WebCat2 beta 11 - new prefs ... (1997) WebCat2: Items xx to xx shown, etc. (1997) writefile and deletefile (1998) [WebDNA] Poll: Discussion Forum (2009) PSC recommends what date format yr 2000??? (1997) Switching from merge to tab delimited..(v 2.x) (2000) posting problems + Webcat 3.0.7 available - did anyone know? (2000) Details of shipping - Totalqty calculations (1997) 2.0 Info (1997) Removing [showif] makes a big difference in speed (1997) sendmail logs (1999) search form problem.. (1997) RE: Emailer Set Up (1997) Multiple prices (1997) WebCatalog2 Feature Feedback (1996) Price and Formula.db (2002)