Begin modifying the SalesDB application

Note

  1. If PocketBuilder is not running, from the Start Menu, select Programs>Sybase>PocketBuilder 2.5> PocketBuilder IDE to start PocketBuilder.

    Before you start developing the SalesDB application in PocketBuilder, you must specify how to connect to the database by creating a database profile. Since SalesDB is an application for the Pocket PC, you create a database profile only for the remote database.

  2. Select Tools> Database Profile.

    Select ODB ODBC in the list box and then click the New button.

    The Database Profile Settings dialog box displays.

  3. Type SalesDB_remote for the Profile Name.

    Select SalesDB_remote for the Data Source.

    Uncheck User ID and Password (since they are provided by the DSN file on the Pocket PC device).

    Shown is the Database Profile Setup dialog box for an O D B C connection. The name of the profile defined by the dialog box is Sales D B underscore remote. This is also the name for the data source. The check boxes for the User I D and Password have been cleared.
  4. Select the Preview tab to examine the database connection syntax.

    The Preview tab also has a Test Connection button you can click to test the connection.

  5. Click OK to return to the Database Profiles painter, expand the ODB ODBC, select SalesDB_remote, and click Connect.

    The SQL Anywhere remote database starts and a connection is established. You can verify this by selecting Tools>Database Profile from the menu bar. SalesDB_remote should have a green check mark next to it.

    Now you set up the Sales database workspace.

  6. Select File>New from the PocketBuilder menu bar.

    On the Workspace tab, select Workspace and click OK.

    Shown is the Workspace page of the New dialog box. The only icon displayed on this page allows you to create a new workspace.
  7. Save the new workspace as salesdb_tutorial in the \PocketBuilder 2.5 \Tutorial\SalesDB directory.

    Shown is the New Workspace name selection dialog box. The file name for the new workspace is sales d b underscore tutorial. The Save as Type entry shows the P K W extension that will be added to the workspace file name after you click Save.
  8. Select File>New and then in the Target tab, select Existing Application and click OK.

    Shown is the Project tab of the New dialog box. The Existing Application wizard icon is selected.
  9. Locate and expand salesdb_tutorial.pkl in the \Tutorial\SalesDB directory.

  10. Select the salesdb_tutorial application object and then click Next.

    Shown is the Choose Library and Application page of the Existing Application wizard. The Sales D B underscore tutorial application is selected. It is listed under the Sales D B underscore tutorial pickle in the Sales D B directory.
  11. Click Next again and then click Finish to accept the default locations.

    If prompted, click Yes to migrate the existing application to the latest version.

    The existing SalesDB application is now ready to be modified. Next you create a function called f_conn to handle the connection code.

  12. Select File -> New from the menu bar.

    In the PB Object page, select Function and then click OK.

    Shown is the P B Object page of the New dialog box. The Function object is selected. The target for the new object is sales d b underscore tutorial.

    The Function painter opens. You use the Function painter to define and code the new f_conn function.

  13. Select (None) at the bottom of the drop-down list for the return type.

    Type f_conn for the function name.

    Do not include an argument name or a Throws statement.

  14. In the script view (the code editor below the function properties), type the following code on separate lines:

    sqlca.dbms='odb'
    sqlca.dbparm="ConnectString='DSN=SalesDB_remote'"
    // establish DB connection
    
    connect using sqlca;
    

    The SalesDB_remote.DSN file establishes a connection to the SalesDB_remote.DB database. Later in this tutorial, you deploy the DSN file to a device, but on the desktop, the connection string finds the ODBC profile of the same name (SalesDB_remote) that you created earlier in this lesson.

    Here is what the definition of your new f_conn function should look like:

    Shown is the script for the function f underscore conn.  The script sets default s q l c a connection object parameters for the data source d b m s and the d b parm connect string. After setting the connect string, it establishes a database connection by calling  "connect using s q l c a". The connection call is terminated with a semicolon.
  15. Select File>Save, then OK, to save the f_conn function.

  16. Close the Function painter.

  17. Expand salesdb_tutorial.pkl in the System Tree in the file.

    In the System Tree, you can see the f_conn function that you just created.

    The f_conn function is used when the application first starts. It is called from the ue_postopen event inside the salesdb_tutorial application. The database connection is established in this event and any connection error is reported to the user. The database connection is closed when the application terminates and is handled by the f_disconn function that is provided for you.

    Next you create a DataWindow to access sales data in your application.