How to use subdatabases


Subdatabases (subdbs in short) do not differ deeply from formats, but provide a type-record and thus allow subrecords to be created according to a defined structure. When subdbs are there, functions such as examplify(), subsume(), templatize() and get_subject() become available.

? select * from subdbs
i	sdb		    n	  a    t               u:
-47 ~ #Data Structure T.. ~ -49 ~ 22 ~ 1541692436497 ~ 1541692426000 ~ 
-41 ~ #Struct Template    ~ -43 ~ 21 ~ 1541692436394 ~ 1541692426000 ~ 
-33 ~ #Note Template      ~ -35 ~ 19 ~ 1541692436251 ~ 1541692426000 ~ 
-26 ~ #Class Template     ~ -28 ~ 17 ~ 1541692436121 ~ 1541692426000 ~ 
-19 ~ #Link Template      ~ -21 ~ 15 ~ 1541692435995 ~ 1541692426000 ~ 	
-9   #Table Template      ~  -5 ~  6  ~ 1541692435720 ~ 1541692426000
templatize()

There are several ways to make a subdatabase, but the safer is probably to start from an existing record, if found representative enough of the content of the wanted subdb. templatize() will copy this record and reformat it as a subdatabase definition. The original record remains untouched – until another command, like subsume() comes to make it pertain to some subdatabase. So let’s start by creating one valid record:

? select make_full_record('My subdb test','subdb test','first prop:unid-protyp-sep:first type:unid-params-sep:second value:unid-protyp-sep:second type', 'mysdbtest')
-1454	
? select send_full_record('mysdbtest',1)
-1454      822  -1455 1472973814      My subdb test	
  -1455   -1039  495   subdb test     1  0                1389820387  admin
  -1457   -1456  824   first type     0  823 first prop   1472973814  admin
  -1459   -1458  826   second type    0  825 second value 1472973814  admin

Now we can clone this to a new subdatabase:

? select templatize('mysdbtest',’my new subdb’)
-1461	
? select send_full_record(-1461,1)
-1461      827   -1462  1472974527     #my new subdb
  -1462   -1460   827   #my new subdb  1  0                 1472974527  admin
  -1463   -1456   824   first type     0  823  first prop   1472973814  admin
  -1464   -1458   826   second type    0  825  second value 1472973814  admin

A subdatabase called ‘my new subdb’ has been created here. This can be induced from the facts that the title and the name are identical, and that a new charachter has been added before the title and before the format. This charachter shown here as ‘#’, is a special mark that can’t be typed directly and makes this record seen as a subdb. Our subdatabase however needs to be populated.

subsume()
? select subsume('mysdbtest','my new subdb')
-1460	
? select send_full_record('mysdbtest',1)
-1454      822  -1455 1472973814      My subdb test	
  -1455   -1039  495   #my new subdb  1  0                1389820387  admin
  -1457   -1456  824   first type     0  823 first prop   1472973814  admin
  -1459   -1458  826   second type    0  825 second value 1472973814 admin

The record has acquired the right format now. We could have used reformat() too here for it is another way of creating a subrecord: getting the subdb id and reformatting. This manner doesn’t guarantee the new format to be a subdb (any record can be reformated to any type), nor the record to fit its template though. If we wanted to create a subrecord according to the template defined by the subdatabase record, we would have to use examplify.

examplify()
? select sql_help('examplify')
sql_help('examplify')		:
(int recid) examplify(templid|alias,title,params):
(257) examplify(SQLITE_INT|TEXT,SQLITE_INT|TEXT)
Create a new record under an existing subdb with params and alias.	

? select examplify(-1461,'another subrecord','first prop:unid-protyp-sep:first type:unid-params-sep:second value:unid-protyp-sep:second type', 'another_alias')
-1454	

examplify() creates a subrecord from an existing subdb. Now what if there is no record nor subdb ?

get_subject()

In reason of its counter-intuitive behaviour, get_subject() is sometimes written in capital letters, as a means to indicate that it is more devoted to scripting and programmation than command line usage. However difficult, get_subject() can reveal useful too. If the named subdb exists, the function can return its id and the subdb creation params are not considered. Otherwise, get_subject() operates somewhat like make_full_record(): the output is either a normal subrecord either a template and the returned value a (negative) record id.

? select get_subject(‘Unid table template’,’Unid Table Template’, ‘’, ‘’, ‘normal’)
get_subject(‘Unid Table Template’, ’Unid Table Template’, ’’, ’’, ‘normal’):
24	

The previous query is parametrised so as to return the id of an existing subdatabase named «Unid Table Template»; actually, this subdatabase is part of the default set of records available through unid-adm. The returned value is a positive format id useful for compound queries. Also, to get this behaviour – i.e. testing for the existence of a subdb by title and retrieving its id – get_subject() requires the title param to be the same as the format param. Otherwise, the function doesn’t stop at testing and creates a subrecord under that subdb.

The function would not be able to make a record having the same title as the subdb: it is a peculiarity of subdbs in Unidatab that they possess already a unique record under the same title, describing the way future subrecords are to be populated.

In ‘normal’ mode get_subject() also handles the case when a title is given, different from the format, and this format does not exist as subdatabase. Again, get_subject() astonishes us by creating a subdb and not the record it pretended to make. Of course, here, as well as with an existing subdb, a record creation invites the third parameter to be set to a type-property list like in make_full_record() while the fourth wants an alias. All this gets even gloomier when the last parameter isn’t set to ‘normal’. We won’t bother any longer with this here since for now, templatize(), subsume() and examplify() bring us what we need.

[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