예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.SplashScreen);
            ActionBar.Hide();

            pref   = PreferenceManager.GetDefaultSharedPreferences(this);
            editor = pref.Edit();
            editor.Clear();
            editor.Apply();

            string folder = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Zen");

            Directory.CreateDirectory(folder);
            string databaseFileName = Path.Combine(folder, "Zen.db");

            SQLite3.Config(SQLite3.ConfigOption.Serialized);
            //database.Reset(); if db structure changes

            database.createDatabase();

            client.DownloadDataCompleted += client_DownloadDataCompleted;
            client.DownloadDataAsync(uri);
            client.Dispose();
        }
예제 #2
0
        public async Task InitializeAsync()
        {
            bool fDbExists = false;

#if NETFX_CORE
            fDbExists = (await ApplicationData.Current.LocalFolder.GetFilesAsync())
                        .Any(f => string.Equals(f.Name, this.dbFileName));
#else
            fDbExists = File.Exists(this.GetDatabaseFilePath());
#endif

            SQLiteAsyncConnection connection = null;
            if (fDbExists)
            {
                connection = this.CreateConnection();
                if (connection != null)
                {
                    connection.Close();
                    await this.DeleteDatabaseAsync();
                }
            }

            connection = this.CreateConnection();
            SQLite3.Config(SQLite3.ConfigOption.MultiThread);

            await this.CreateBasicObjectsAsync(connection);

            await this.CreateTriggersAsync(connection);

            await connection.ExecuteAsync(string.Format(CultureInfo.InvariantCulture, "PRAGMA user_version = {0} ;", CurrentDatabaseVersion));
        }
예제 #3
0
        public async Task <bool> CheckVersionAsync()
        {
            bool fDbExists = false;

#if NETFX_CORE
            fDbExists = (await ApplicationData.Current.LocalFolder.GetFilesAsync())
                        .Any(f => string.Equals(f.Name, this.dbFileName));
#else
            fDbExists = File.Exists(this.GetDatabaseFilePath());
#endif
            SQLite3.Config(SQLite3.ConfigOption.MultiThread);

            if (fDbExists)
            {
                SQLiteAsyncConnection connection = this.CreateConnection();
                int currentVersion = await connection.ExecuteScalarAsync <int>("PRAGMA user_version");

                if (currentVersion == CurrentDatabaseVersion)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        // must specify database file on creation
        // will throw an error if database not found or invalid format
        public Database(string dbPath)
        {
            logger.Trace(nameof(Database));
            this.dbPath = dbPath;

            // check if the database exists
            ValidateDbFileExists();

            if (InitDll)
            {
                InitDll = false;

                // add support for loading correct native DLLs under both Win32 (x86) and Win64 (amd64)
                try
                {
                    SQLiteLoader.SetNativeDllDirectory();

                    // force loading of DLL (should throw an error if failed to load DLL) and log version
                    var sqliteVersion = SQLite3.LibVersionNumber();
                    logger.Info($"SQLite3 DLL version is {sqliteVersion}");
                }
                catch (Exception e)
                {
                    logger.Error(e, $"Critical error initializing dynamic libraries!  ABORTING! - {e.Message}");
                    throw;
                }

                // setup logging SQLite errors, must be done before Initialize()
                if (SQLite3.Config(SQLite3.ConfigOption.Log, SQLiteErrorLogCallbackDelegate, IntPtr.Zero) != SQLite3.Result.OK)
                {
                    logger.Error("Failed to register SQlite error log callback!");
                }

                // ensure initialized (future versions and some embedded versions may not automatically call this)
                // [may be automatically invoked by Open() call when creating the SQLiteConnection]
                if (SQLite3.Initialize() != SQLite3.Result.OK)
                {
                    logger.Warn("Failed to Initialize() SQLite!");
                }
            }

            // attempt to open our connection to db
            dbConnection = new SQLiteConnection(dbPath, storeDateTimeAsTicks: true);

#if DEBUG
            // enable debug output of SQL statements executed
            dbConnection.Trace = true;
#endif

            // confirm it is of expected format
            ValidateSchema();
        }
예제 #5
0
        public void Initialize()
        {
            using (var c = GetConnection())
            {
                SQLite3.Config(SQLite3.ConfigOption.MultiThread);

                c.CreateTable <AsanaWorkspace>();
                c.CreateTable <AsanaTask>();
                c.CreateTable <AsanaProject>();
                c.CreateTable <AsanaUser>();
                c.CreateTable <AsanaTag>();
                c.CreateTable <AsanaTagTask>();
                c.CreateTable <AsanaStory>();
            }
        }
예제 #6
0
        public async Task <DatabaseUpdateInformation> InitializeAsync(bool forceToUpdate)
        {
            bool fDbExists = false;

#if NETFX_CORE
            fDbExists = (await ApplicationData.Current.LocalFolder.GetFilesAsync())
                        .Any(f => string.Equals(f.Name, this.dbFileName));
#else
            fDbExists = File.Exists(this.GetDatabaseFilePath());
#endif
            SQLite3.Config(SQLite3.ConfigOption.MultiThread);

            int currentVersion = -1;

            SQLiteAsyncConnection connection = null;

            if (fDbExists)
            {
                connection     = this.CreateConnection();
                currentVersion = await connection.ExecuteScalarAsync <int>("PRAGMA user_version");

                if (currentVersion == CurrentDatabaseVersion && !forceToUpdate)
                {
                    return(new DatabaseUpdateInformation(CurrentDatabaseVersion, DatabaseStatus.Existed));
                }
            }

            bool versionUpdated = false;

            if ((currentVersion >= 2 && currentVersion < CurrentDatabaseVersion) &&
                !forceToUpdate)
            {
                await this.DropAllTriggersAsync(connection);

                if (currentVersion <= 2)
                {
                    await this.Update2Async(connection);
                }

                if (currentVersion <= 3)
                {
                    await this.Update3Async(connection);
                }

                if (currentVersion <= 4)
                {
                    await this.Update4Async(connection);

                    forceToUpdate = true;
                }

                if (currentVersion <= 5)
                {
                    forceToUpdate = true;
                }

                versionUpdated = true;
            }

            if (!versionUpdated || forceToUpdate)
            {
                currentVersion = -1;

                if (connection != null)
                {
                    connection.Close();
                    await this.DeleteDatabaseAsync();
                }

                connection = this.CreateConnection();
                await this.CreateBasicObjectsAsync(connection);
            }

            if (connection != null)
            {
                await this.CreateTriggersAsync(connection);

                await connection.ExecuteAsync(string.Format(CultureInfo.InvariantCulture, "PRAGMA user_version = {0} ;", CurrentDatabaseVersion));
            }

            return(new DatabaseUpdateInformation(currentVersion, currentVersion == -1 ? DatabaseStatus.New : DatabaseStatus.Updated));
        }