How to modify information


No surprise that with various recording levels, Unidatab provides also various means of modifying information.  Let’ start by looking at how we can change some input data and we’ll admit that we should better act on properties and types.

Changing data

Since pure data is only entered once and not duplicated, we understand that changing data directly could yield more problems than anything else. For if within one record the data refered to has to be changed, the same bits of information could well be pointed to in another record where this modification wouldn’t seem appropriate. Thus there’s only one situation where a direct modification of input, is required: when the data is falty. Suppose for instance you have entered a symbol containing property “H3O” and type “water” (and a symbol id set to -219 in our examples). You can then issue:

? select change_data('H3O','H2O')

Or if you know the data id (say ‘72‘):

? select change_data(72,'H2O')
Changing symbols

However, the database can contain for instance materials for a fantasy book where water is H3O, or H3O can have another meaning. Moreover, you may have modification rights on the base without knowing exactly its content. Therefore, change_data() is a dangerous function to be used by admin only and for repair purpose. A normal use of the software should prevent any damage to occur at all and  prefer a non destructive function like replace_symbol(). First make a correct symbol:

? select get_symbol('H2O','water') 
-217 -- then
? select replace_symbol(0,-219,-217,-1)

or use a compound query. According to the definition of replace_symbol(), the last parameter decides the scope of this function, -1 targets the whole base, then the falty symbol -219 shall be replaced by -217 globally, and 0 as last parameter would target a specific link; in this latter case, the first parameter would have to be the node to modify. Other scopes are not available yet.

Removing a symbol

Knowing how to remove a link will help a lot in using Unidatab from unid-adm, because we can then bypass more complex functions like replace_symbol(). Combined with ink_record(), remove_link() allows to add and remove symbols from a record as desired. All we need is the id of the unwanted link:

? select show_record(-204)
show_record(-204) :
i a d n t u 
-204 63 -204 -201 1479498214 admin 
-201 -202 -204 -208 1479498214 admin 
-208 -207 -201 -217 1479498679 admin 
-217 -219 -208 0 1479500329 admin 
? select remove_link(-217)
remove_link(-217) :
1 -- link has been removed
reformat()

The modification of symbols is basic, but records are grouped by their format too (the second node in the record’s links), so we need to be able to change this field which is the type of the record:

? select reformat('my_fantasy_book',get_symbol(0,'new book format',1))
1 -- an existing record is given a new format

The request will fail if get_symbol() is not fed with property=0 and unicity=1 like above. reformat() also accepts the ids of an existing record and an existing format.

retitle()

Changing a title (the first node in the record’s links) is even simpler:

? select retitle('my_fantasy_book','Fantasy')
1 -- note that 'my_fantasy_book' is the alias here, not the old title

By the way, let’s remark in the show_record() query above, that unlike other links, the title always points to a positive value (field a). This is due to the fact that in Unidatab, a title is not conceived as a real property, but only as a token, not even necessarily unique.

Changing symbols order

Depending on the type policy, records may either be ordered or unordered sets of symbols. In the former case, or for design reasons, users may want to change the order of symbols within a record. As each symbol is targeted by a link in the record’s node chain, changing the order of two symbols implies two fields in two different nodes. This is done with swap_symbols():

? select show_record(-204)
show_record(-204) :
i a d n t u 
-204 63 -204 -201 1479498214 admin 
-201 -202 -204 -208 1479498214 admin 
-208 -207 -201 0 1479498679 admin 
-217 -219 -208 0 1479500329 admin 
? select swap_symbols(-204,-207,-204,-219) 
_UnidCon__exec__sqlarg_ctl_: invalid sign: -1 for arg: -207 to: _SWAP_SYMBOLS_ ### SQL Error: 100_unidAdmin_request failed: _sqlarg_ctl_: invalid sign: 1 for arg: -207 to: _SWAP_SYMBOLS_ 
? select swap_symbols(-204,0,-204,2) 
_UnidCon__exec__SWAP_SYMBOLS_: (a) invalid pos. :0 (3) ### SQL Error: 100_unidAdmin_request failed: _SWAP_SYMBOLS_: (a) invalid pos. :0 (3)
? select swap_symbols(-204,1,-204,2) 
swap_symbols(-204,1,-204,2)        : 
1 -- first and second symbols of record -181 have been swapped 

In the previous set of queries, swap_symbols didn’t work when we entered the symbols as ids (-207,-219), because it wants positions (1,2). And the function didn’t work either when we tried to swap symbol 0: a format can’t be swapped.

The dangerousness of swap_symbols lies in the third parameter: symbols of two different records can be swapped. Note that swap_symbols() automatically updates user and time values for the node (not the symbol itself). Thus the order matters for swap_symbols() and its modification is recorded. There is another function that allows to swap symbols in one record only and that does not update user and time values by default, swap_links():

? select swap_links(-208,-217)
swap_links(-208,-217)
1 -- links -208 and -217 have been swapped without user and time update 
? select show_record(-204)
i a d n t u 
-204 63 -204 -201 1479498214 admin 
-201 -202 -204 -208 1479498214 admin 
-208 -207 -201 0 1479498679 admin 
-217 -219 -208 0 1479500329 admin -- links have been swapped back to their origins.

swap_links() proceeds quite differently from swap_symbols, for the field ‘a’ remains untouched while values in the navigation fields (d,n at record level) are swapped. Its parameters are directly the links ids, and swap_links() will fail if links do not pertain to the same record, or aren’t swapable like the title and the format. The definition of USERDATE_ATORDERMODIF at compile time (see on top of UnidSql.h) will enable user and time update for swap_links() if this is needed by type policy. Otherwise it is useful to have a function that can modify order of symbols without time update in links: not every error made by the administrator in symbol order needs to be registered. swap_symbols() can be reserved to users and swap_links() to admin.

[2018 edit]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s