Manual:Database Functions

From Mudlet
Revision as of 02:49, 14 January 2012 by Darmir (talk | contribs) (Created page with "==db:add== ;db:add(sheet reference, table1, …, tableN) : Adds one or more new rows to the specified sheet. If any of these rows would violate a UNIQUE index, a lua error will b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

db:add

db
add(sheet reference, table1, …, tableN)
Adds one or more new rows to the specified sheet. If any of these rows would violate a UNIQUE index, a lua error will be thrown and execution will cancel. As such it is advisable that if you use a UNIQUE index, you test those values before you attempt to insert a new row.
Returns whatever the function returns.
See also: paste


Parameters
  • arg1:
What arg1 is/does. Passed as a string.
  • arg2:
What arg2 is/does. Passed as a string.


Examples

<lua> --a small example snippet of the function in action --the comments up top should introduce it/explain what the snippet does

       db:add(mydb.enemies, {name="Bob Smith", city="San Francisco"})
       db:add(mydb.enemies,
               {name="John Smith", city="San Francisco"},
               {name="Jane Smith", city="San Francisco"},
               {name="Richard Clark"})

</lua> As you can see, all fields are optional.


Each table is a series of key-value pairs to set the values of the sheet, but if any keys do nto exist then they will be set to nil or the default value.