# Q

`+QueryChart`
  In addition to the 'standard' arguments passes to charts, the +QueryChart takes two additional ones. First, the number of initial rows to fetch and second a Pilog query that retrieves data. Typically used in search dialogs, as the following example from the demo app supplied with the PicoLisp distribution.

          (de choItem (Dst)
             (diaform '(Dst)
                (<grid> "--.-."
                   ,"Number" (gui 'nr '(+Focus +Var +NumField) '*ItemNr 10)
                   ,"Supplier" (gui 'sup '(+Var +TextField) '*ItemSup 20)
                   (searchButton '(init> (: home query)))
                   ,"Description" (gui 'nm '(+Var +TextField) '*ItemNm 30)
                   ,"Price" (gui 'pr '(+Var +FixField) '*ItemPr 2 12)
                   (resetButton '(nr nm pr sup query)) )
                (gui 'query '(+QueryChart) (cho)
                   '(goal
                      (quote
                         @Nr (and *ItemNr (cons @ T))
                         @Nm *ItemNm
                         @Pr (and *ItemPr (cons @ T))
                         @Sup *ItemSup
                         (select (@@)
                            ((nr +Item @Nr) (nm +Item @Nm) (pr +Item @Pr) (nm +CuSu @Sup (sup +Item)))
                               (range @Nr @@ nr)
                               (part @Nm @@ nm)
                               (range @Pr @@ pr)
                               (tolr @Sup @@ sup nm) ) ) )
                   6
                   '((This) (list This (: nr) This (: sup) (: sup ort) (: pr))) )
                   (<table> 'chart (choTtl ,"Items" 'nr '+Item)
                      (quote
                         (btn)
                         (align "#")
                         (NIL ,"Description")
                         (NIL ,"Supplier")
                         (NIL ,"City")
                         (align ,"Price") )
                      (do (cho)
                         (<row> (alternating)
                            (gui 1 '(+DstButton) Dst)
                            (gui 2 '(+NumField))
                            (gui 3 '(+ObjView +TextField) '(: nm))
                            (gui 4 '(+ObjView +TextField) '(: nm))
                            (gui 5 '(+TextField))
                            (gui 6 '(+FixField) 2) ) ) )
                   (<spread>
                      (scroll (cho))
                      (newButton T Dst '(+Item)
                      '(nr genKey 'nr '+Item)
                      'nm *ItemNm
                      'pr *ItemPr )
                      (cancelButton) ) ) )

  The first argument to +QueryChart, `(cho)`, returns a number that decides how many rows of data should be fetched. The same call is used a little later to draw the table presenting the data as well. Following that argument is the Pilog query used to fetch the data we wish to display.

          '(goal
             (quote
                @Nr (and *ItemNr (cons @ T))
                @Nm *ItemNm
                @Pr (and *ItemPr (cons @ T))
                @Sup *ItemSup
                (select (@@)
                   ((nr +Item @Nr) (nm +Item @Nm) (pr +Item @Pr) (nm +CuSu @Sup (sup +Item)))
                      (range @Nr @@ nr)
                      (part @Nm @@ nm)
                      (range @Pr @@ pr)
                      (tolr @Sup @@ sup nm) ) ) )

  The Pilog query is followed by a number, in this case 6, that tells how many columns are used when presenting the data. This is the normal column count, as inherited from +Chart, and it matches up with the number of columns in our table.

          (<table> 'chart (choTtl ,"Items" 'nr '+Item)
             (quote
                (btn)
                (align "#")
                (NIL ,"Description")
                (NIL ,"Supplier")
                (NIL ,"City")
                (align ,"Price") )
             (do (cho)
                (<row> (alternating)
                   (gui 1 '(+DstButton) Dst)
                   (gui 2 '(+NumField))
                   (gui 3 '(+ObjView +TextField) '(: nm))
                   (gui 4 '(+ObjView +TextField) '(: nm))
                   (gui 5 '(+TextField))
                   (gui 6 '(+FixField) 2) ) ) )

  The +QueryChart in the example uses a 'put'- function to put data into the GUI components from the result of the Pilog query.

          '((This) (list This (: nr) This (: sup) (: sup ort) (: pr)))

  The 'put'- function is applied to each row and places the desired content into the GUI. Since this chart is read only, i.e. contains no input fields, the corresponding 'get'- function can be omitted. Each item in the list produced by our 'put'- function matches up with a column in the table presenting the result. The first item, `This`, is used to create a link to the object, in column 1 of the table: `(gui 1 '(+DstButton) Dst)` Item number 2, `(: nr)`, maps to the second column, showing the number of the object in question: `(gui 2 '(+NumField))` The two following items, `This` and `(: sup)` each map to a combination of +ObjView and +TextField:

          (gui 3 '(+ObjView +TextField) '(: nm))
          (gui 4 '(+ObjView +TextField) '(: nm))

  The +ObjView is used to create a link to an object, in both cases displaying the `(: nm)` property of each object. Finally, the name of the town where the supplier is located and the price of the item are displayed. The 'put'- function supplies these values: `(: sup ort)` and `(: pr)`, which are mapped to the following columns in the table:

          (gui 5 '(+TextField))
          (gui 6 '(+FixField) 2)

  See also +Chart, cho, gui, +DstButton, +NumField, diaform, +ObjView, +TextField, +FixField, charts and the select predicate.