Esempio n. 1
0
        private SQLiteConnection InitializeDatabase(string dbDir, string dbFile)
        {
            string fullPath          = dbDir + "/" + dbFile;
            bool   needsInitializing = false;

            // Create database
            if (!File.Exists(fullPath))
            {
                Console.WriteLine("Creating database");
                Directory.CreateDirectory(dbDir);
                SQLiteConnection.CreateFile(fullPath);
                needsInitializing = true;
            }

            // Connect to database
            SQLiteConnection conn = new SQLiteConnection("Data Source=" + fullPath + "; Version=3;");

            conn.Open();

            if (needsInitializing)
            {
                ConfigureDatabase(conn);
            }

            // Close the connection so that it is only opened upon client requests
            conn.Close();
            DBController.TruncateSessions(conn);
            return(conn);
        }
Esempio n. 2
0
        private SQLiteConnection InitializeDatabase(string dbDir, string dbFile)
        {
            string dbPath = dbDir + "/" + dbFile;
            bool   needsInitialization = false;

            // Create database if it is not already present
            if (!File.Exists(dbPath))
            {
                Console.WriteLine("CREATING DATABASE");
                Directory.CreateDirectory(dbDir);
                SQLiteConnection.CreateFile(dbPath);
                needsInitialization = true;
            }

            // Connection to database
            SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath + "; Version=3;");

            connection.Open();

            if (needsInitialization)
            {
                ConfigureDatabase(connection);
            }

            // Close the connection
            connection.Close();
            DBController.TruncateSessions(connection);

            return(connection);
        }