Difference between revisions of "Manual:Database Functions"

From Mudlet
Jump to navigation Jump to search
(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...")
 
Line 1: Line 1:
 
==db:add==
 
==db:add==
;db:add(sheet reference, table1, …, tableN)
+
;<nowiki>db:add(sheet reference, table1, …, tableN)</nowiki>
 
: 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.
 
: 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: [[Manual:Lua_Functions#paste|paste]]
 
: See also: [[Manual:Lua_Functions#paste|paste]]
<br/>
 
 
;Parameters
 
* arg1:
 
: What arg1 is/does. Passed as a string.
 
* arg2:
 
: What arg2 is/does. Passed as a string.
 
 
<br/>
 
<br/>
  
 
;Examples
 
;Examples
 
<lua>
 
<lua>
--a small example snippet of the function in action
+
--Each table is a series of key-value pairs to set the values of the sheet, but if any keys do not exist then they will be set to nil or the default value.
--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="Bob Smith", city="San Francisco"})
 
         db:add(mydb.enemies,
 
         db:add(mydb.enemies,
Line 24: Line 16:
 
</lua>
 
</lua>
 
As you can see, all fields are optional.
 
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.
 

Revision as of 02:56, 14 January 2012

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.
See also: paste


Examples

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

       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.