Skip to content

Commit f9cc4fe

Browse files
authoredJan 14, 2025··
Merge pull request #42 from gilzoide/sqlite-net-v1.9.172
Update SQLite-net to v1.9.172
·
1.3.11.2.0
2 parents 661852b + f7a9962 commit f9cc4fe

File tree

4 files changed

+263
-15
lines changed

4 files changed

+263
-15
lines changed
 

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This package provides the excelent [SQLite-net](https://github.com/praeclarum/sq
55

66

77
## Features
8-
- [SQLite-net v1.8.116](https://github.com/praeclarum/sqlite-net/tree/v1.8.116)
8+
- [SQLite-net v1.9.172](https://github.com/praeclarum/sqlite-net/tree/v1.9.172)
99
+ Both synchronous and asynchronous APIs are available
1010
+ `SQLiteConnection.Serialize` extension method for serializing a database to `byte[]` (reference: [SQLite Serialization](https://www.sqlite.org/c3ref/serialize.html)).
1111
+ `SQLiteConnection.Deserialize` extension method for deserializing memory (`byte[]`, `NativeArray<byte>` or `ReadOnlySpan<byte>`) into an open database (reference: [SQLite Deserialization](https://www.sqlite.org/c3ref/deserialize.html)).

‎Runtime/sqlite-net/SQLite.cs

Lines changed: 143 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2009-2021 Krueger Systems, Inc.
2+
// Copyright (c) 2009-2024 Krueger Systems, Inc.
33
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
@@ -114,6 +114,7 @@ public static NotNullConstraintViolationException New (SQLiteException exception
114114
public enum SQLiteOpenFlags
115115
{
116116
ReadOnly = 1, ReadWrite = 2, Create = 4,
117+
Uri = 0x40, Memory = 0x80,
117118
NoMutex = 0x8000, FullMutex = 0x10000,
118119
SharedCache = 0x20000, PrivateCache = 0x40000,
119120
ProtectionComplete = 0x00100000,
@@ -159,11 +160,109 @@ public enum CreateFlags
159160
FullTextSearch4 = 0x200
160161
}
161162

163+
public interface ISQLiteConnection : IDisposable
164+
{
165+
Sqlite3DatabaseHandle Handle { get; }
166+
string DatabasePath { get; }
167+
int LibVersionNumber { get; }
168+
bool TimeExecution { get; set; }
169+
bool Trace { get; set; }
170+
Action<string> Tracer { get; set; }
171+
bool StoreDateTimeAsTicks { get; }
172+
bool StoreTimeSpanAsTicks { get; }
173+
string DateTimeStringFormat { get; }
174+
TimeSpan BusyTimeout { get; set; }
175+
IEnumerable<TableMapping> TableMappings { get; }
176+
bool IsInTransaction { get; }
177+
178+
event EventHandler<NotifyTableChangedEventArgs> TableChanged;
179+
180+
void Backup (string destinationDatabasePath, string databaseName = "main");
181+
void BeginTransaction ();
182+
void Close ();
183+
void Commit ();
184+
SQLiteCommand CreateCommand (string cmdText, params object[] ps);
185+
SQLiteCommand CreateCommand (string cmdText, Dictionary<string, object> args);
186+
int CreateIndex (string indexName, string tableName, string[] columnNames, bool unique = false);
187+
int CreateIndex (string indexName, string tableName, string columnName, bool unique = false);
188+
int CreateIndex (string tableName, string columnName, bool unique = false);
189+
int CreateIndex (string tableName, string[] columnNames, bool unique = false);
190+
int CreateIndex<T> (Expression<Func<T, object>> property, bool unique = false);
191+
CreateTableResult CreateTable<T> (CreateFlags createFlags = CreateFlags.None);
192+
CreateTableResult CreateTable (Type ty, CreateFlags createFlags = CreateFlags.None);
193+
CreateTablesResult CreateTables<T, T2> (CreateFlags createFlags = CreateFlags.None)
194+
where T : new()
195+
where T2 : new();
196+
CreateTablesResult CreateTables<T, T2, T3> (CreateFlags createFlags = CreateFlags.None)
197+
where T : new()
198+
where T2 : new()
199+
where T3 : new();
200+
CreateTablesResult CreateTables<T, T2, T3, T4> (CreateFlags createFlags = CreateFlags.None)
201+
where T : new()
202+
where T2 : new()
203+
where T3 : new()
204+
where T4 : new();
205+
CreateTablesResult CreateTables<T, T2, T3, T4, T5> (CreateFlags createFlags = CreateFlags.None)
206+
where T : new()
207+
where T2 : new()
208+
where T3 : new()
209+
where T4 : new()
210+
where T5 : new();
211+
CreateTablesResult CreateTables (CreateFlags createFlags = CreateFlags.None, params Type[] types);
212+
IEnumerable<T> DeferredQuery<T> (string query, params object[] args) where T : new();
213+
IEnumerable<object> DeferredQuery (TableMapping map, string query, params object[] args);
214+
int Delete (object objectToDelete);
215+
int Delete<T> (object primaryKey);
216+
int Delete (object primaryKey, TableMapping map);
217+
int DeleteAll<T> ();
218+
int DeleteAll (TableMapping map);
219+
int DropTable<T> ();
220+
int DropTable (TableMapping map);
221+
void EnableLoadExtension (bool enabled);
222+
void EnableWriteAheadLogging ();
223+
int Execute (string query, params object[] args);
224+
T ExecuteScalar<T> (string query, params object[] args);
225+
T Find<T> (object pk) where T : new();
226+
object Find (object pk, TableMapping map);
227+
T Find<T> (Expression<Func<T, bool>> predicate) where T : new();
228+
T FindWithQuery<T> (string query, params object[] args) where T : new();
229+
object FindWithQuery (TableMapping map, string query, params object[] args);
230+
T Get<T> (object pk) where T : new();
231+
object Get (object pk, TableMapping map);
232+
T Get<T> (Expression<Func<T, bool>> predicate) where T : new();
233+
TableMapping GetMapping (Type type, CreateFlags createFlags = CreateFlags.None);
234+
TableMapping GetMapping<T> (CreateFlags createFlags = CreateFlags.None);
235+
List<SQLiteConnection.ColumnInfo> GetTableInfo (string tableName);
236+
int Insert (object obj);
237+
int Insert (object obj, Type objType);
238+
int Insert (object obj, string extra);
239+
int Insert (object obj, string extra, Type objType);
240+
int InsertAll (IEnumerable objects, bool runInTransaction = true);
241+
int InsertAll (IEnumerable objects, string extra, bool runInTransaction = true);
242+
int InsertAll (IEnumerable objects, Type objType, bool runInTransaction = true);
243+
int InsertOrReplace (object obj);
244+
int InsertOrReplace (object obj, Type objType);
245+
List<T> Query<T> (string query, params object[] args) where T : new();
246+
List<object> Query (TableMapping map, string query, params object[] args);
247+
List<T> QueryScalars<T> (string query, params object[] args);
248+
void ReKey (string key);
249+
void ReKey (byte[] key);
250+
void Release (string savepoint);
251+
void Rollback ();
252+
void RollbackTo (string savepoint);
253+
void RunInTransaction (Action action);
254+
string SaveTransactionPoint ();
255+
TableQuery<T> Table<T> () where T : new();
256+
int Update (object obj);
257+
int Update (object obj, Type objType);
258+
int UpdateAll (IEnumerable objects, bool runInTransaction = true);
259+
}
260+
162261
/// <summary>
163262
/// An open connection to a SQLite database.
164263
/// </summary>
165264
[Preserve (AllMembers = true)]
166-
public partial class SQLiteConnection : IDisposable
265+
public partial class SQLiteConnection : ISQLiteConnection
167266
{
168267
private bool _open;
169268
private TimeSpan _busyTimeout;
@@ -364,7 +463,7 @@ public static string Quote (string unsafeString)
364463
/// if your database is encrypted.
365464
/// This only has an effect if you are using the SQLCipher nuget package.
366465
/// </summary>
367-
/// <param name="key">Ecryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
466+
/// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
368467
void SetKey (string key)
369468
{
370469
if (key == null)
@@ -379,7 +478,7 @@ void SetKey (string key)
379478
/// if your database is encrypted.
380479
/// This only has an effect if you are using the SQLCipher nuget package.
381480
/// </summary>
382-
/// <param name="key">256-bit (32 byte) ecryption key data</param>
481+
/// <param name="key">256-bit (32 byte) encryption key data</param>
383482
void SetKey (byte[] key)
384483
{
385484
if (key == null)
@@ -390,6 +489,32 @@ void SetKey (byte[] key)
390489
ExecuteScalar<string> ("pragma key = \"x'" + s + "'\"");
391490
}
392491

492+
/// <summary>
493+
/// Change the encryption key for a SQLCipher database with "pragma rekey = ...".
494+
/// </summary>
495+
/// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
496+
public void ReKey (string key)
497+
{
498+
if (key == null)
499+
throw new ArgumentNullException(nameof(key));
500+
var q = Quote(key);
501+
ExecuteScalar<string>("pragma rekey = " + q);
502+
}
503+
504+
/// <summary>
505+
/// Change the encryption key for a SQLCipher database.
506+
/// </summary>
507+
/// <param name="key">256-bit (32 byte) or 384-bit (48 bytes) encryption key data</param>
508+
public void ReKey (byte[] key)
509+
{
510+
if (key == null)
511+
throw new ArgumentNullException(nameof(key));
512+
if (key.Length != 32 && key.Length != 48)
513+
throw new ArgumentException ("Key must be 32 bytes (256-bit) or 48 bytes (384-bit)", nameof (key));
514+
var s = String.Join("", key.Select(x => x.ToString("X2")));
515+
ExecuteScalar<string>("pragma rekey = \"x'" + s + "'\"");
516+
}
517+
393518
/// <summary>
394519
/// Enable or disable extension loading.
395520
/// </summary>
@@ -1894,7 +2019,7 @@ public int Update (object obj, Type objType)
18942019
}
18952020
ps.Add (pk.GetValue (obj));
18962021
var q = string.Format ("update \"{0}\" set {1} where \"{2}\" = ? ", map.TableName, string.Join (",", (from c in cols
1897-
select "\"" + c.Name + "\" = ? ").ToArray ()), pk.Name);
2022+
select "\"" + c.Name + "\" = ? ").ToArray ()), pk.Name);
18982023

18992024
try {
19002025
rowsAffected = Execute (q, ps.ToArray ());
@@ -1905,7 +2030,7 @@ public int Update (object obj, Type objType)
19052030
throw NotNullConstraintViolationException.New (ex, map, obj);
19062031
}
19072032

1908-
throw ex;
2033+
throw;
19092034
}
19102035

19112036
if (rowsAffected > 0)
@@ -2349,7 +2474,7 @@ public class AutoIncrementAttribute : Attribute
23492474
{
23502475
}
23512476

2352-
[AttributeUsage (AttributeTargets.Property)]
2477+
[AttributeUsage (AttributeTargets.Property, AllowMultiple = true)]
23532478
public class IndexedAttribute : Attribute
23542479
{
23552480
public string Name { get; set; }
@@ -2786,7 +2911,7 @@ public static string SqlDecl (TableMapping.Column p, bool storeDateTimeAsTicks,
27862911
public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks)
27872912
{
27882913
var clrType = p.ColumnType;
2789-
if (clrType == typeof (Boolean) || clrType == typeof (Byte) || clrType == typeof (UInt16) || clrType == typeof (SByte) || clrType == typeof (Int16) || clrType == typeof (Int32) || clrType == typeof (UInt32) || clrType == typeof (Int64)) {
2914+
if (clrType == typeof (Boolean) || clrType == typeof (Byte) || clrType == typeof (UInt16) || clrType == typeof (SByte) || clrType == typeof (Int16) || clrType == typeof (Int32) || clrType == typeof (UInt32) || clrType == typeof (Int64) || clrType == typeof (UInt64)) {
27902915
return "integer";
27912916
}
27922917
else if (clrType == typeof (Single) || clrType == typeof (Double) || clrType == typeof (Decimal)) {
@@ -3185,7 +3310,7 @@ internal static void BindParameter (Sqlite3Statement stmt, int index, object val
31853310
else if (value is Boolean) {
31863311
SQLite3.BindInt (stmt, index, (bool)value ? 1 : 0);
31873312
}
3188-
else if (value is UInt32 || value is Int64) {
3313+
else if (value is UInt32 || value is Int64 || value is UInt64) {
31893314
SQLite3.BindInt64 (stmt, index, Convert.ToInt64 (value));
31903315
}
31913316
else if (value is Single || value is Double || value is Decimal) {
@@ -3319,6 +3444,9 @@ object ReadCol (Sqlite3Statement stmt, int index, SQLite3.ColType type, Type clr
33193444
else if (clrType == typeof (Int64)) {
33203445
return SQLite3.ColumnInt64 (stmt, index);
33213446
}
3447+
else if (clrType == typeof (UInt64)) {
3448+
return (ulong)SQLite3.ColumnInt64 (stmt, index);
3449+
}
33223450
else if (clrType == typeof (UInt32)) {
33233451
return (uint)SQLite3.ColumnInt64 (stmt, index);
33243452
}
@@ -3463,6 +3591,12 @@ internal static Action<object, Sqlite3Statement, int> GetFastSetter<T> (SQLiteCo
34633591
return SQLite3.ColumnInt64 (stmt, index);
34643592
});
34653593
}
3594+
else if (clrType == typeof(UInt64))
3595+
{
3596+
fastSetter = CreateNullableTypedSetterDelegate<T, UInt64>(column, (stmt, index) => {
3597+
return (ulong)SQLite3.ColumnInt64(stmt, index);
3598+
});
3599+
}
34663600
else if (clrType == typeof (UInt32)) {
34673601
fastSetter = CreateNullableTypedSetterDelegate<T, UInt32> (column, (stmt, index) => {
34683602
return (uint)SQLite3.ColumnInt64 (stmt, index);

‎Runtime/sqlite-net/SQLiteAsync.cs

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2012-2021 Krueger Systems, Inc.
2+
// Copyright (c) 2012-2024 Krueger Systems, Inc.
33
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
@@ -28,12 +28,102 @@
2828
using System.Threading;
2929
using System.Threading.Tasks;
3030

31+
#pragma warning disable 1591 // XML Doc Comments
32+
3133
namespace SQLite
3234
{
35+
public interface ISQLiteAsyncConnection
36+
{
37+
string DatabasePath { get; }
38+
int LibVersionNumber { get; }
39+
string DateTimeStringFormat { get; }
40+
bool StoreDateTimeAsTicks { get; }
41+
bool StoreTimeSpanAsTicks { get; }
42+
bool Trace { get; set; }
43+
Action<string> Tracer { get; set; }
44+
bool TimeExecution { get; set; }
45+
IEnumerable<TableMapping> TableMappings { get; }
46+
47+
Task BackupAsync (string destinationDatabasePath, string databaseName = "main");
48+
Task CloseAsync ();
49+
Task<int> CreateIndexAsync (string tableName, string columnName, bool unique = false);
50+
Task<int> CreateIndexAsync (string indexName, string tableName, string columnName, bool unique = false);
51+
Task<int> CreateIndexAsync (string tableName, string[] columnNames, bool unique = false);
52+
Task<int> CreateIndexAsync (string indexName, string tableName, string[] columnNames, bool unique = false);
53+
Task<int> CreateIndexAsync<T> (Expression<Func<T, object>> property, bool unique = false);
54+
Task<CreateTableResult> CreateTableAsync<T> (CreateFlags createFlags = CreateFlags.None) where T : new();
55+
Task<CreateTableResult> CreateTableAsync (Type ty, CreateFlags createFlags = CreateFlags.None);
56+
Task<CreateTablesResult> CreateTablesAsync<T, T2> (CreateFlags createFlags = CreateFlags.None)
57+
where T : new()
58+
where T2 : new();
59+
Task<CreateTablesResult> CreateTablesAsync<T, T2, T3> (CreateFlags createFlags = CreateFlags.None)
60+
where T : new()
61+
where T2 : new()
62+
where T3 : new();
63+
Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4> (CreateFlags createFlags = CreateFlags.None)
64+
where T : new()
65+
where T2 : new()
66+
where T3 : new()
67+
where T4 : new();
68+
Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> (CreateFlags createFlags = CreateFlags.None)
69+
where T : new()
70+
where T2 : new()
71+
where T3 : new()
72+
where T4 : new()
73+
where T5 : new();
74+
Task<CreateTablesResult> CreateTablesAsync (CreateFlags createFlags = CreateFlags.None, params Type[] types);
75+
Task<IEnumerable<T>> DeferredQueryAsync<T> (string query, params object[] args) where T : new();
76+
Task<IEnumerable<object>> DeferredQueryAsync (TableMapping map, string query, params object[] args);
77+
Task<int> DeleteAllAsync<T> ();
78+
Task<int> DeleteAllAsync (TableMapping map);
79+
Task<int> DeleteAsync (object objectToDelete);
80+
Task<int> DeleteAsync<T> (object primaryKey);
81+
Task<int> DeleteAsync (object primaryKey, TableMapping map);
82+
Task<int> DropTableAsync<T> () where T : new();
83+
Task<int> DropTableAsync (TableMapping map);
84+
Task EnableLoadExtensionAsync (bool enabled);
85+
Task EnableWriteAheadLoggingAsync ();
86+
Task<int> ExecuteAsync (string query, params object[] args);
87+
Task<T> ExecuteScalarAsync<T> (string query, params object[] args);
88+
Task<T> FindAsync<T> (object pk) where T : new();
89+
Task<object> FindAsync (object pk, TableMapping map);
90+
Task<T> FindAsync<T> (Expression<Func<T, bool>> predicate) where T : new();
91+
Task<T> FindWithQueryAsync<T> (string query, params object[] args) where T : new();
92+
Task<object> FindWithQueryAsync (TableMapping map, string query, params object[] args);
93+
Task<T> GetAsync<T> (object pk) where T : new();
94+
Task<object> GetAsync (object pk, TableMapping map);
95+
Task<T> GetAsync<T> (Expression<Func<T, bool>> predicate) where T : new();
96+
TimeSpan GetBusyTimeout ();
97+
SQLiteConnectionWithLock GetConnection ();
98+
Task<TableMapping> GetMappingAsync (Type type, CreateFlags createFlags = CreateFlags.None);
99+
Task<TableMapping> GetMappingAsync<T> (CreateFlags createFlags = CreateFlags.None) where T : new();
100+
Task<List<SQLiteConnection.ColumnInfo>> GetTableInfoAsync (string tableName);
101+
Task<int> InsertAllAsync (IEnumerable objects, bool runInTransaction = true);
102+
Task<int> InsertAllAsync (IEnumerable objects, string extra, bool runInTransaction = true);
103+
Task<int> InsertAllAsync (IEnumerable objects, Type objType, bool runInTransaction = true);
104+
Task<int> InsertAsync (object obj);
105+
Task<int> InsertAsync (object obj, Type objType);
106+
Task<int> InsertAsync (object obj, string extra);
107+
Task<int> InsertAsync (object obj, string extra, Type objType);
108+
Task<int> InsertOrReplaceAsync (object obj);
109+
Task<int> InsertOrReplaceAsync (object obj, Type objType);
110+
Task<List<T>> QueryAsync<T> (string query, params object[] args) where T : new();
111+
Task<List<object>> QueryAsync (TableMapping map, string query, params object[] args);
112+
Task<List<T>> QueryScalarsAsync<T> (string query, params object[] args);
113+
Task ReKeyAsync (string key);
114+
Task ReKeyAsync (byte[] key);
115+
Task RunInTransactionAsync (Action<SQLiteConnection> action);
116+
Task SetBusyTimeoutAsync (TimeSpan value);
117+
AsyncTableQuery<T> Table<T> () where T : new();
118+
Task<int> UpdateAllAsync (IEnumerable objects, bool runInTransaction = true);
119+
Task<int> UpdateAsync (object obj);
120+
Task<int> UpdateAsync (object obj, Type objType);
121+
}
122+
33123
/// <summary>
34124
/// A pooled asynchronous connection to a SQLite database.
35125
/// </summary>
36-
public partial class SQLiteAsyncConnection
126+
public partial class SQLiteAsyncConnection : ISQLiteAsyncConnection
37127
{
38128
readonly SQLiteConnectionString _connectionString;
39129

@@ -143,7 +233,7 @@ public Task EnableWriteAheadLoggingAsync ()
143233
/// Whether to store DateTime properties as ticks (true) or strings (false).
144234
/// </summary>
145235
public bool StoreDateTimeAsTicks => GetConnection ().StoreDateTimeAsTicks;
146-
236+
147237
/// <summary>
148238
/// Whether to store TimeSpan properties as ticks (true) or strings (false).
149239
/// </summary>
@@ -460,7 +550,7 @@ public Task<int> CreateIndexAsync<T> (Expression<Func<T, object>> property, bool
460550
}
461551

462552
/// <summary>
463-
/// Inserts the given object and (and updates its
553+
/// Inserts the given object and (and updates its
464554
/// auto incremented primary key if it has one).
465555
/// </summary>
466556
/// <param name="obj">
@@ -1176,6 +1266,30 @@ public Task<IEnumerable<object>> DeferredQueryAsync (TableMapping map, string qu
11761266
{
11771267
return ReadAsync (conn => (IEnumerable<object>)conn.DeferredQuery (map, query, args).ToList ());
11781268
}
1269+
1270+
/// <summary>
1271+
/// Change the encryption key for a SQLCipher database with "pragma rekey = ...".
1272+
/// </summary>
1273+
/// <param name="key">Encryption key plain text that is converted to the real encryption key using PBKDF2 key derivation</param>
1274+
public Task ReKeyAsync (string key)
1275+
{
1276+
return WriteAsync<object> (conn => {
1277+
conn.ReKey (key);
1278+
return null;
1279+
});
1280+
}
1281+
1282+
/// <summary>
1283+
/// Change the encryption key for a SQLCipher database.
1284+
/// </summary>
1285+
/// <param name="key">256-bit (32 byte) or 384-bit (48 bytes) encryption key data</param>
1286+
public Task ReKeyAsync (byte[] key)
1287+
{
1288+
return WriteAsync<object> (conn => {
1289+
conn.ReKey (key);
1290+
return null;
1291+
});
1292+
}
11791293
}
11801294

11811295
/// <summary>

0 commit comments

Comments
 (0)
Please sign in to comment.