
Programming i!-Database Plus
10
i!-Database Plus and DBWizard
(***********************************************************)
(* TYPE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_TYPE
(* TITLES *)
STRUCTURE _sDB_TITLES
{
CHAR strArtist[128]
CHAR strCopyright[128]
CHAR strLabel[128]
CHAR strReleaseDate[128]
CHAR strTitle[128]
SLONG slTitleID
}
The next section creates NetLinx variables needed to store the data and connect to the database.
The
sDB_CLIENT
variable contains information about the current database transaction, the location
of the web server database script. The
sDB_QUE
variable keeps track of all database request and
makes sure the script is sent one request at a time. The
sDB_TITLES
variable is an array of the
sDB_TITLES
structure to hold the data from the database. In order to keep track of the discs in the
window, an
sDB_LISTBOX
structure is needed.
(***********************************************************)
(* VARIABLE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_VARIABLE
(* QUE VARS *)
VOLATILE _sDB_CLIENT sDB_CLIENT (* DB CLIENT *)
VOLATILE _sDB_QUE sDB_QUE (* dB QUE *)
(* DATABASE STRUCTURES *)
_sDB_TITLES sDB_TITLES[10] (* TITLES *)
_sDB_LISTBOX sTitleListBox
The next section creates four calls to delete, add, update and read information in the database. It is
here that we need our SQL and database setup information. When building SQL statements, you
need to know the names of the tables and/or view and usually the names of any columns you are
interested in reading or writing.
Another key piece of information is which column(s) in a table are the primary keys. Each record in
a database usually has a unique column called the primary key. This field is unique for this entry in
a given table. When deleting or updating a record in a database, you should reference the primary
key of the table to make certain it is the record you are interested in modifying.
TitleID
is the
primary key in our example.
When adding to a database, we may also need to provide a value for the primary key. In this case,
you must supply a key that is not currently used. Many databases offer a column typed called
AutoNumber
. This is usually used as a unique key that automatically increments every time you
add a record to the database. When using
AutoNumber
types for your primary key, you do not need
to specify the value since it is automatically generated.
All of these calls generate an SQL statement to run against the database. Some people may find this
part the hardest since SQL may be a new language to many people. If you are having trouble with
SQL, refer to the
Structure Query Language (SQL)
section on page 5.