1# Simple demo, can be used to verify proper Mk4tcl/TclKit installation
2#
3# On first run, output should consist of 5 lines:
4#   John Lennon 44
5#   Flash Gordon 42
6#   first Flash last Gordon shoesize 42
7#   first John last Lennon shoesize 44
8#   first John last Lennon shoesize 44
9#
10# Every following run will generate 5 more lines of output
11
12package require Mk4tcl
13
14  # create a file called "demo.db"
15mk::file open db demo.db
16  # define a view in it called "people", containing three fields
17set vw [mk::view layout db.people {first last shoesize:I}]
18
19  # let's append two rows to the end of the view
20mk::row append $vw first John last Lennon shoesize 44
21mk::row append $vw first Flash last Gordon shoesize 42
22
23  # commit the structure and data to file
24mk::file commit db
25
26  # a simple loop to print out all rows
27mk::loop c $vw {
28  puts [mk::get $c first last shoesize]
29}
30
31  # another way to loop, in sorted order
32foreach r [mk::select $vw -sort last] {
33  puts [mk::get $vw!$r]
34}
35
36  # this loop iterates over a selection
37foreach r [mk::select $vw first John] {
38  puts [mk::get $vw!$r]
39}
40