next up previous contents
Next: 7.4 Retrieving and displaying Up: 7 Writing Qddb Applications Previous: 7.2 QTcl Commands

7.3 Searching

Qddb provides a plethora of searching techniques. You can search by word, numbers, dates, ranges, and regular expressions. You can tell Qddb what a word looks like with the separators option in the Schema. You can also prune the resultant keylist of uninteresting attributes, in effect searching on a particular attribute.

The qddb_search command returns a keylist descriptor. This keylist descriptor can then be (1) used to produce rows matching the query, (2) combined with other keylists using intersection, union, and exclusion, (3) pruned of duplicate rows or entries, (4) copied and sorted, and (5) used to directly read tuples.

Example:

Suppose you have a relation ``MyRelation'' and you want to print a list of all tuples that match the word range ``r-z'' in an attribute named ``A''. You aren't interested in rows, but in entire tuples. You also only want to print each tuple once and in readable form.

 
    set s [qddb_schema open MyRelation] 
    set k [qddb_search $s -prunebyattr A word_range r - z] 
    set k [qddb_keylist process nullop -deldup_sameentry on] $k
    foreach i [qddb_keylist get $k] { 
        set t [qddb_tuple read $s $i] 
        if {[string length $t] == 0} {continue}
        puts [qddb_tuple get readable $t] 
        qddb_tuple delete $t 
    }
    qddb_keylist delete $k 
    qddb_schema close $s

First, we open the schema and search for a word range ``r-z'' within attribute ``A''; the qddb_search command returns a keylist that we use to find the matching tuples. We may have multiple keylist nodes for any individual matching tuple, so now we must prune the keylist of all nodes referring to the same entry. Finally, we walk through the keylist and (1) read the tuple, (2) check to see if the tuple we read is valid (not deleted), (3) print the tuple in readable form, and (4) delete the tuple from memory. Notice that we did not lock the tuple before we read it. This is because Qddb takes care of read locks for you. A qddb_tuple read (or any other Qddb command that reads a tuple) will wait for any writes to complete before reading. Read and write operations are atomic in Qddb, so even if the tuple is locked for writing, you will still be able to read it. You only need to invoke qddb_tuple lock before writing a tuple.


next up previous contents
Next: 7.4 Retrieving and displaying Up: 7 Writing Qddb Applications Previous: 7.2 QTcl Commands

Herrin Software Development, Inc.