/// <summary> /// Open the todomoo main database. /// </summary> /// <param name="database_path">Path of the main SQLite database</param> public static void OpenDatabase(string database_path) { // If not exists, create empty if (!File.Exists(database_path)) CreateEmptyDatabase(database_path); // Open database Todomoo.database_path = database_path; db = new SQLite(database_path); isDbOpen = true; // Update database UpdateDatabase(); }
/// <summary> /// 初期化 /// </summary> /// <param name="localDbPath"></param> public void Initialize( string localDbPath ) { m_localDbPath = localDbPath; // 接続 m_sqlite = new SQLite(); m_sqlite.Connection( m_localDbPath ); }
/// <summary> /// Create the empty database. /// </summary> public static void CreateEmptyDatabase(string database_path) { // Open database (create) db = new SQLite(database_path); string q = ""; // Categories table q = "CREATE TABLE category ( "; q += " id INTEGER PRIMARY KEY AUTOINCREMENT, "; q += " name TEXT NOT NULL, "; q += " colour INTEGER UNSIGNED NOT NULL "; q += "); "; db.NonQuery(q); // Notes table q = "CREATE TABLE note ( "; q += " id INTEGER PRIMARY KEY AUTOINCREMENT, "; q += " text TEXT NOT NULL, "; q += " task INTEGER UNSIGNED NOT NULL, "; q += " marked INTEGER UNSIGNED "; q += "); "; db.NonQuery(q); // Task table q = "CREATE TABLE task ( "; q += " id INTEGER PRIMARY KEY AUTOINCREMENT, "; q += " name TEXT NOT NULL, "; q += " description TEXT NULL, "; q += " colour INTEGER UNSIGNED NOT NULL, "; q += " priority INTEGER UNSIGNED NOT NULL, "; q += " creation_date TEXT NOT NULL, "; q += " due_date TEXT NULL, "; q += " completed TEXT NULL, "; q += " timer TEXT NULL, "; q += " price TEXT NULL, "; q += " paid TEXT NULL, "; q += " payment TEXT NULL, "; q += " payment_note TEXT NULL, "; q += " parent INTEGER UNSIGNED NULL, "; q += " category INTEGER UNSIGNED NOT NULL "; q += "); "; db.NonQuery(q); }
/// <summary> /// 破棄 /// </summary> public void Destruction() { if( m_sqlite != null ) { m_sqlite.Dispose(); m_sqlite = null; } if( File.Exists( m_localDbPath ) ) { File.Delete( m_localDbPath ); } }