Database Management for Smalltalk

Example Query

Example Query

 
Here Is an example of a query using a VirtualDictionarySet.  In addition to the usual methods inherited from Collection, DictionarySets respond to query component messages which answer sets of objects, which can then be intersected with other such sets or processed sequentially by the usual enumeration methods, to build complex queries.  The use of temporary variables, such as emps and average here, allows completely general queries not even possible in SQL.

This example collects a set of tuples of named property values related to selected employees.  In evaluating the sub-queries, the VirtualDictionarySet Employees, will use its dictionaries for the message selectors manager and salary, for fast indexed access.  If no such keys were defined it would instead enumerate its contents sequentially to achieve the same result.

If the message #select: aBlock is sent to a VirtualDictionarySet, it answers, as would be expected, a new VirtualDictionarySet with dictionaries on the same keys as the receiver, but containing only those content objects for which aBlock evaluates to true.  However, #collect: aBlock returns a Set.
  | emps average |
  [ Employees collect:
    [:emp |
      ( emp salary > 50000 or:
        [ emps := Employees for: #manager equals: emp manager.
          average := ( emps inject: 0
                              into: [:total :e | total + e salary]
                     ) // emps size.
          emp salary > (1.5 * average) or:
            [ ( Employees for: #salary
                      between: (emp salary min: average)
                          and: (emp salary max: average)
              ) size < (Employees size // 10)
            ]
        ]
      )
      ifTrue:
        [ Dictionary new
            at: #empno put: emp empno;
            at: #empname put: emp name;
            at: #salary put: emp salary;
            at: #manager put: emp manager name;
            at: #average put: average;
            at: #averageOf put: emps size;
            yourself
        ]
     ]
  ] atomicReadOnly



 
  • Viagra ordre
  • Cialis en ligne
  • Levitra en ligne
  • Propecia acheter
  • Viagra acheter
  • Acheter cialis
  • Ordre levitra
  • Ordre propecia
  • En ligne viagra
  • Vente cialis
  • Levitra bon marche
  • Propecia en ligne
  • Viagra online
  • Buy cialis
  • Order Levitra
  • Buy propecia
  • Buy viagra
  • Cheap cialis
  • Cheap Levitra
  • propecia online
  • Viagra prescription
  • Cialis online
  • Buy Levitra
  • Order propecia