Chapter 6 Wrapped Class Reference

6.6 Database

The Database (DB) wrapped classes provide multi-database support for object-oriented multimedia. The addition of database functionality allows the application author to decouple the application code from the application data, allowing the easy update of data and reuse of code. It also allows the application to provide easy access to many existing data repositories. Therefore, it is very important that an application provide easy access to many existing data repositories. It is also important that an application be able to interact, perhaps simultaneously, with a wide variety of existing database systems. The advantages of providing a generic database interface for use by the application author are twofold. The same application code can be used to access multiple database systems and there is no need for the author to spend time learning several different database access interfaces. AM2 DBclasses support the following database packages:

Documentation for the following classes appear in this section:

Note that the class inheritance tree diagram for the Database (DB) wrapped classes is relatively flat, meaning that these classes share very few inheritance relationships, thus no inheritance diagram is provided here.

6.6.1 DBdatabase

This is the principle class and represents a connection to a component database. Methods are available on the class to perform schema identification and modification, to control query execution, transaction management and to store application objects in the component database.

Superclasses

Section 6.1.2, "Activity Manager - Abstract" page 116

Section 6.1.3, "Attribute Manager - Abstract" page 118

Methods

on AddAttribute: string className, string attrName, string attr return boolean

Adds an attribute attrName of type attrType to the class className. In a relational database this is equivalent to adding a field to a table. Returns TRUE if the attribute is added to the class, otherwise FALSE.

on Commit

Sends a commit transaction message to the database which saves all changes made to the database since the last commit and automatically begins a new transaction. Commit must be called before a DBdatabase instance is destroyed if changes are to be saved. Only applies to those database systems that support transactions.

on CreateAppObj: string className, list arguments return handle

This method returns a handle to an application object of type className constructed on the heap. The method is used to create instances of classes retrieved from the database. For example, it can retrieve a row from a database table or the results from a query. The number and type of the values in arguments determines which constructors are used. If there are no arguments, the default constructor is used.

on CreateClass: string className, list attributes return boolean

Causes the creation of a new class called className in the schema database. The list attributes contains a list of lists. Each of these sublists is made up of two strings. The first item specifies the attribute name and the second item specifies the attribute type. Returns TRUE if the class is created, FALSE if creation fails.

on CreateObj: string className, list attributes, list data return handle

Creates an instance of the class className in the database and returns a handle to the newly created database object. The returned handle will be a handle to an object of class DBobject. The list attributes contains a list of attribute names for which initial data values will be specified and the data contains the corresponding data values in the order specified in the list of attribute names.

on CreateSubClass: string className, list superClasses, list attributes return boolean

Similar to CreateClass, but allows the specification of a list of superclasses, which contains the list of class names from which the newly created class should inherit. The list may contain no class names. The list of attributes contains additional attribute names for which data values will be entered. Returns true upon successful creation of the subclass classname, and false otherwise.

on DeleteClass: string className return boolean

Removes the definition of the class named className from the database schema. Returns TRUE if successful, otherwise FALSE. Also necessarily removes all objects of this class.

on Execute: handle hQuery return handle

Executes the query specified by hQuery, a handle to an object of type DBquery. The query specification is pre-processed appropriately for the component database type before the query is executed. A handle to a DBcursor object is retuned from which the results may be retrieved.

on ExecuteStr: string query return handle

The string query is send directly to the database for execution. No pre-processing of the query is carried out. A handle to a DBcursor object is returned.

on GetAllClasses: return list

returns a list of the names of all the classes/tables in the component database

on GetBaseClasses: return list

Returns a list of the names of all the base classes (classes that have no superclasses) that are defined in the database schema.

on GetPersistentRoot: string rootName return handle

Returns a handle to the database object pointed to by the persistent root named rootName, or NULL if the root does not exist in the database. The handle is to an object of class DBobject.

on GetPersistenRoots: return list

Returns a list of the names of all the persistent roots defined in the database. The list will be empty if no roots are defined or if the database does not support the notion of persistent roots.

