How to create a record

In the previous example we were trying to append a symbol to a record called ‘myrecord’. Let’s see how to create this record.

We can do this conveniently through make_record():

? select make_record('myrecord','test')

How does this new record, which only has a title and a format, look like:

? select send_full_record(-204,1)
-204 63 -201 1468769339 myrecord 
-201 -202 64  test       1      0  1468769339 admin
? select * from unid_node where i = -204
a     d     i     n    t          u :
63  -204  -204  -201  1468769339 admin
? select * from node where i = -201
a      d     i    n    t          u :
-202 -204  -201   0   1468769339 admin 

The title

At the record level, one has to consider the table node as a chain which begins with the first node and ends in the last one. Except in the first node, which necessarily targets positive data  for its title string (a=63=’myrecord’), the field ‘a’ otherwise contains only symbol ids.

The field ‘n’ (like ‘next’), in a record, always contains the next node or 0 at the end of the chain.

The field ‘d’ normally contains the id of the previous node in the record chain except in the first node where d equals the identification number (field ‘i’).

What is a format?

The record we have created so far only has a title and a symbol entry called ‘format’. Sometimes we call the meta-symbol constituted by this node pair, Format too. There is no difference in the columns of table node and table symbol used here, and we have to look inside the special symbol that constitutes a format (field ‘a’=-202) to learn how it looks:

? select show_symbol(-202) :
i        a     d   n    t             u                       
-202    64   1   0    1468769339    admin    test    

This function normally prints out two literal content values but one here (‘test’), as a format is a symbol with only one side.

How to append content

If we have a symbol ready to append to this new record we can do this as before or otherwise by issuing a composed command like:

? select ink_record('myrecord',get_symbol('myprop','mytype',0)):

But this won’t work because our record hasn’t got an alias set already. So we should change the previous command as:

? select ink_record(-204,get_symbol('myprop','mytype',0)):
ink_record(-204,get_symbol('myprop','mytype',0))        :

or set an appropriate alias beforehand:

? select set_alias(-204,'myrecord'):

This would work too:

? select ink_record(set_alias(-204,'myrecord'),get_symbol('myprop','mytype',0)):

Note that here our alias string is the same as our title string but many other strings without spaces or special characters would be accepted as aliases.

Finally we can define an UnidSQL oneliner for the creation of a record with one alias and one symbol:

? select ink_record(set_alias(make_record('My record title','my record type'),'myalias'),get_symbol('title, format, alias and symbols can always be modifed while the record itself can only be created and deleted','unidatab objects',0))

This compound command can be run with an easier syntax and function make_full_record():

? select make_full_record('My record title','my record type','A shorter property:unid-protyp-sep:unidatab objects:unid-params-sep:another property:unid-protyp-sep:undefined type','myalias2')

make_full_record() requires the special string separators (‘:unid-protyp-sep:’ and ‘:unid-params-sep:’) and is handy as long as we don’t want to set a value to a node or data number. In this case, the function can still run but requires some special characters that will be described later. The simpler function make_record() accepts a format id directly.

Remark on aliases

The definition of an alias is never mandatory, it is only a mnemotechnic means. A record can have zero or more aliases, but a given alias only points to one record (set_alias() reattributes an existing alias to a newer target).

[2018 edit]


Leave a Reply

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

You are commenting using your 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