Tasks database table

From TaskDepender
Jump to: navigation, search
(Design)
(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 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 [http://www.sqlite.org/lang_createtable.html#rowid] by the database[http://www.sqlite.org/lang_createtable.html#rowid]. Since a task represents a graphical element, it has a position, a width and a height. The TaskDepender™ program uses a true-type font, and therefore 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:
 
The following constraints apply for the tasks table:
Line 10: Line 12:
  
 
== Design ==
 
== Design ==
 
=== Definition ===
 
  
 
The tasks are stored in a table with the following columns:
 
The tasks are stored in a table with the following columns:
Line 47: Line 47:
 
* [[Tasks database table - Paste|Paste]]
 
* [[Tasks database table - Paste|Paste]]
  
 +
== References ==
 +
<references/>
  
 
=== 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. To restrict the database to update more tasks when the selected tasks table contains more than one task, the update is [http://www.sqlite.org/lang_select.html limited] to the first element.
 
 
=== 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. Since the <tt>Id</tt> of a task is stored in a [[Types|<tt>uint32</tt>]], this value is explicitly set to 4294967295 (=2<sup>32</sup>).
 
 
=== 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. As follows from the previous section, this is done by finding all the tasks that have this <tt>ContainerId</tt> set to the maximum integer value of 4294967295.
 
 
== Implementation ==
 
 
=== Interface structure ===
 
 
<syntaxhighlight lang="cpp">
 
typedef struct
 
{
 
  uint32 id,
 
  char*  name,
 
  char*  description,
 
  uint  resourceId,
 
  uint  x,
 
  uint  y,
 
  uint  width,
 
  uint  height,
 
  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,
 
  Width INTEGER,
 
  Height INTEGER,
 
  ContainerId INTEGER REFERENCES Tasks(Id) ON DELETE CASCADE
 
)
 
</syntaxhighlight>
 
 
=== Insert ===
 
 
<syntaxhighlight lang="sql">
 
INSERT INTO Tasks
 
(Name,Description, Resource, X, Y, Width, Height, ContainerId)
 
VALUES (%s, %s, %s, %d, %d, %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,
 
  Width=%d,
 
  Height=%d
 
WHERE Id IN (SELECT Id FROM SelectedTasks LIMIT 1)
 
</syntaxhighlight>
 
 
=== Delete selected tasks ===
 
 
<syntaxhighlight lang="sql">
 
DELETE FROM Tasks WHERE Id IN (SELECT Id FROM SelectedTasks)
 
</syntaxhighlight>
 
 
=== Cut selected tasks ===
 
 
<syntaxhighlight lang="sql">
 
UPDATE Tasks SET ContainerId=4294967295 WHERE Id IN (SELECT Id FROM SelectedTasks)
 
</syntaxhighlight>
 
 
=== Paste tasks ===
 
 
<syntaxhighlight lang="sql">
 
UPDATE Tasks SET ContainerId=(SELECT Val FROM StateVariables WHERE Name='CurrentContainerId') WHERE ContainerId=4294967295
 
</syntaxhighlight>
 
  
 
----
 
----
 
* [[Database]]
 
* [[Database]]

Latest revision as of 06:42, 2 December 2011

Personal tools