Tdd create
From TaskDepender
(→Implementation) |
|||
Line 5: | Line 5: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
− | + | /* | |
+ | * Creates the TaskDepender database in the specified file. | ||
+ | */ | ||
+ | HANDLE tdd_create | ||
( | ( | ||
char *filename // Filename of the database file to create. | char *filename // Filename of the database file to create. | ||
Line 14: | Line 17: | ||
== Design == | == Design == | ||
− | + | To create a TaskDepender database the following steps are taken. | |
+ | |||
+ | # Create a new database and open it for reading and writing. | ||
+ | # Create the [[Tasks database table|tasks table]]. | ||
+ | # Create the [[Deliverables database table|deliverables table]]. | ||
+ | # Create the [[Connections database table|connections table]]. | ||
+ | # Create the temporary [[Task list database table|task-list table]]. | ||
+ | # Create the temporary [[Deliverable list database table|deliverable-list table]]. | ||
+ | # Create the temporary [[Connection list database table|connection-list table]]. | ||
+ | |||
+ | |||
+ | |||
+ | To open and create a new database, the <tt>[http://www.sqlite.org/c3ref/open.html sqlite3_open_v2()]</tt> is used. | ||
== Implementation == | == Implementation == | ||
+ | <syntaxhighlight lang="c"> | ||
+ | HANDLE tdd_create | ||
+ | ( | ||
+ | char *filename // Filename of the database file to create. | ||
+ | ) | ||
+ | { | ||
+ | sqlite3 *db; | ||
+ | rc = sqlite3_open_v2(filename,&db,SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,NULL); | ||
+ | |||
+ | if(rc) | ||
+ | { | ||
+ | sqlite3_close(db); | ||
+ | return &db; | ||
+ | } | ||
+ | |||
+ | // -- Create tasks table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_TASKS_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | // -- Create deliverables table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_DELIVERABLES_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | // -- Create the connections table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_CONNECTIONS_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | // -- Create the temporary task-list table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_TASKLIST_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | // -- Create the temporary deliverable-list table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_TASKS_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | // -- Create the temporary connection-list table -- | ||
+ | rc = sqlite3_exec(db, TDD_CREATE_TASKS_TABLE, NULL, NULL, &dbError ); | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | return &db; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
---- | ---- | ||
* [[Database]] | * [[Database]] |