Created
September 10, 2016 17:14
-
-
Save twolfprogrammer/a75f1946c928e8903dc695637719ba7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using SQLite; | |
| using Xamarin.Forms; | |
| [assembly: Dependency(typeof(SQLiteExample.Droid.SQLiteService))] | |
| namespace SQLiteExample.Droid { | |
| public class SQLiteService : ISQLiteService { | |
| string GetPath(string databaseName) { | |
| if (string.IsNullOrWhiteSpace(databaseName)) { | |
| throw new ArgumentException("Invalid database name", nameof(databaseName)); | |
| } | |
| var sqliteFilename = $"{databaseName}.db3"; | |
| var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); | |
| var path = Path.Combine(documentsPath, sqliteFilename); | |
| return path; | |
| } | |
| public SQLiteConnection GetConnection(string databaseName) { | |
| return new SQLiteConnection(GetPath(databaseName)); | |
| } | |
| public long GetSize(string databaseName) { | |
| var fileInfo = new FileInfo(GetPath(databaseName)); | |
| return fileInfo != null ? fileInfo.Length : 0; | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment