Tdd create

From TaskDepender
Jump to: navigation, search
(Implementation)
 
Line 1: Line 1:
 
{{#customtitle:'''<tt>tdd_create()</tt>'''}}
 
{{#customtitle:'''<tt>tdd_create()</tt>'''}}
 
''Function to create a new TaskDepender&trade; database.''
 
''Function to create a new TaskDepender&trade; database.''
 +
 +
== Function prototype ==
 +
 +
<syntaxhighlight lang="c">
 +
/*
 +
* Creates the TaskDepender database in the specified file.
 +
*/
 +
HANDLE tdd_create
 +
(
 +
  char *filename // Filename of the database file to create.
 +
)
 +
 +
</syntaxhighlight>
 +
 +
== 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 ==
 +
 +
<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]]

Latest revision as of 10:31, 22 October 2011