Difference between revisions of "Manual:Database Functions"
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...") |
(→db:add) |
||
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. | ||
− | + | ||
: See also: [[Manual:Lua_Functions#paste|paste]] | : See also: [[Manual:Lua_Functions#paste|paste]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<br/> | <br/> | ||
;Examples | ;Examples | ||
<lua> | <lua> | ||
− | --a | + | --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="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. | ||
− | |||
− | |||
− |
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.