programming.nbk: Home | Index | Next Page: Tcl Mk4Tcl: Reading/Writing from Tcl Arrays | Previous Page: Tcl Mk4Tcl: Iterating over rows


 Tcl Mk4Tcl: Queries

Queries

If you're searching for only particular data items, its possible to do it simply by iterating over each row and comparing the row's properties to what you're looking for. However, its easier and more efficient to use the "mk::select" command, which will do the work of searching through the rows for you.

The mk::select command will search through the rows in a view and return a list of row numbers matching a given search criterion. So to search for all employees with a salary of 10, we could do the search, and iterate over these rows to print their names:

    set rownums [mk::select db.employees salary 10]
    foreach i $rownums {
        puts [mk::get db.employees!$i name]
    }

The search criterion is specified as a property followed by its value. To search for rows matching multiple criterion you can specify multiple property/value pairs (e.g. "salary 10 name Mark"), where all of the properties must match. The default matching is case-insensitive.

Other Options

You can also specify other search options, beyond just a simple check if a property equals a given value ("property value"). These include:

You can also sort the results according to the value of a property ("-sort property" or reverse ordered sort with "-rsort property"). There are also other options allowing you to choose the maximum number of results to return, at what index to start the search, and so on. See the reference manual for details.

Next: Tcl Mk4Tcl: Reading/Writing from Tcl Arrays


programming.nbk: Home | Index | Next Page: Tcl Mk4Tcl: Reading/Writing from Tcl Arrays | Previous Page: Tcl Mk4Tcl: Iterating over rows


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