programming.nbk: Home | Index | Next Page: Tcl Mk4Tcl mk::view layout | Previous Page: Tcl Mk4Tcl mk::select


 Tcl Mk4Tcl mk::view

mk::view

View structure and size operations

SYNOPSIS mk::view layout tag.view mk::view layout tag.view {structure} mk::view delete tag.view mk::view size path mk::view size path size mk::view info path

Description

The mk::view command is used to query or alter the structure of a view in a datafile (layout, delete), as well as the number of rows it contains (size). The last command (info) returns the list of properties currently defined for a view.

The 'mk::view layout' command returns a description of the current datastructure of tag.view. If a structure is specified, the current data is restructured to match that, by adding new properties with a default value, deleting obsolete ones, and reordering them.

Structure definitions consist of a list of properties. Subviews are specified as a sublist of two entries: the name and the list of properties in that subview. Note that subviews add two levels of nesting (see phones in the phonebook example below). The type of a property is specified by appending a suffix to the property name (the default type is string):

Properties which are not listed int the layout will only remain set while the datafile is open, but not be stored. To make properties persist, you must list them in the layout definition, and do so before setting them.

The 'mk::view delete' command completely removes a view and all the data it contains from a datafile.

The 'mk::view size' command returns the number of rows contained in the view identified as tag.view. If an argument is specified, the size of the view is adjusted accordingly, dropping the highest rows if the size is decreased or adding new empty ones if the size is increased. The command 'mk::view size 0' deletes all rows from a view, but keeps the view in the datafile so rows can be added again later (unlike 'mk::view delete'.

The 'mk::view info' returns the list of properties which are currently defined for path.

Note that the layout and delete sub-commands operate only on top-level views (of the form tag.view), whereas size and info take a path as arguments, which is either a top-level view or a nested subview (of the form 'tag.view!index.subview!subindex...etc...subview').

EXAMPLES

Define a phonebook view which can store more than one phone number for each person: 
    mk::view layout db.book {name address {phones {category phone}}}
Add a new phonebook entry: 
    mk::row append db.book name "Steve" address "Down-under"
Add two phone numbers to phone book entry zero, i.e. "Steve": 
    mk::row append db.book!0.phones category "home" phone "1234567"
    mk::row append db.book!0.phones category "mobile" phone "2345678"
Restructure the view in the datafile, adding an integer date field: 
    mk::view layout db.book {name address {phones {category phone}} date:I}
Delete all phonebook entries as well as its definition from the datafile: 
    mk::view delete db.book

programming.nbk: Home | Index | Next Page: Tcl Mk4Tcl mk::view layout | Previous Page: Tcl Mk4Tcl mk::select


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time