This repository was archived by the owner on Sep 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathSQLiteConnection.cs
More file actions
96 lines (89 loc) · 3.56 KB
/
SQLiteConnection.cs
File metadata and controls
96 lines (89 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// OsmSharp - OpenStreetMap (OSM) SDK
// Copyright (C) 2013 Abelshausen Ben
//
// This file is part of OsmSharp.
//
// OsmSharp is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// OsmSharp is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OsmSharp. If not, see <http://www.gnu.org/licenses/>.
using OsmSharp.UI.Data.SQLite;
using System.IO;
using System.Reflection;
namespace OsmSharp.Android.UI.Data.SQLite
{
/// <summary>
/// An Android-specific implementation of an SQLiteConnection.
/// </summary>
public class SQLiteConnection : OsmSharp.UI.Data.SQLite.SQLiteConnectionBase
{
/// <summary>
/// Holds the 'native' or platform-specific connection.
/// </summary>
private OsmSharp.Android.SQLite.SQLiteConnection _nativeConnection;
/// <summary>
/// Creates a new SQLite connection.
/// </summary>
/// <param name="databasePath"></param>
public SQLiteConnection(string databasePath)
{
_nativeConnection = new OsmSharp.Android.SQLite.SQLiteConnection(databasePath);
}
/// <summary>
/// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
/// in the command text for each of the arguments and then executes that command.
/// It returns each row of the result using the mapping automatically generated for
/// the given type.
/// </summary>
/// <param name="query">
/// The fully escaped SQL.
/// </param>
/// <param name="args">
/// Arguments to substitute for the occurences of '?' in the query.
/// </param>
/// <returns>
/// An enumerable with one result for each row returned by the query.
/// </returns>
public override System.Collections.Generic.List<T> Query<T>(string query, params object[] args)
{
return _nativeConnection.Query<T>(query, args);
}
/// <summary>
/// Creates a new SQLite connection from a Stream by copying the data in the stream to a local path and open that file.
/// </summary>
/// <param name="stream">The stream containing the database data.</param>
/// <param name="dbName">A name for the temporary file to use.</param>
/// <returns></returns>
public static SQLiteConnection CreateFrom(Stream stream, string dbName)
{
var destinationPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbName + ".db3");
using (var destination = System.IO.File.Create(destinationPath))
{
stream.CopyTo(destination);
}
return new SQLiteConnection(destinationPath);
}
/// <summary>
/// Diposes of all resources associated with this connection.
/// </summary>
public override void Dispose()
{
_nativeConnection.Dispose();
}
/// <summary>
/// Closes this connection.
/// </summary>
public override void Close()
{
_nativeConnection.Close();
}
}
}