on Login: string userName, string password return boolean

Enables the user to specify a username and password when connecting to the database. This method is usually called before a connection to the database is opened. However, it may be called before and/or after Open. It can also be called later to change the username under which database operations are carried out. Returns TRUE if the username and password are accepted successfully and false otherwise.

on Open: string databaseName, string server, string location, string type return boolean

Opens a connection to the component database named databaseName that is located on the machine specified in the string server and can be located by means of the string location. If the string containing server is an empty string then the database is presumed to reside on the local machine. Similarly, location is an empty string when it is not required to specify the component database. The string type specifies which type of database is being used. Currently, the supported types for UNIX are ODBC, O2, PG95, UniSQL, and MSQL. The supported types for Windows NT include Oracle, dBase, Foxpro and MS Access. A description of each type available is located after the class interface descriptions. The method returns TRUE if a connection is established and FALSE if the connection fails.

on Store: handle hObject return boolean

Stores an ADL object instance, referenced by the handle hObject, in the database so that it can be retrieved later. The class information for the object to be stored is stored first only if this is the first instance of that class to be stored in the open database. Returns TRUE if the object is stored successfully.

on StoreAs: handle hObject, string objName return boolean

Similar to Store, but stores the object specified by the handle hObject along with a persistent name objName. This persistent name, objName can be used as an identifier during retrieval.

on StoreClassOnly: handle hObject return boolean

Stores only the ADL class definition for the object retrieved by the handle hObject. It doesn't store individual instance information. Returns TRUE if the class definition is stored successfully.

on RefreshStructure

Reread the database schema definition from the database. This is only necessary if updates are made outside of the multidatabase environment. Changes made within the environment are automatically reflected in the schema.

on Retrieve: handle hObject, list theList return handle

Retrieves an ADL object instance from the database which is referenced by the database handle hObject. The list is used to hold special constructor arguments, such as handle to a parent widget when a widget object is being retrieved. Returns a handle to the retrieved object.

on RetrieveByName: string className, string objName, list theList return handle

Retrieves an ADL object instance from the database which is of class className and identified by the persistent name objName. If the object cannot be found in the database a NULL handle is returned.

on RetrieveClassOnly: string className, handle parentClass return handle

Retrieves the definition of the application class className from the database and loads it into the environment so that instances of that class can be created. The class is created as a nested class of parentClass. A handle to the class is returned. This handle will be NULL if the class is not successfully created.

Attributes

None

Activities

None

Example

1 DBdatabase dbase; // variable declarations

2 list classes, attrs;

3 string class;

4 boolean done;

5

6 // login to the database with a username and password

