Tasks database table

From TaskDepender
Jump to: navigation, search
(Design)
 
Line 3: Line 3:
 
== Description ==
 
== Description ==
  
The task element is described in the [[Task_Management_Method#Task|"Task Management Method"]]. The tasks in the project are stored in a table in the project database. The name does not have to be unique. Therefore, a task also has to have a unique id. Since a task represents a graphical element, it has a position, a width and a height. When using a true-type font, the width and height will be determined when the task is displayed.
+
The task element is described in the [[Task_Management_Method#Task|"Task Management Method"]]. The tasks in the project are stored in a table in the project database. The name of a task does not have to be unique, a task has to have a unique id which can be generated as a integer primary key<ref name="primary_key">[http://www.sqlite.org/lang_createtable.html#rowid rowid - SQLite specification]</ref> by the database. Since a task represents a graphical element, it has a position, a width and a height. The TaskDepender&trade; program uses a true-type font, and therefore the width and height will be determined when the task is displayed.
 +
 
 +
== Constraints ==
 +
 
 +
The following constraints apply for the tasks table:
 +
* When a container task is deleted, the contained tasks need to be deleted as well.
 +
* When a resource is deleted that is the responsible resource for a task, the resource is set to undefined.
  
 
== Design ==
 
== Design ==
Line 21: Line 27:
 
| <tt>ResourceId</tt> || integer || Id of the person responsible for the task as defined in the [[Resources database table|<tt>Resources</tt> table]].
 
| <tt>ResourceId</tt> || integer || Id of the person responsible for the task as defined in the [[Resources database table|<tt>Resources</tt> table]].
 
|- valign="top"
 
|- valign="top"
| <tt>X</tt> || integer || The x-coordinate of the task in the diagram.
+
| <tt>X</tt> || integer || The x-coordinate of the task in the diagram, expressed in pixels.
 
|- valign="top"
 
|- valign="top"
| <tt>Y</tt> || integer || The y-coordinate of the task in the diagram.
+
| <tt>Y</tt> || integer || The y-coordinate of the task in the diagram, expressed in pixels.
 +
|- valign="top"
 +
| <tt>Width</tt> || integer || The width of the task in the diagram, expressed in pixels.
 +
|- valign="top"
 +
| <tt>Height</tt> || integer || The height of the task in the diagram, expressed in pixels.
 
|- valign="top"
 
|- valign="top"
 
| <tt>ContainerId</tt> || integer || The id of the container task. Set to 0 if defined at the top level.
 
| <tt>ContainerId</tt> || integer || The id of the container task. Set to 0 if defined at the top level.
 
|}
 
|}
  
There is are two constraints for the table:
 
* When its container is deleted, the contained task must be deleted as well.
 
* When the resource with the <tt>ResourceId</tt> is deleted, the value of the <tt>ResourceId</tt> is to be set to NULL.
 
This can be done by [http://www.sqlite.org/foreignkeys.html#fk_actions referencing] these columns to the appropriate columns.
 
 
The following actions are defined on the tasks table:
 
 
;Create:When a new project is created, the tasks table must be created as well. When creating the table, the constraint must be implemented that when the task is contained in a container which is deleted, the task needs to be deleted as well. This is done by self-referencing the <tt>ContainerId</tt> column to the <tt>Id</tt> column.
 
 
;Insert:Since a task can only be added in the current container, the <tt>ContainerId</tt> does not have to be supplied but can be retrieved from the [[State variables database table|<tt>StateVariables</tt>]] table.
 
 
;Update:A task can only be updated when it is selected. The selected tasks are stored in the [[Selected tasks database table|selected tasks table]]. This means that the user does not have to supply the id when updating a selected task. This means that the caller must ensure that only one task is selected.
 
 
;Delete:Only selected tasks can be deleted. This means that the user does not have to supply an id, but simply all selected tasks are deleted.
 
 
;Cut:As described in [[Cut selected elements|"Cut selected elements"]], selected elements can be 'cut to the clipboard' by setting the <tt>ContainerId</tt> column to the maximum integer value.
 
 
;Paste:As described in [[Paste elements|"Paste elements"]], elements can be pasted into the current diagram by setting the <tt>ContainerId</tt> column to the current container. This is done by finding all the tasks that have this <tt>ContainerId</tt> set to the maximum integer value.
 
 
== Implementation ==
 
 
=== Interface structure ===
 
 
<syntaxhighlight lang="c">
 
typedef struct
 
{
 
  uint32 id,
 
  char*  name,
 
  char*  description,
 
  char*  resource,
 
  uint  x,
 
  uint  y,
 
  uint32 container_id
 
} tdd_task;
 
</syntaxhighlight>
 
 
=== Create table ===
 
 
<syntaxhighlight lang="sql">
 
CREATE TABLE Tasks
 
(
 
  Id INTEGER PRIMARY KEY,
 
  Name TEXT,
 
  Description TEXT,
 
  ResourceId INTEGER REFERENCES Resources(Id) ON DELETE SET NULL,
 
  X INTEGER,
 
  Y INTEGER,
 
  ContainerId INTEGER REFERENCES Tasks(Id) ON DELETE CASCADE
 
)
 
</syntaxhighlight>
 
 
=== Insert ===
 
 
<syntaxhighlight lang="sql">
 
INSERT INTO Tasks
 
(Name,Description, Resource, X, Y, ContainerId)
 
VALUES (%s, %s, %s, %d, %d, (SELECT Val FROM StateVariables WHERE Name='CurrentContainerId'))
 
</syntaxhighlight>
 
 
=== Update ===
 
 
<syntaxhighlight lang="sql">
 
UPDATE Tasks SET
 
  Name=%s,
 
  Description=%s,
 
  Resource=%s,
 
  X=%d,
 
  Y=%d
 
WHERE Id IN (SELECT Id FROM SelectedTasks)
 
</syntaxhighlight>
 
 
=== Delete selected tasks ===
 
 
<syntaxhighlight lang="sql">
 
DELETE FROM Tasks WHERE Id IN (SELECT Id FROM SelectedTasks)
 
</syntaxhighlight>
 
 
=== Cut selected tasks ===
 
  
<syntaxhighlight lang="sql">
+
The following actions are defined:
UPDATE Tasks SET ContainerId=MAXINT WHERE Id IN (SELECT Id FROM SelectedTasks)
+
* [[Tasks database table - Create|Create]]
</syntaxhighlight>
+
* [[Tasks database table - Insert|Insert]]
 +
* [[Tasks database table - Update|Update]]
 +
* [[Tasks database table - Delete|Delete]]
 +
* [[Tasks database table - Cut|Cut]]
 +
* [[Tasks database table - Paste|Paste]]
  
=== Paste tasks ===
+
== References ==
 +
<references/>
  
<syntaxhighlight lang="sql">
 
UPDATE Tasks SET ContainerId=(SELECT Val FROM StateVariables WHERE Name='CurrentContainerId') WHERE ContainerId=MAXINT
 
</syntaxhighlight>
 
  
 
----
 
----
 
* [[Database]]
 
* [[Database]]

Latest revision as of 06:42, 2 December 2011

Personal tools