Dialog for assigning key-value pairs.
Dialog for assigning key-value pairs. The call opens a dialog which displays a list of key-value pairs. In the third column of the displayed list, new values can be assigned to the keys. The key-value pairs can either be loaded from the data pool or from string lists. When the statement for updating the key-value assignment is given, the changes are are commited to the data pool on accepting the dialog. In an optional list, the new keys can be returned in the order of the key-value pairs.
Name | Type | Default | Description |
Return | int | 0 or ErrorCode |
|
title | String or char* | - | Title of the dialog |
info | String or char* | - | Descriptive text above the list |
selectStmt | String or char* | - | SQL- or xmlquery-statement for loading the key-value pairs. The statement may be empty. In this case, the key-value pairs will be loaded from the lists keys and values. Otherwise, the statement must yield three result columns (int, string, string]), containing the id of the entry which is used for saving changes, aswell as key and value. e.g. \span[src]{select id, key_, value from tt where id > 0. |
updateStmt | String or char* | - | SQL- or xmlquery-statement for saving changes keys. The statement will be executed when accepting the dialog. Only keys with a value != "" are saved. The statement may be empty and is ignored, when selectStmt is empty. Otherwise, the statement must contain two question marks ("?"). The first one is replaced by the new key, the second one by the id of the entry, e.g. update tt set key_ = ? where id = ?. |
keys | StringList | 0 | List of keys. The list is only used when selectStmt is empty. |
values | StringList | 0 | List of values. The list is only used when selectStmt is empty. When keys and values differ in length, the entry count is truncated to the length of the shorter list. |
result | IDTypeList | 0 | List of new keys.
This list is filled when the dialog is accepted.
The entries contain the following values: idtype::id : old ID (when using lists keys and values the old (1-based) row number idtype::id2 : new ID (when using lists keys and values the new (1-based) row number idtype::stringid : New key. The key doesn't necessarily have to exist in the list |
Example for simple assignment of Keys and Values in an XML Pool.
int main () { key_value_mapping ( "ttt", "Assignment for file ttt", "'ttt.xml' select id, name2, name node colors.color where id > 0", "'ttt.xml' update name2=? node colors.color where id = ?"); return 0; }
The call is nearly identical in an SQL-Datapool.
int main () { key_value_mapping ( "ttt", "Assignment of table ttt", "select id, key_, value from ttt where id > 0", "update ttt set key_ = ? where id = ?"); return 0; }
For complex situations where you cannot simply use select and update statements, you can use string lists and result lists. Here is a simple framework for the script.
int main () { StringList keys = stringlist::alloc (); StringList values = stringlist::alloc (); IDTypeList mappings = idtypelist::alloc (); IDType map = idtype::alloc (); int result; int i;
//Collect value pairs for (i = 0; i < 10; i++) { char key[256], value[256];
sprintf (key, "Key %d", i+1); sprintf (value, "Value %d", i+1); stringlist::append (keys, key); stringlist::append (values, value); }
result = key_value_mapping ( "Number assignment", "Assignment of new numbers", "", "", keys, values, mappings);
//Evaluate assignments if (result == 0) { i = 0; map = idtypelist::first (mappings); while (map) { if (strcmp (idtype::stringid (map), "") != 0) { wlog ("", "Mapping : Entry %d --> '%s', old id %d, new id %d\n", i+1, idtype::stringid (map), idtype::id (map), idtype::id2 (map)); } map = idtypelist::next (mappings); i = i+1; } } return 0; }
Alphabetic index HTML hierarchy of classes or Java