Download Quick Tutorial - Using the Database Object

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Relational algebra wikipedia , lookup

SQL wikipedia , lookup

Commitment ordering wikipedia , lookup

Global serializability wikipedia , lookup

Microsoft Access wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Serializability wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Oracle Database wikipedia , lookup

IMDb wikipedia , lookup

Functional Database Model wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Ingres (database) wikipedia , lookup

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Concurrency control wikipedia , lookup

Relational model wikipedia , lookup

Versant Object Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

ContactPoint wikipedia , lookup

Transcript
Quick Tutorial - Using the Database Object
Description: This tutorial will expand on the use of expressions and demonstrate the simple adding, deleting
and modifying of records in the database.
Resources: DBOStart.bsp, DBOFinished.bsp
The Database Object
Writing to the database through expressions is handled by the Database object and its methods in the data
source tree, located under Objects > Database. As seen below, there are numerous methods available for use,
however, in this tutorial we will cover using the object for add, modify and delete functionality and the
methods associated with this.
These methods usually take in values of table names, columns, queries and parameters in String format,
which can either be entered in manually, or conveniently found under the Names folder of the data source tree.
For more information on the other database methods listed, please consult the Bright Software Object
Definitions manual.
It is advised to reset the database object before any add, delete or modify operations are called, to reset the
internal structures of the database object. This method is to be called before any Database methods.
Adding Records
Records may be added to tables using both the AddColumn() and AddRecord() methods. Using these
methods creates a temporary record which is then added to the table specified by AddRecord().
If the constraints of the table are not met, the AddRecord() method will not update the tables, for example, if a
Primary Key is not specified or if it already exists, or if non-existent columns are specified with the
AddColumn() methods. If nulls are allowed in a table, they may be omitted when the AddColumn() methods
are called.
Page | 1
www.brightxpress.com
Example Expression:
id_field = NumberGenerator.GetUniqueNumber();
Database.Reset();
Database.AddColumn("ID", id_field);
Database.AddColumn("NAME", name_field);
Database.AddColumn("DESCRIPTION", desc_field);
Database.AddRecord("TABLE1");
Modifying Records
Modifying records in a database requires a query to specify what records need to be modified. It uses the
SetQueryParam() method to set the parameter (if necessary) and UpdateRecords() with the query name in
order to do this. Any modify expression with an invalid parameter or one which is not specified will not
update when UpdateRecords() is called.
All rows returned by the query can then have their column values replaced if the AddColumn() method is
called. UpdateRecords() then takes these rows with replaced values and updates the parent table of the query
specified accordingly. Records will not be updated if the columns in the temporary table are not a subset of
the parent table.
Page | 2
www.brightxpress.com
Example Expression:
Database.Reset();
Database.SetQueryParam("pItemID", id_field);
Database.AddColumn("NAME", name_field);
Database.AddColumn("DESCRIPTION", desc_field);
Database.UpdateRecords("qItemFilter");
listview1.Refresh();
Deleting Records
Similar to modifying records in the database, deletion is handled by queries and a method. Any records
returned by the query will be deleted from the parent table of the query. Below is a sample expression which
demonstrates this. Please note that there are two types of delete methods available in BrightBuilder. The one
below demonstrates the deletion of records that will be reflected on the server database - DeleteRecords(). If
records are to be deleted locally, use the DeleteRecordsLocally() method.
Example Expression:
Database.Reset();
Database.SetQueryParam("pItemID", id_field);
Database.DeleteRecords("qItemFilter");
listview1.Refresh();
Page | 3
www.brightxpress.com
Exercise
Replicate the following behaviour when the listed buttons are clicked in DBOStart.bsp.
Button
Pre-Click
Post-Click
Enter in any values for the name and
description. You may also enter in an
ID but this will not be used.
A new entry should be created, with a
randomly generated ID (from the
NumberGenerator object)
Enter in the ID generated in the
previous step, referenced from the list
view. Then specify a new name,
description or both. Click the modify
button.
The entry in the listview should
change to the newly specified values.
Enter in the generated ID and then
click the delete button.
The value should be removed from the
listview below.
Add
Modify
Delete
Note, all these expressions from the screenshots end with the resetting of the id, name and desc fields with:
listview1.Refresh();
id_field = "";
name_field = "";
desc_field = "";
Also, try producing error messages when no ID is entered, and modify/delete is called.
Page | 4
www.brightxpress.com