This repository was archived by the owner on Apr 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqliteClient.cs
114 lines (109 loc) · 4.88 KB
/
SqliteClient.cs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#region Licenses
/*MIT License
Copyright(c) 2020
Robert Garrison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
#region Using Statements
using ADONetHelper.Core;
using System.Data;
using System.Data.SQLite;
#endregion
namespace ADONetHelper.Sqlite
{
/// <summary>
/// Helper class that works with a sqlite datastore
/// </summary>
/// <seealso cref="DbClient"/>
public class SqliteClient : DbClient
{
#region Fields/Properties
/// <summary>
/// Gets the connection.
/// </summary>
/// <value>
/// The connection.
/// </value>
protected SQLiteConnection Connection
{
get
{
//Return this back to the caller
return (SQLiteConnection)this.ExecuteSQL.Connection;
}
}
#endregion
#region Constructors
/// <summary>
/// Instantiates a new instance of <see cref="SqliteClient"/> using the passed in <paramref name="executor"/>
/// </summary>
/// <param name="executor">An instance of <see cref="ISqlExecutor"/></param>
public SqliteClient(ISqlExecutor executor) : base(executor)
{
}
/// <summary>
/// Instantiates a new instance of <see cref="SqliteClient"/> using the passed in <paramref name="connectionString"/> and <paramref name="queryCommandType"/>
/// </summary>
/// <param name="connectionString">The connection string used to query a data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
public SqliteClient(string connectionString, CommandType queryCommandType) : base(connectionString, queryCommandType, SQLiteFactory.Instance)
{
}
/// <summary>
/// Instantiates a new instance of <see cref="SqliteClient"/> using the passed in <paramref name="connectionString"/>
/// </summary>
/// <param name="connectionString">The connection string used to query a data store</param>
public SqliteClient(string connectionString) : base(connectionString, SQLiteFactory.Instance)
{
}
/// <summary>
/// Instantiates a new instance of <see cref="SqliteClient"/> using the passed in <paramref name="connection"/>
/// </summary>
/// <param name="connection">An instance of <see cref="SQLiteConnection"/> to use to query a database</param>
public SqliteClient(SQLiteConnection connection) : base(connection)
{
}
/// <summary>
/// Instantiates a new instance of <see cref="SqliteClient"/> using the passed in <paramref name="connectionString"/> and <paramref name="factory"/>
/// </summary>
/// <param name="connectionString">Connection string to use to query a database</param>
/// <param name="factory">An instance of <see cref="IDbObjectFactory"/></param>
public SqliteClient(string connectionString, IDbObjectFactory factory) : base(connectionString, factory)
{
}
#endregion
#region Utility Methods
/// <summary>
/// Verifies all queries within the current command context can be compiled
/// </summary>
/// <param name="query">The query.</param>
/// <exception cref="SQLiteException">Thrown if any error occurs during compilation of the query</exception>
public void VerifyOnly(string query)
{
//Wrap this in a using statement to automatically dispose of resources
using (SQLiteCommand command = new SQLiteCommand(query, this.Connection))
{
//Add in any parameters
command.Parameters.AddRange(ExecuteSQL.Parameters.ToArray());
command.VerifyOnly();
//Clear the parameters
command.Parameters.Clear();
}
}
#endregion
}
}