Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Example schema cache file creation

> The following event-driven application allows you to create partial schema cache files for any combination of tables in the sports database. The main procedure, `i-schcs1.p`, presents all the available sports database tables in a multiple selection list and a field to enter a name for the schema cache file. When you choose the Save to File button, it connects to the sports database, and calls `i-schcs2.p`, which reads the selected tables and saves the resulting schema cache file in the current working directory. The main procedure then disconnects the sports database to allow new table selections for a different schema cache file.

> i-schcs1.p
>     DEFINE VARIABLE filen AS CHARACTER FORMAT "x(8)"
>     LABEL "Schema Cache Name".
>     DEFINE VARIABLE icnt AS INTEGER.
>     DEFINE VARIABLE db-table AS CHARACTER LABEL "Select Tables"
>            VIEW-AS SELECTION-LIST
>            MULTIPLE NO-DRAG SIZE 32 BY 7
>            LIST-ITEMS "customer", "invoice", "item", "local-default",
>                       "order", "order-line", "ref-call", "salesrep",
>                       "state".
>     DEFINE BUTTON bsave LABEL "Save to File".
>     DEFINE BUTTON bcancel LABEL "Cancel".
>     DEFINE FRAME SchemaFrame
>         SPACE(1)
>         db-table
>         VALIDATE(db-table <> "" AND db-table <> ?, "You must select a table.")
>         filen
>         VALIDATE(filen <> "" AND filen <> ?, "You must enter filename.")
>         SKIP(1)
>         SPACE(20) bsave bcancel
>     WITH TITLE "Save Schema Cache File" SIDE-LABELS SIZE 80 by 11.
>     ON CHOOSE OF bcancel IN FRAME SchemaFrame QUIT.
>     ON CHOOSE OF bsave IN FRAME SchemaFrame DO:
>         ASSIGN filen db-table.
>         IF NOT filen:VALIDATE() THEN RETURN NO-APPLY.
>         IF NOT db-table:VALIDATE() THEN RETURN NO-APPLY.
>         DO WHILE NOT CONNECTED("sports"):
>             BELL.
>             PAUSE MESSAGE "When ready to connect the sports database, press
>     <RETURN>".
>             CONNECT sports -1 NO-ERROR.
>             IF NOT CONNECTED("sports") THEN
>                 DO icnt = 1 to ERROR-STATUS:NUM-MESSAGES:
>                     MESSAGE ERROR-STATUS:GET-MESSAGE(icnt).
>                 END.
>             ELSE
>                 MESSAGE "Sports database connected.".
>         END.
>         RUN i-schcs2.p (INPUT db-table, INPUT filen).
>         DISCONNECT sports NO-ERROR.
>     END.
>     ENABLE ALL WITH FRAME SchemaFrame.
>     WAIT-FOR CHOOSE OF bcancel IN FRAME SchemaFrame.

> i-schcs2.p
>     DEFINE INPUT PARAMETER db-table AS CHARACTER.
>     DEFINE INPUT PARAMETER filen AS CHARACTER.
>     DEFINE VARIABLE itab AS INTEGER.
>     Table-Add: DO itab = 1 to NUM-ENTRIES(db-table):
>         CASE ENTRY(itab, db-table):
>             WHEN "customer"         THEN FIND FIRST customer NO-ERROR.
>             WHEN "invoice"          THEN FIND FIRST invoice NO-ERROR.
>             WHEN "item"             THEN FIND FIRST item NO-ERROR.
>             WHEN "local-default"    THEN FIND FIRST local-default NO-ERROR.
>             WHEN "order"            THEN FIND FIRST order NO-ERROR.
>             WHEN "order-line"       THEN FIND FIRST order-line NO-ERROR.
>             WHEN "ref-call"         THEN FIND FIRST ref-call NO-ERROR.
>             WHEN "salesrep"         THEN FIND FIRST salesrep NO-ERROR.
>             WHEN "state"            THEN FIND FIRST state NO-ERROR.
>             OTHERWISE               LEAVE Table-Add.
>         END CASE.
>     END.
>     SAVE CACHE CURRENT sports to VALUE(filen + ".csh") NO-ERROR.
>     IF NOT ERROR-STATUS:ERROR THEN
>         MESSAGE "Saved partial schema cache for the sports database"
>                 "in" filen + ".csh.".
>     ELSE DO:
>         BELL.
>         DO itab = 1 TO ERROR-STATUS:NUM-MESSAGES:
>             MESSAGE ERROR-STATUS:GET-MESSAGE(itab) VIEW-AS ALERT-BOX.
>         END.
>     END.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095