Replace Context [Replace Parameters]new values[/Replace]
Replaces each found record in a database with the new field values.
SQL/ODBC Note: To replace records in an ODBC-compliant table controlled by a SQL server, use the [SQL] context.
New for WebDNA 5.x - You can specifiy a WebDNA table, in place of a db file, in the Replace context. For example: [Replace table=TableName&...]values[/Replace]

To replace records in a database, put a [Replace] context into a template (alternately, you may use the Replace command from a URL or a FORM). Whenever WebDNA encounters a Replace, it immediately searches for the specified records in the database, and replaces those records' fields with the named field values inside the Replace.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[Replace db=SomeDatabase.db&eqNAMEdata=Grant]name=John&address=1492 Somewhere Lane&zip=90000&date=[date][/Replace]

The database "SomeDatabase.db" opens and all records whose name field is "Grant" are found. The field names "name" is set to "John," "address" is set to "1492 Somewhere Lane," "zip" is set to "90000," and "date" is set to the current date. Notice that any WebDNA [xxx] tags inside the context are first substituted for their real values before being written to the database. The name of the database itself may also be an [xxx] tag, as in "[Replace db=[FormVarable]]".

Any field names not existing in the database are ignored, and if you leave some existing field names out of the replace context, they will remain unchanged in the database. Certain letters are illegal, such as <tab> or <carriage return>, so they are converted to <soft tab> and <soft return> before being added to the database. Some computers use the two-character sequence <carriage return><line feed> to indicate a single end of line, which is automatically converted to a single <soft return> character before being added to the database. These 'soft' characters are automatically converted back to 'hard' versions (the originals) whenever you retrieve fields from a search of the database.

You may specify an absolute or relative path to the database file, as in "/WebCatalog/GeneralStore/SomeDatabase.db" or "../SomeDatabase.db".

Note: Normally all database filepaths are relative to the local template, or if they begin with "/" they are relative to the web server's virtual host root (MacOS and Unix versions only; PC versions treat the DBServer.exe folder as root regardless of the virtual host). You may optionally put "^" in front of the file path to indicate the file can be found in a global root folder called "Globals" inside the WebCatalogEngine folder. This global root folder is the same regardless of the virtual host.

 Parameter  Description
path to database file, relative to this template.
New for WebDNA 5.x
In place of a db file, you can specify a named reference to a WebDNA table object.
Search information describing which records should be found and replaced. Can be any complex search criteria, works exactly like Search command or [Search] context.
(Optional) "T" if you want a new record to be added to the end of the database in the case where no records were found to be replaced. Any fields you do not specify are left blank in the new record.
(Optional) Instructs WebDNA to automatically generate the 'next highest number' value for the given fieldname.


You can use the 'AUTONUMBER=' parameter with the [append] or [replace] context to instruct WebDNA to automatically generate the 'next highest number' value for the given fieldname. This is useful for 'ID' type fields, where unique values are required.

Here is a demonstration of the AUTONUMBER feature using a WebDNA TABLE (of course this will work on database files as well).

Example WebDNA code:

[table name=table_1&fields=ID,NAME,EMAIL][/table]

[append table=table_1&AUTONUMBER=ID]NAME=Scott&[/append]
[append table=table_1&AUTONUMBER=ID]NAME=Lee&[/append]
[append table=table_1&AUTONUMBER=ID]NAME=OMNI&[/append]
[delete table=table_1&eqIDdata=2]
[append table=table_1&AUTONUMBER=ID]NAME=Lee&[/append]

[search table=table_1&neIDdata=[blank]]
[ID] - [NAME] - [EMAIL]



1 - Scott -
3 - OMNI -
4 - Lee -


You can see that WebDNA automatically generated the ID value by calculating the 'next largest value', given the existing ID values in the table.

New for WebDNA 5.1 - You use the new [ThisAutonumber] tag from within an Append or Replace context, to retrieve the current auto-generated number (if the AUTONUMBER parameter was used).

User Contributed Notes

Bill DeVaul  
05/23/2003 at 08:22:41
Is autonumber the New in 5.0 feature?

GK - gary at garykrockover dot com 
07/13/2003 at 20:27:06
Because it's been asked about a few times lately on the list; if you're not using 5.x, you can get the next available sku (or whatever) number in an "autonumber" format for your append in this manner:

[Append db=YOURDATABASE.db][!]
[/!]sku=[math]Newsku=([Search db=YOURDATABASE.db&neskudatarq=[blank]&deskusort=1&skutype=num&max=1][FoundItems][sku][/FoundItems][/Search]+1)[/math][!]

* comments added at the EOL to prevent linebreaks in the actual context.
** Substitute "sku" for your datafield that you wish to apply the autoincrement to.
*** Adjust the +1 in the [math] context to any amount you wish to auto-increment by.

Nitai - 
11/20/2003 at 12:01:33
An autonumber action will only occur in a replace IF you have specified
'Append=T', and the replace does result in an new record getting appended to the database.

Copyright © 2008 WebDNA Software Corporation, Inc.