Skip to content

Commit ff1f2df

Browse files
committedDec 20, 2018
Add sqlite_fetch_and increment docs
1 parent 5d8f637 commit ff1f2df

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "sqlite_fetch_and_increment",
3+
"type": "function",
4+
"description": "Manage autoincrementing values in sqlite databases.<p>SQlite default values can only be applied on insert and not prefetched.</p><p>This makes it impossible to acquire an incremented primary key via AUTO_INCREMENT before creating the row in the database. Sidenote: with postgres, this works via the option "evaluate default values".</p><p>When adding new features with relations, it is really nice to be able to already add children for a parent, while the parents form is still open and hence the parent feature uncommitted.</p><p>To get around this limitation, this function can be used to manage sequence values in a separate table on sqlite based formats like gpkg.</p><p>The sequence table will be filtered for a sequence id (filter_attribute and filter_value) and the current value of the id_field will be incremented by 1 ond the incremented value returned.</p><p>If additional columns require values to be specified, the default_value map can be used for this purpose.</p><p><b>Note</b><br/>This function modifies the target sqlite table. It is intended for usage with default value configurations for attributes.</p>",
5+
"arguments": [
6+
{"arg":"database", "description":"Path to the sqlite file"},
7+
{"arg":"table", "description":"Name of the table that manages the sequences"},
8+
{"arg":"id_field", "description":"Name of the field that contains the current value"},
9+
{"arg":"filter_attribute", "description":"Name the field that contains a unique identifier for this sequence. Must have a UNIQUE index."},
10+
{"arg":"filter_value", "description":"Name of the sequence to use."},
11+
{"arg":"default_values", "description":"Map with default values for additional columns on the table. The values need to be fully quoted. Functions are allowed."}
12+
],
13+
"examples": [
14+
{ "expression":"sqlite_fetch_and_increment(layer_property(@layer, 'path'), 'sequence_table', 'last_unique_id', 'sequence_id', 'global', map('last_change','date(''now'')','user',@user_account_name))", "returns":"0"}
15+
]
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.