Example #1
0
        public global::SQLite.Net.SQLiteConnection GetConnection()
        {
            var    sqliteFilename = "M2ESQLite.db3";
            string documentsPath  = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);

            // This is where we copy in the prepopulated database
            Console.WriteLine(path);
            if (!File.Exists(path))
            {
                var s = Forms.Context.Resources.OpenRawResource(Resource.Raw.TodoSQLite); // RESOURCE NAME ###

                // create a write stream
                FileStream writeStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                // write to the stream
                ReadWriteStream(s, writeStream);
            }

            var plat = new global::SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
            var conn = new global::SQLite.Net.SQLiteConnection(plat, path);

            // Return the database connection
            return(conn);
            //return null;
        }
Example #2
0
        public global::SQLite.Net.SQLiteConnection GetConnection()
        {
            var sqliteFilename = "M2ESQLite.db3";
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);

            // This is where we copy in the prepopulated database
            Console.WriteLine(path);
            if (!File.Exists(path))
            {
                var s = Forms.Context.Resources.OpenRawResource(Resource.Raw.TodoSQLite); // RESOURCE NAME ###

                // create a write stream
                FileStream writeStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                // write to the stream
                ReadWriteStream(s, writeStream);
            }

            var plat = new global::SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
            var conn = new global::SQLite.Net.SQLiteConnection(plat, path);

            // Return the database connection 
            return conn;
            //return null;
        }