Append Context [Append db=DatabaseName]values[/Append]
Appends a new record with the specified field values to the end of a database.
SQL/ODBC Note: To append new records to the end of an ODBC-compliant table, use the [SQL] context.
New for WebDNA 5.x - You can specifiy a WebDNA table, in place of a db file, in the Append context. For example: [Append table=TableName]values[/Append]

 

Optional Context Parameters

· autonumber - instructs WebDNA to automatically generate the 'next highest number' value for the given fieldname.

To add new records to a database, put an Append context into a template (alternately, you may use the Append command from a URL or a FORM). Whenever WebDNA encounters an Append context, it immediately adds a new record to the end of the specified database given the named field values inside the Append context.

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

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

The database "SomeDatabase.db" is opened, and a new record is added to the end. The field name "name" is set to "Grant," the field name "address" is set to "1492 Somewhere Lane," the field name "zip" is set to "90000," and the field name "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 "[Append [FormVarable]]."

Any field names not existing in the database are ignored, and any fields you do not specify are left blank in the new record. Certain letters are illegal, such as <tab> or <carriage return>, so they are converted to <space> 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.

You may specify an absolute or partial path to the database file, as in "/WebCatalog/Folder/SomeDatabase.db" or "../SomeDatabase.db" (relative paths start in the same folder as the template, just like URLs, so "../" will look "up" one folder level from the template, and "/" will start at the web server's root).

Some database filenames are reserved. You may not create your own database named "WebCatalog Prefs," "Users.db," "ErrorMessages.db," "StandardConversions.db," or "Triggers.db"

Note: Normally all database file paths are relative to the local template, or if they begin with "/" they are relative to the web server's virtual host root. 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.

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&EMAIL=scott@here.com[/append]
[append table=table_1&AUTONUMBER=ID]NAME=Lee&EMAIL=lee@there.com[/append]
[append table=table_1&AUTONUMBER=ID]NAME=OMNI&EMAIL=omni@everywhere.com[/append]
[delete table=table_1&eqIDdata=2]
[append table=table_1&AUTONUMBER=ID]NAME=Lee&EMAIL=lee@there.com[/append]


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

[/founditems]
[/search]


Results:

1 - Scott - scott@here.com
3 - OMNI - omni@everywhere.com
4 - Lee - lee@there.com

 

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
AppendContext  

GJK - gary at garykrockover dot com 
06/06/2003 at 16:36:56
If you ever find yourself needing to do a large [append], save this snippet in an .html file named buildIt.html and put it in the same directory as your database's .hdr file (required).  You'll then have your large append statement ready to be copied/pasted into your template:


<form method="post" name="buildIt" action="buildIt.html">
Name of the Database:
<input type="text" name="strDatabase" value="[Input][/Input]">
Name of the .hdr file for this database:
<input type="text" name="theHdr" value="[Input][/Input]">
<input type="hidden" name="hasRun" value="T">
<input type="submit" name="submit" value="Submit">
[showif [hasRun]=T]
<br>
<br>
Here's your output:<br>
<hr>
[raw][append db=[/raw][strDatabase][raw]][!][/raw]<br>
[ListWords Words=[include file=[theHdr]]&Tabs=T]
[raw][/!][/raw][hideif [index]=1]&[/hideif][word][raw]=[url][[/raw][word][raw]][/url][!][/raw]<br>
[/ListWords][raw][/!][/append][/raw]
[/showif]
</form>

Stuart Tremain  
10/24/2003 at 06:01:02
An example for using [ThisAutoNumber]

[Append db=stores.db&AUTONUMBER=SKU][!]
[/!]STORE_NAME=[URL][_STORE_NAME][/URL][!]
[/!]&CITY=[URL][_CITY][[/URL][!]
[/!]&STATE=[URL][_STATE][/URL][!]
[/!][TEXT]ThisSKU=[ThisAutoNumber][/TEXT][!]
[/!][/Append]

The number that was assigned to the store was [ThisSKU].


nitai - nitai@computeroil.com 
11/20/2003 at 12:00:28
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.