7 done = {'Login, 'user, 'password} => dbase;

8 // open the unisql database called myDatabase

9 // the unisql server must be running

10 done = {'Open, 'myDatabase, 'UNISQL} => dbase;

11 if(done){

12 classes = 'GetAllClasses => dbase

13 for class in classes{

14 // list of class attributes

15 attrs = {'GetAttributes, class} => dbase;

16 }

17 // create an instance of class person and give the

18 // attribute name an initial value of "joe"

19 // the class and attribute must be valid for the

20 // database "my Database"

21 {'CreateObj, 'person, {'name}, {'joe}} => dbase;

22 // save the changes to the database

23 'Commit => dbase;

24 }

6.6.2 DBclass

This class represents a class definition within a component database. This class has superclass, attribute, method, key and extent properties associated with it. Methods are provided to access these properties.

Superclasses

None

Methods

on GetAttributes: return list

A list of attributes defined for the class is returned. The list is composed of two sublists. The first sublist is a list of attribute names. The second is a list of the data types of these attributes.

on GetMethods: return list

Returns a list of all the methods defined for the class. The returned list contains a sublist for each method. This sublist itself contains three elements. The first element is the name of the method. The second is a string specifying the return type of the method. The third element is a list of strings specifying, in order, the parameter types for the method.

on GetSubClasses: return list

Returns a list of the names of all the subclasses of the class.

on GetSuperClasses: return list

Returns a list of the names of all the superclasses of the class.

Attributes

None

Activities

None

Example

None

6.6.3 DBobject

This class represents a database object. The object will be an instance of a particular database class, which can be found from querying the object. The object has methods which allow manipulation of its attributes and methods.

Superclasses

None

Methods

on Name: return string

Returns the class name of the object class to which the object belongs.

on GetAttribute: string attribute_name return any

Returns the value of the specified attribute for that object.

on SetAttribute: string attribute, any value return boolean

Set the value of the named attribute to value and returns TRUE if successful assignment.

on Call: string method_name, list arguments return any

Calls the specified method on the object using the list of arguments specified and returns the result of the method invocation.

on Drop: return boolean

Deletes the object from the database and returns TRUE if the action was successful.

Attributes

None

Activities

None

Example

1 DBdatabase dbase; // variable declarations

2 handle hObj, hCursor;

3 list result;

4

5 // don't forget to open the database etc.

6 // execute a query that returns an object handle

7 hCursor = {'ExecuteStr, "select person from person"} => dbase;

8 result = 'Next => hCursor;

9 hObj = at(1, result);

10 // fine the value of the name attribute

11 echo({'GetAttribute, 'name} => hObj);

12 // delete the object from the database

13 'Drop => hObj;

14 // save the changes

15 'Commit => hObj;

6.6.4 DBset

This class represents the set data type. A set is used to hold a collection of data types. Duplicate data types are allowed within the set. To the ADL programmer, a set can be viewed as a list of database objects or values.

Superclasses

None

Methods

upon Create: list values

Creates a DBset and initializes its contents to the values found in the list. The contents of the list must be a database-recognized type, such as integer, real, etc. (toDTobject, DTdate etc.).

on GetList: return list

Returns the set in the form of a list.

on SetList: list values

Sets the contents of the set to the values in the list.

on AddElement: any value

Adds an element to the set of the specified type and value.

Attributes

None

Activities

None

Example

1 DBset {'Create, {'dum,'dee}} => set;

2 // add the integer 3 to the set

3 {'AddElement, 3} => set;

4 values = 'GetList => set;

5 // values should now be {'dum, 'dee, 3}

6.6.5 DBcursor

This class is used to access the results of a query execution. The class also provides information as to the format of the query result set. Each entry in the result set is represented as a list. The cursor class can be thought of as a pointer that moves forward and backwards in this list.

Superclasses

None

Methods

on Success: return boolean

Returns TRUE if the query executed successfully, otherwise FALSE. This value should be checked before attempting to retrieve the results.

on RowCount: return integer

Returns the number of entries in the result set.

on ColumnCount: return integer

This method returns the number of elements in an entry of the result set.

on TypeList: return list

Returns the data types of the elements of a result entry.

on Next: return list

Moves the cursor forward one entry in the result set and returns the value of that entry. Initially Next returns the data values for the first row of the cursor. If Next is used beyond the number of result rows in the cursor, an empty list is returned.

on Prev: return list

Moves the cursor to the previous entry in the result set and returns that entry. If Prev is used back beyond the first result row of the cursor, an empty list is returned.

on OpenAt: integer position return list

Moves the cursor to the result entry at position and returns that entry. If it is outside the range of the cursor, an empty list is returned.

on IsLast: return boolean

Returns TRUE if the cursor is currently positioned at the last result in the set. A subsequent execution of the method Next would result in an error.

on Position: return integer

Returns the position to which the cursor currently points. First row is at position 1.

Attributes

None

Activities

None

Example

1 handle hCursor; // variable declarations

2 hCursor={'ExecuteStr, "select name, age from

3 person where name='John'"}=>dbase;

4 //assuming there are three instances of person that match

5 //the set would be

6 //{{'John, 14}, {'John, 9}, {;John, 12}}

6.6.6 DBquery

This class represents the database query. The multidatabase uses a standard query format that is based on SQL-92 with extended functionality to accommodate object database systems. A typical SQL query has four parts, each part represented by one line in the sample query below. The query finds the name, age and salary of all people called John who are working on project 3345 and orders the result set by salary amount. The keyword in each line is given in bold face.

select name, age salary

from person, project

where name='John' and projectID=3345

order by 3

The query class enables the query to be specified as a string or built up from its component parts. The query is subject to pre-processing by the multidatabase system.

Superclasses

None

Methods

on SetQryFrom: list fromList

Sets the list of class names from which the query result will be generated.

on SetQryOrderBy: list orderList

Sets the order in which the results will appear.

on SetQrySelect: list selectList

Sets the list of attributes from which the query result will be generated.

on SetQryText: string queryText

Sets the text of the entire query. The query will automatically be broken down into its component parts.

on SetQryWhere: list whereList

Sets the list of conditions which govern result generation.

on GetQryOrderBy: return list

Returns the order in which the results will be listed.

on GetQrySelect: return list

Returns the list of attributes from which the query result will be generated.

on GetQryText: return string

Returns the complete text of the query. This will be automatically generated from the component parts if necessary.

on GetQryWhere: return list

Returns the list of conditions which governs result generation.

on Bind: integer n, any value

A parameter in a query can be specified by a question mark (?) when the query is constructed. This mark must be replaced by an appropriate value before the query is executed. This method replaces the parameter marked by the nth question mark with value.

on BindAll: list values

This function replaces all the question marks in the query with the values from the supplied list in order.

Attributes

None

Activities

None

Example

1 DBquery q;

2 // don't forget to open the database etc.

3 // example of constructing queries from lists

4 {'SetSelect, {'name, 'age}} => q;

5 {'SetFrom, {'person}} => q;

6 hCursor = {'Execute, &q} => dbase;

7 // example of query binding

8 {'SetQuery, "select person from person where name = ?"} => q;

9 {'BindAll, {'joe}} => dbase;

10 hCursor = {'Execute, &q} => dbase;

6.6.7 DBbinary

This class represents the binary data type. It is assumed that the data is either stored directly as bytes or as a reference to an external file that holds the bytes. If the data is stored in an external file, then the file location can be retrieved. The location has three components, a name to identify the machine on which the file resides, a path to locate the file on that machine, and the name of the file itself. Currently, since there is no means of returning a pointer to a binary stream of data to the ADL program directly, the only option with binary data is to store it in a temporary file.

Superclasses

None

Methods

upon Create: string pathName, string fileName, string hostName return handle

Returns a handle to a DBbinary object where the binary information is stored in the file locations specified by the method parameters.

upon CreateAsBinary: string pathName, string fileName, string hostName return handle

Creates a DBbinary object where the binary information is read from the file location specified by the method parameters and stored internally to the object.

on GetFile: return string

If the binary data is stored as a reference to an external file. GetFile returns the external filename.

on GetHost: return string

If the binary data is stored as a reference to an external file. GetFile returns machine name where the file is stored.

on GetPath: return string

If the binary data is stored as a reference to an external file. GetPath returns a path to the external file.

on IsBinary: return boolean

Returns TRUE if the binary data is stored internally to the object. Returns FALSE if the binary data is stored as a reference to an external file.

Attributes

None

Activities

None

Example

None

6.6.8 DBmedia

This class represents media data that is stored either internally in binary form or as a reference to an external file.

Superclasses

Section 6.6.7, "DBbinary" page 249

Methods

upon Create: string pathName, string fileName, string hostName return handle

Returns a handle to a DBmedia object.

Attributes

None

Activities

None

Example

None

6.6.9 DBimage

This class represents image data specifically.

Superclasses

Section 6.6.7, "DBbinary" page 249

Methods

upon Create: string pathName, string fileName, string hostName return handle

Returns a handle to a DBimage object that is located on the hostname machine at the location pathname in filename.

on GetImage: return handle

Returns a handle to an MMimage object that has been constructed from the information contained in the DBimage object.

Attributes

None

Activities

None

Example

None

6.6.10 DBdate

This class is used to represent the date data type. The data type is composed of three components, an integer from 1 to 12 representing the month, an integer from 1 to 31 representing the day, and a four digit number representing the year.

Superclasses

None

Methods

upon Create: integer month, integer day, integer year return handle

Creates a DBdate and initializes the value of the date.

on SetDate: integer day, integer month, integer year

Sets the value of the date.

on GetDateStr: return string

Returns the date in the form of a string such as '13/10/1994'.

on GetDateList: return list

Returns the date in the form of a list of integers, {month, day, year}.

Attributes

None

Activities

None

Example

1 DBdate {'Create, 5, 23, 1994} => date;

2 echo('GetDateStr => date);

6.6.11 DBtime

This class represents the time data type. The data types has three components, an integer between 0 and 23 representing the hour, an integer between 0 and 59 representing the minute and an integer between 0 and 59 representing the seconds.

Superclasses

None

Methods

upon Create: integer hour, integer minute, integer second return handle

Creates a DBtime and initializes the value of the time.

on SetTime: integer hour, integer minute, integer second

Sets the value of the time.

on GetTimeStr: return string

Returns the time (24 hour clock) in the form of a string such as '14:03:22'.

on GetTimeList: return list

Returns the date in the form of a list of integers, {hour, minute, second}.

Attributes

None

Activities

None

Example

1 DBtime {'Create, 5, 15, 32} => dtime;

2 echo('GetTimeStr => dtime);

6.6.12 DBtimestamp

This class represents the timestamp data type which consist of a time and a date together represented by a data value of type DBtime and a data value to type DBdate.

Superclasses

None

Methods

upon Create: handle date, handle time return handle

Creates a DBtimestamp and initializes the value of the timestamp.

on GetTstampList: return list

Returns a list composed of two elements, a handle to a DBdate object and a handle to a DBtime object.

on SetTstamp: handle date, handle time

Sets the value of the timestamp.

on GetTstampStr: return string

Returns the timestamp in the form of a string such as '05:04:03 13/10/1994'.

Attributes

None

Activities

None

Example

1 DBtimestamp {'Create, &date, &dtime} => tstamp;

2 echo('GetTstampStr => tstamp);

6.6.13 DBmonetary

This class is used to represent the monetary data type. Currently the only information available is the amount of money represented by an object of this class. Currency information is not yet incorporated into the class.

Superclasses

None

Methods

upon Create: real amount

Creates a DBmonetary and initializes the amount of the monetary value.

on SetAmount: real amount

Sets the amount of the monetary value.

on GetAmount: return real

Returns the amount of the monetary value.

Attributes

None

Activities

None

Example

1 DBmonetary {'Create, 14.01} => money;

2 echo('GetAmount => money);

3 {'SetAmount, 18.99} => money;

4 echo('GetAmount => money);

6.6.1 - DBdatabase
Superclasses
Methods
Attributes
Activities
Example
6.6.2 - DBclass
Superclasses
Methods
Attributes
Activities
Example
6.6.3 - DBobject
Superclasses
Methods
Attributes
Activities
Example
6.6.4 - DBset
Superclasses
Methods
Attributes
Activities
Example
6.6.5 - DBcursor
Superclasses
Methods
Attributes
Activities
Example
6.6.6 - DBquery
Superclasses
Methods
Attributes
Activities
Example
6.6.7 - DBbinary
Superclasses
Methods
Attributes
Activities
Example
6.6.8 - DBmedia
Superclasses
Methods
Attributes
Activities
Example
6.6.9 - DBimage
Superclasses
Methods
Attributes
Activities
Example
6.6.10 - DBdate
Superclasses
Methods
Attributes
Activities
Example
6.6.11 - DBtime
Superclasses
Methods
Attributes
Activities
Example
6.6.12 - DBtimestamp
Superclasses
Methods
Attributes
Activities
Example
6.6.13 - DBmonetary
Superclasses
Methods
Attributes
Activities
Example

AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker