Re: Database append/replace

This WebDNA talk-list message is from

2004


It keeps the original formatting.
numero = 55897
interpreted = N
texte = >Hi, > >I make a "easy to use" webdna code to append or replace data into a >database. > >[!]Insert database name[/!] >[text]dbname=../db/database.db][/text] > >[!]Insert location server home directory[/!] >[text]server=/home/www.website.com/docs/HTML/db/[/text] >[text]velden=[ListDatabases db=[dbname]][showif >[name]=[server][dbname]][numFields][/showif][/ListDatabases][/text] > >[!]Replace[/!] >[showif [go]=replace][replace db=[dbname]&eqSKUdata=[SKU][listfields >db=[dbname]][fieldname]=[interpret][[fieldname]][/interpret][showif >[index]![velden]]&[/showif][/listfields][/replace][/showif] > >[!]Append[/!] >[showif [go]=append][append db=[dbname]&eqSKUdata=[SKU][listfields >db=[dbname]][fieldname]=[interpret][[fieldname]][/interpret][showif >[index]![velden]]&[/showif][/listfields][/append][/showif] > >Maybe usefull for you! Thanks Edwin, that's a good start! Just be careful with your syntax (you made some syntax errors above) and if you want your code to work properly with all data you will have to URL the values in your append and replace contexts. Here's a better (simpler) example of only the replace context to show you what I mean: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][listfields db=[dbname]]&[fieldname]=[url][interpret][[fieldname]][/interpret][/url][/listfields][/replace] By the way, you do not need the 'velden' variable because there's no need to prevent the extra '&' from being entered by the listfields context, webdna just ignores it anyways. Therefore you can also get rid of the showif that you're using to eliminate the extra '&' and the results will be the same -- with simpler code. And for everyone who is going to use a similar technique, you can *also* set custom field values BEFORE the listfields code, because webdna only recognizes the first occurrence of each field value inside append and replace contexts. In other words, this will set the sku value to 'abc' even though a different sku value is already included in the listfields code: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]]sku=123[listfields db=[dbname]]&[fieldname]=[url][interpret][[fieldname]][/interpret][/url][/listfields][/replace] And if you're really only interested in changing the values that appear in a form, instead of changing the values of every field in the database record, there's an even better way to do it: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][formvariables]&[name]=[url][value][/url][/formvariables][/replace] Just remember, the formvariables context *still* passes an undesirable value named "template" that is not a true formvariable, it's just the name of the file the form appears in. The webdna developers apparently threw this in there for 'convenience' about 7 or 8 years ago, so it's still there -- and it can create problems in certain situations if you're not careful. For example, if you have a db field named "template" and you use the example above, your db 'template' value will be overwritten by that damn 'template' pseudo-formvariable UNLESS you write what I refer to as "bug avoidance code" to get around the problem, like this: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][formvariables][hideif [url][name][/url]=template]&[name]=[url][value][/url][/hideif][/formvariables][/replace] The hideif will strip out the bogus 'template' value that the formvariables context enters, thus preventing that bogus value from overwriting the existing 'template' value in your db. But of course it's easier to deal with this issue by not use a field named 'template' in the first place, and then you don't have to work around this particular webdna inconsistency. :) -- Kenneth Grome WebDNA Programmer Outsource Service Provider ------------------------------------------------------------- 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. Re: Database append/replace ( Kenneth Grome 2004)
  2. Database append/replace ( "Edwin Hoevers" 2004)
>Hi, > >I make a "easy to use" webdna code to append or replace data into a >database. > >[!]Insert database name[/!] >[text]dbname=../db/database.db][/text] > >[!]Insert location server home directory[/!] >[text]server=/home/www.website.com/docs/HTML/db/[/text] >[text]velden=[ListDatabases db=[dbname]][showif >[name]=[server][dbname]][numFields][/showif][/ListDatabases][/text] > >[!]Replace[/!] >[showif [go]=replace][replace db=[dbname]&eqSKUdata=[SKU][listfields >db=[dbname]][fieldname]=[interpret][[fieldname]][/interpret][showif >[index]![velden]]&[/showif][/listfields][/replace][/showif] > >[!]Append[/!] >[showif [go]=append][append db=[dbname]&eqSKUdata=[SKU][listfields >db=[dbname]][fieldname]=[interpret][[fieldname]][/interpret][showif >[index]![velden]]&[/showif][/listfields][/append][/showif] > >Maybe usefull for you! Thanks Edwin, that's a good start! Just be careful with your syntax (you made some syntax errors above) and if you want your code to work properly with all data you will have to URL the values in your append and replace contexts. Here's a better (simpler) example of only the replace context to show you what I mean: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][listfields db=[dbname]]&[fieldname]=[url][interpret][[fieldname]][/interpret][/url][/listfields][/replace] By the way, you do not need the 'velden' variable because there's no need to prevent the extra '&' from being entered by the listfields context, webdna just ignores it anyways. Therefore you can also get rid of the showif that you're using to eliminate the extra '&' and the results will be the same -- with simpler code. And for everyone who is going to use a similar technique, you can *also* set custom field values BEFORE the listfields code, because webdna only recognizes the first occurrence of each field value inside append and replace contexts. In other words, this will set the sku value to 'abc' even though a different sku value is already included in the listfields code: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]]sku=123[listfields db=[dbname]]&[fieldname]=[url][interpret][[fieldname]][/interpret][/url][/listfields][/replace] And if you're really only interested in changing the values that appear in a form, instead of changing the values of every field in the database record, there's an even better way to do it: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][formvariables]&[name]=[url][value][/url][/formvariables][/replace] Just remember, the formvariables context *still* passes an undesirable value named "template" that is not a true formvariable, it's just the name of the file the form appears in. The webdna developers apparently threw this in there for 'convenience' about 7 or 8 years ago, so it's still there -- and it can create problems in certain situations if you're not careful. For example, if you have a db field named "template" and you use the example above, your db 'template' value will be overwritten by that damn 'template' pseudo-formvariable UNLESS you write what I refer to as "bug avoidance code" to get around the problem, like this: [replace db=[dbname]&eqSKUdata=[url][SKU][/url]][formvariables][hideif [url][name][/url]=template]&[name]=[url][value][/url][/hideif][/formvariables][/replace] The hideif will strip out the bogus 'template' value that the formvariables context enters, thus preventing that bogus value from overwriting the existing 'template' value in your db. But of course it's easier to deal with this issue by not use a field named 'template' in the first place, and then you don't have to work around this particular webdna inconsistency. :) -- Kenneth Grome WebDNA Programmer Outsource Service Provider ------------------------------------------------------------- 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/ 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:

Speeding up my [showif] performance (1999) [WebDNA] Is there a D.E. database record limit? (2014) how many users (2000) form image (2000) WebCat2 Append problem (B14Macacgi) (1997) [format xs] freeze (1997) WebCat2b13MacPlugIn - [showif][search][/showif] (1997) [searchString] (1997) problems with 2 tags (1997) Bug Report, maybe (1997) Calendar Program (2004) WebDNA Server (2007) Trouble with formula.db (1997) Q: writefile and uploads. (1998) Code database (1998) Using WC for Bulk Emailings (1997) Dummy Form Variables Needed (2000) different ship dates and shopping carts -- how to? (1997) HELP WITH DATES (1997) Friendly , quick 'security' check, please (2003)