Tips_tutorials   >   Studio101   >   Getting Started

Getting Started

In this section of the tutorial we we will prepare the folders and add the files needed for a Contacts application which we will be building. We will also create a table in the database and insert some records.

You will need a developer version of Omnis Studio. The standard edition v4.0 is the minimum version.

One of the features I really like about Omnis Studio version 4 is the notation helper. It save a lot of keystrokes. I find the default setting of 1000 milliseconds a bit slow and recommend you reduce the setting to 50 milliseconds.

  1. Open the Omnis Studio Preferences > Property Manager window > General tab
  2. Set the $notationhelptimer value to 50

Create Folders

We need to create some folders on your computer's hard drive to contain the Omnis Studio library and data file which we are going to create.

  1. Create a new folder on your desktop.
  2. Name the new folder Contacts. The Omnis Studio library will be contained in this folder.
  3. Create a subfolder inside the Contacts folder.
  4. Name the subfolder data. The Omnis Studio data file will be contained in this subfolder.

Once the files are added the folder/file structure will be as follows:

FoldersFiles.gif

Create Library

We need an Omnis Studio library to contain the classes and code which make up our Omnis Studio application.

  1. Open Omnis Studio.
  2. F2 Browser > select Libraries node > click New Library.
  3. Navigate to the Contacts folder on your desktop and enter Contacts.lbs for the library name.
  4. Click the Okay button. Omnis Studio creates the new library file and opens it. You will see a Contacts library in the F2 Browser treelist.

    By default the library name matches the file name. If the file name changes, so does the library name. Changing the library name causes problems in multi-library applications, so it is a good practice to set the $defaultname library property.
  5. Select the Contacts library in the treelist > F6 Property Manager > Prefs tab.
  6. Enter Contacts in the $defaultname property.

defaultname.gif

Create Data File

We need a database to store the records created by our Omnis Studio application. The database could be any third party RDBMS. For this tutorial will be we using the Omnis data file for the database.

  1. F2 Browser > select SQL Browser > click Session Manager.
  2. Select the OMNISSQL session and click Duplicate Session.
  3. Double-click the duplicate session to edit the session settings.
  4. Change the session name to CONTACTS.
  5. Click the Create new data file button. (The file cabinet button at the end of the Host Name entry field.)
  6. Navigate to the Contacts/data subfolder.
  7. Enter ContactsData.df1 for the data file name and click the Okay button. Omnis Studio will create the data file and the path to the data file will appear in the Host Name entry field.

    SessionManager.gif

  8. Click the Okay button.
  9. Click the Back button.
  10. Click the Open Session button.
  11. Click the CONTACTS session. Omnis Studio will open a SQL session with the ContactsData.df1 data file and CONTACTS will appears as a child node of SQL Browser in the F2 Browser treelist.

    SessionManager.gif

The SQL Browser is a handy tool to use for testing connections to SQL databases, testing SQL scripts, checking for records inside tables, etc. The SQL Browser is for use by developers, not runtime users. For runtime users we will need connect to the database using a session object. Connecting to the database using a session object will come later in the tutorial.

Create a Table from a Schema Class

Within the database we need to create tables. Each table stores a set of records.

Tables have columns. The columns store specific fields of information about each record.

To begin we will create a Country table for storing the names of different countries. There are numerous ways of creating tables in Omnis Studio.

First we will create the Country table by creating a schema class and then dragging the schema class on to the CONTACTS session in the F2 Browser.

  1. F2 Browser > select Contacts library > click New Class > click Schema.
  2. Name the new schema, sCountry.
  3. Double-click the sCountry schema class.
  4. Enter Country as the Server table or view.
  5. In row 1 of the schema class enter the following:
    Column name - Country_pkey
    Data type - Number
    Data subtype - Long integer
    Primary key - kTrue
    No nulls - kTrue

    This is the primary key column. The primary key must be unique for each record in the table. The primary key is normally hidden from the user and once created is normally never changed.
  6. In row 2 of the schema class enter the following:
    Column name - CountryName
    Data type - Character
    Data subtype - 30
    Primary key - kFalse
    No nulls - kTrue

    sCountry.gif

  7. Close the sCountry schema class.
  8. F2 Browser > select sCounty and drag it onto the CONTACTS session of the SQL Browser node. Omnis Studio will automatically create the Country table in the ContactsData.df1 data file with the columns specified in the schema class.
  9. F2 Browser > SQL Browser > CONTACTS > Tables > select Country > click Modify Table.

    sCountry.gif

  10. You will see that Omnis Studio has created the table with the columns specified in the sCountry schema class. One problem with this technique of creating tables from schema classes is that Omnis Studio does not create any indexes or constraints for you. If you click the Indexes tab in the Alter Table window you will see that no indexes have been created. The primary key should always have a unique index, and in this table we want the CountryName to also have a unique index. The indexes will have to be added using SQL scripts.
  11. Close the Alter Table window.
  12. F2 Browser > select the Country table > click Delete Table > click Yes to delete the table.

Create a Table using SQL

This time we will create the Country table using SQL.

  1. F2 Browser > SQL Browser > select CONTACTS session > click Interactive Sql
  2. Enter the following SQL script in the Interactive SQL window:

    CREATE TABLE Country (Country_pkey INTEGER NOT NULL,CountryName VARCHAR (30) NOT NULL)



    InteractiveSQLCreateCountry.gif

  3. Click the Run button to execute the SQL script.
  4. Enter the following SQL script in the Interactive SQL window to create a unique index on the primary key column:

    CREATE CASE SENSITIVE UNIQUE INDEX Country_pkey ON Country (Country_pkey)

  5. Click the Run button to execute the SQL script.
  6. Enter the following SQL script in the Interactive SQL window to create a unique index on the CountryName column:

    CREATE CASE SENSITIVE UNIQUE INDEX CountryName ON Country (CountryName)

  7. Click the Run button to execute the SQL script.
  8. F2 Browser > SQL Browser > select CONTACTS session > Tables > select Country > click Modify Table
  9. This time if you click the Indexes tab in the Alter Table window you will see the unique indexes which were created by the SQL scripts which we executed.
Note

The above SQL scripts used to create the unique indexes is specific to the Omnis data file. For creating unique index constraints on other databases check the documentation specific to the RDBMS.

Insert Data

Insert some data into the Country table using the SQL Browser.

  1. F2 Browser > SQL Browser > select CONTACTS session > click Insert Data
  2. Enter the following:

    Country_pkey - 1001
    CountryName - Australia
  3. Click the Insert Data button.
  4. Close the Insert Data window.
  5. Click Show Data. The country which you entered should show up in the list.

Insert some more data into the Country table using SQL scripts.

  1. F2 Browser > SQL Browser > select CONTACTS session > click Interactive Sql
  2. Enter the following SQL script:

    INSERT INTO Country VALUES (1002,'Canada')

    Be sure to include the quotes around the country name.
  3. Click the Run button.
  4. Repeat the above steps for:

    INSERT INTO Country VALUES (1003,'UK')
    INSERT INTO Country VALUES (1004,'USA')
  5. Close the Interactive SQL window.
  6. Click Show Data. The countries which you entered should show up in the list.

Summary

In this section of the tutorial we have completed the following:

  1. Created the folders which contain our Contacts application.
  2. Created a library which wil contain the classes and code for our application.
  3. Created a database to store information for our application.
  4. Created a Country table in the database using SQL.
  5. Added some country records to the table using SQL.
We are now ready to start creating the visual classes in the Contacts library which users will use to interact with our application.