Skip to content

Commit 49866bf

Browse files
committed
Convert to netstandard 2. Removed all platform projects and tests. Fix unit tests.
1 parent 8e336de commit 49866bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+621
-840
lines changed

LICENSE.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//
2-
// Copyright (c) 2012 Krueger Systems, Inc.
2+
// Copyright (c) 2014-2019 Benjamin Mayrargue (https://github.com/softlion/)
33
// Copyright (c) 2013 Øystein Krog ([email protected])
4+
// Copyright (c) 2012 Krueger Systems, Inc.
45
//
56
// Permission is hereby granted, free of charge, to any person obtaining a copy
67
// of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
# Changes
1+
# Setup
22

3-
The iOS and Android versions now uses SQLitePCL.raw as a nuget dependency, so your app will use the latest version of SQLite instead of the buggy one provided by the OS !
3+
Add this package to your netstandard project:
44

5-
See https://github.com/ericsink/SQLitePCL.raw/ for more information on how to use SQLitePCL.raw
5+
```
6+
TODO
7+
```
8+
9+
And call this function in your executable projects (.net, ios, android, uwp, mac, ...):
610

7-
Since SQLitePCL.raw 0.9 you have to add a new nuget package in your platform project:
11+
```
12+
SQLitePCL.Batteries_V2.Init()
13+
```
14+
15+
16+
See https://github.com/ericsink/SQLitePCL.raw/ for more information on how to use SQLitePCL.raw
817

9-
SQLitePCL.plugin.sqlite3.ios_unified for ios
18+
If you search a simple key value store based on sqlite, alternative to Akavache, check https://github.com/softlion/KeyValueLite
1019

11-
and add an init code:
20+
# Changes
1221

13-
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_internal());
22+
* Netstandard 2.0 only
23+
* Uses SQLitePCLRaw for sqlite raw communication
1424

15-
For information:
16-
iOS 9.2 is shipped with sqlite 3.8.10.2
17-
iOS 8.4 is shipped with sqlite 3.8.5
1825

1926
# New Features compared to oysteinkrog
2027

@@ -40,91 +47,11 @@ iOS 8.4 is shipped with sqlite 3.8.5
4047
Signature: `IEnumerable<T> ExecuteSimpleQuery<T>(string query, params object[] args)`
4148
Usage: `ExecuteSimpleQuery<string>("select 'drop table ' || name || ';' from sqlite_master where type = 'table'")`
4249

43-
# Fork
44-
45-
This is a fork of oysteinkrog fork which is a fork of the original sqlite-net library (https://github.com/praeclarum/sqlite-net),
46-
which aims to improve the code quality by using modern technologies such as PCL (portable class library).
47-
48-
This is a fork of the original sqlite-net library (https://github.com/praeclarum/sqlite-net), which aims to improve the code quality by using modern technologies such as PCL (portable class library).
49-
50-
The project will avoid the use of #if-based conditional code and use platform-specific code injection instead.
51-
52-
I welcome pull requests, but keep in mind that this library is in heavy use and all changes must be:
53-
- Backwards-compatible (don't change database defaults).
54-
- Well tested (please add unit tests).
55-
56-
# Versioning
57-
58-
This project uses semantic versioning.
59-
60-
# API Changes
61-
62-
As part of the cleanup there are now some API changes.
63-
For the most part I hope these are self-explanatory, but here is a non-exhaustive list of changes.
64-
65-
## SQLiteConnection
66-
You now have to pass in an implementation of ISQlitePlatform in the SQLiteConnectionWithLock and SQLiteConnection constructors.
67-
The correct platform implementation is automatically added to the project.
68-
69-
At the moment these platforms are supported:
70-
- Win32 (bundles sqlite binaries for windows, works on both x86 and x64 automatically) (very well tested)
71-
- XamarinIOS and XamarinIOS.Unified
72-
- XamarinAndroid
73-
- WindowsPhone8 (contributed by Nick Cipollina, thanks!)
74-
- WinRT (Windows 8 and Windows Phone 8.1+) (contributed by Nick Cipollina and Micah Lewis, thanks!)
75-
- Generic (net4 project without any sqlite3 binaries, requires sqlite installed in the OS) (contributed by James Ottaway)
76-
77-
Note:
78-
To use the WP8.1/WinRT platform you must install the "SQLite for Windows Phone"/"SQLite for Windows" VSIX extension.
79-
Then, in the project, add a reference to the extension (in the Extensions section of the Add Reference dialog)
80-
If you have problems with signed apps take a look here: https://github.com/oysteinkrog/SQLite.Net-PCL/issues/25
81-
82-
## SQliteAsyncConnection
83-
The SQLiteAsyncConnection class now takes a Func<SQLiteConnectionWithLock> in the constructor instead of a path.
84-
This is done because the async classes are now just meant to be wrappers around the normal sqlite connection.
85-
86-
To use SQLiteAsyncConnection just create an instance of a SQLiteConnectionWithLock and pass in that through a func, e.g.:
87-
new SQLiteAsyncConnection(()=>_sqliteConnectionWithLock);
88-
89-
Please be aware that the Task.Run pattern used in SQLiteAsyncConnection can be considered an anti-pattern (libraries should not provide async methods unless they are truly async).
90-
This class is maintained for backwards compatability and for use-cases where async-isolation is handy.
91-
92-
## DateTime serialization
93-
94-
DateTime serialization is changed, in order to be consistent.
95-
When using the storeDateTimeAsTicks option, the DateTime is now serialized as Utc, and the returned DateTime is also in Utc.
96-
You can get the local time by using dateTime.ToLocalTime()
97-
98-
# SQLite.Net
50+
# Original Fork
9951

100-
SQLite.Net is an open source, minimal library to allow .NET and Mono applications to store data in [http://www.sqlite.org SQLite 3 databases]. It is written in C# and is meant to be simply compiled in with your projects. It was first designed to work with [MonoTouch](http://xamarin.com) on the iPhone, but has grown up to work on all the platforms (Mono for Android, .NET, Silverlight, WP7, WinRT, Azure, etc.).
52+
https://github.com/praeclarum/sqlite-net
10153

102-
SQLite.Net was designed as a quick and convenient database layer. Its design follows from these *goals*:
103-
104-
* Very easy to integrate with existing projects and with MonoTouch projects.
105-
106-
* Thin wrapper over SQLite and should be fast and efficient. (The library should not be the performance bottleneck of your queries.)
107-
108-
* Very simple methods for executing CRUD operations and queries safely (using parameters) and for retrieving the results of those query in a strongly typed fashion.
109-
110-
* Works with your data model without forcing you to change your classes. (Contains a small reflection-driven ORM layer.)
111-
112-
* 0 dependencies aside from a [compiled form of the sqlite2 library](http://www.sqlite.org/download.html).
113-
114-
*Non-goals* include:
115-
116-
* Not an ADO.NET implementation. This is not a full SQLite driver. If you need that, use [Mono.Data.SQLite](http://www.mono-project.com/SQLite) or [csharp-sqlite](http://code.google.com/p/csharp-sqlite/).
117-
118-
## License
119-
This projected is licensed under the terms of the MIT license.
120-
See LICENSE.TXT
121-
122-
## Meta
123-
124-
This is an open source project that welcomes contributions/suggestions/bug reports from those who use it. If you have any ideas on how to improve the library, please [post an issue here on github](https://github.com/praeclarum/SQLite.Net/issues). Please check out the [How to Contribute](https://github.com/praeclarum/SQLite.Net/wiki/How-to-Contribute).
125-
126-
127-
# Example Time!
54+
# Examples
12855

12956
Please consult the source code (see unit tests) for more examples.
13057

@@ -203,54 +130,4 @@ You can perform low-level updates of the database using the `Execute` method.
203130

204131
## Asynchronous API
205132

206-
The asynchronous library uses the Task Parallel Library (TPL). As such, normal use of `Task` objects, and the `async` and `await` keywords
207-
will work for you.
208-
209-
Once you have defined your entity, you can automatically generate tables by calling `CreateTableAsync`:
210-
211-
var conn = new SQLiteAsyncConnection(()=>sqliteConnection, "foofoo");
212-
conn.CreateTableAsync<Stock>().ContinueWith((results) =>
213-
{
214-
Debug.WriteLine("Table created!");
215-
});
216-
217-
You can insert rows in the database using `Insert`. If the table contains an auto-incremented primary key, then the value for that key will be available to you after the insert:
218-
219-
Stock stock = new Stock()
220-
{
221-
Symbol = "AAPL"
222-
};
223-
224-
var conn = new SQLiteAsyncConnection(()=>sqliteConnection, "foofoo");
225-
conn.InsertAsync(stock).ContinueWith((t) =>
226-
{
227-
Debug.WriteLine("New customer ID: {0}", stock.Id);
228-
});
229-
230-
Similar methods exist for `UpdateAsync` and `DeleteAsync`.
231-
232-
Querying for data is most straightforwardly done using the `Table` method. This will return an `AsyncTableQuery` instance back, whereupon
233-
you can add predictates for constraining via WHERE clauses and/or adding ORDER BY. The database is not physically touched until one of the special
234-
retrieval methods - `ToListAsync`, `FirstAsync`, or `FirstOrDefaultAsync` - is called.
235-
236-
var conn = new SQLiteAsyncConnection(()=>sqliteConnection, "foofoo");
237-
var query = conn.Table<Stock>().Where(v => v.Symbol.StartsWith("A"));
238-
239-
query.ToListAsync().ContinueWith((t) =>
240-
{
241-
foreach (var stock in t.Result)
242-
Debug.WriteLine("Stock: " + stock.Symbol);
243-
});
244-
245-
There are a number of low-level methods available. You can also query the database directly via the `QueryAsync` method. Over and above the change
246-
operations provided by `InsertAsync` etc you can issue `ExecuteAsync` methods to change sets of data directly within the database.
247-
248-
Another helpful method is `ExecuteScalarAsync`. This allows you to return a scalar value from the database easily:
249-
250-
var conn = new SQLiteAsyncConnection("foofoo");
251-
conn.ExecuteScalarAsync<int>("select count(*) from Stock", null).ContinueWith((t) =>
252-
{
253-
Debug.WriteLine(string.Format("Found '{0}' stock items.", t.Result));
254-
});
255-
256-
133+
The asynchronous API has been removed, as it was only wrapping synchronous methods in Task.Run(), which has nasty side effects as multiple Tasks are queued. Use your own Task.Run to achieve the same effect.

tests/SQLite.Net.Tests.Generic/ArithmeticTest.cs renamed to SQLite.Net.Tests/ArithmeticTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TestObjInt : TestObjBase<int>
2929
public class TestDb : SQLiteConnection
3030
{
3131
public TestDb(String path)
32-
: base(new SQLitePlatformTest(), path)
32+
: base(path)
3333
{
3434
CreateTable<TestObjString>();
3535
CreateTable<TestObjInt>();

tests/SQLite.Net.Tests.Generic/BackupTest.cs renamed to SQLite.Net.Tests/BackupTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class BackupTestObj3
4646

4747
public class BackupTestDb : SQLiteConnection
4848
{
49-
public BackupTestDb(String path) : base(new SQLitePlatformTest(), path)
49+
public BackupTestDb(String path) : base(path)
5050
{
5151
CreateTable<BackupTestObj>();
5252
CreateTable<BackupTestObj2>();
@@ -89,7 +89,7 @@ public async Task CreateBackup()
8989
Assert.AreEqual(numIn2, result2.Count);
9090
Assert.AreEqual(obj2.Text, result2.First().Text);
9191

92-
string destDbPath = await srcDb.CreateDatabaseBackup(new SQLitePlatformTest());
92+
string destDbPath = await srcDb.CreateDatabaseBackup();
9393
// Assert.IsTrue(File.Exists(destDbPath));
9494

9595
SQLiteConnection destDb = new BackupTestDb(destDbPath);

tests/SQLite.Net.Tests.Generic/BlobSerializationTest.cs renamed to SQLite.Net.Tests/BlobSerializationTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class BlobSerializationTest : BaseTest
1616
public class BlobDatabase : SQLiteConnection
1717
{
1818
public BlobDatabase(IBlobSerializer serializer) :
19-
base(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase(), false, serializer)
19+
base(TestPath.CreateTemporaryDatabase(), false, serializer)
2020
{
2121
DropTable<ComplexOrder>();
2222
}
@@ -331,11 +331,7 @@ public void SavesUnsupportedTypes()
331331
{
332332
if (t == typeof(DivideByZeroException))
333333
{
334-
#if __WINRT__ || WINDOWS_PHONE
335-
var json = Encoding.UTF8.GetString(d, 0, d.Length);
336-
#else
337334
var json = Encoding.UTF8.GetString(d);
338-
#endif
339335
var result = JsonConvert.DeserializeObject<DivideByZeroException>(json);
340336
return result;
341337
}
@@ -358,7 +354,11 @@ public void SavesUnsupportedTypes()
358354
var dbItem = db.Find<UnsupportedTypes>(item.Id);
359355

360356
Assert.AreEqual(item.Id, dbItem.Id);
361-
Assert.AreEqual(item.DateTimeOffset, dbItem.DateTimeOffset);
357+
Assert.AreEqual(item.DateTimeOffset, dbItem.DateTimeOffset);
358+
//most db stores datetimeoffset as utc, forgetting the offset part. This one is not an exception.
359+
//TODO: test fails
360+
Assert.AreEqual(item.DateTimeOffset.Offset, dbItem.DateTimeOffset.Offset);
361+
//TODO: test fails
362362
Assert.AreEqual(item.DivideByZeroException.Message, dbItem.DivideByZeroException.Message);
363363
}
364364
}

tests/SQLite.Net.Tests.Generic/BooleanTest.cs renamed to SQLite.Net.Tests/BooleanTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public override string ToString()
2525

2626
public class DbAcs : SQLiteConnection
2727
{
28-
public DbAcs(ISQLitePlatform sqlitePlatform, String path)
29-
: base(sqlitePlatform, path)
28+
public DbAcs(String path)
29+
: base(path)
3030
{
3131
TraceListener = DebugTraceListener.Instance;
3232
}
@@ -46,9 +46,8 @@ public int CountWithFlag(Boolean flag)
4646
[Test]
4747
public void TestBoolean()
4848
{
49-
var sqlite3Platform = new SQLitePlatformTest();
5049
string tmpFile = TestPath.CreateTemporaryDatabase();
51-
var db = new DbAcs(sqlite3Platform, tmpFile);
50+
var db = new DbAcs(tmpFile);
5251
db.buildTable();
5352
for (int i = 0; i < 10; i++)
5453
{

tests/SQLite.Net.Tests.Generic/ByteArrayTest.cs renamed to SQLite.Net.Tests/ByteArrayTest.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ namespace SQLite.Net.Tests
77
[TestFixture]
88
public class ByteArrayTest : BaseTest
99
{
10-
[SetUp]
11-
public void SetUp()
12-
{
13-
_sqlite3Platform = new SQLitePlatformTest();
14-
}
15-
16-
private SQLitePlatformTest _sqlite3Platform;
17-
1810
public class ByteArrayClass
1911
{
2012
[PrimaryKey, AutoIncrement]
@@ -45,6 +37,9 @@ public void AssertEquals(ByteArrayClass other)
4537
[Description("Create objects with various byte arrays and check they can be stored and retrieved correctly")]
4638
public void ByteArrays()
4739
{
40+
var database = new SQLiteConnection(TestPath.CreateTemporaryDatabase());
41+
database.CreateTable<ByteArrayClass>();
42+
4843
//Byte Arrays for comparisson
4944
ByteArrayClass[] byteArrays =
5045
{
@@ -68,18 +63,19 @@ public void ByteArrays()
6863
{
6964
bytes = new byte[] {1, 0, 1}
7065
},
71-
new ByteArrayClass
72-
{
73-
bytes = new byte[] {}
74-
}, //Empty byte array should stay empty (and not become null)
66+
//new ByteArrayClass
67+
//{
68+
// //Rule should be that "Empty byte array should stay empty (and not become null)"
69+
// //But "The return value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer." (https://www.sqlite.org/c3ref/column_blob.html)
70+
// //So an empty byte array will become null
71+
// bytes = new byte[] {}
72+
//},
7573
new ByteArrayClass
7674
{
7775
bytes = null
7876
} //Null should be supported
7977
};
8078

81-
var database = new SQLiteConnection(_sqlite3Platform, TestPath.CreateTemporaryDatabase());
82-
database.CreateTable<ByteArrayClass>();
8379

8480
//Insert all of the ByteArrayClass
8581
foreach (ByteArrayClass b in byteArrays)
@@ -113,7 +109,7 @@ public void ByteArrayWhere()
113109
new ByteArrayClass() { bytes = null } //Null should be supported
114110
};
115111

116-
var database = new SQLiteConnection(_sqlite3Platform, TestPath.CreateTemporaryDatabase());
112+
var database = new SQLiteConnection(TestPath.CreateTemporaryDatabase());
117113
database.CreateTable<ByteArrayClass>();
118114

119115
byte[] criterion = new byte[] { 1, 0, 1 };
@@ -150,7 +146,7 @@ public void ByteArrayWhereNull()
150146
new ByteArrayClass() { bytes = null } //Null should be supported
151147
};
152148

153-
var database = new SQLiteConnection(_sqlite3Platform, TestPath.CreateTemporaryDatabase());
149+
var database = new SQLiteConnection(TestPath.CreateTemporaryDatabase());
154150
database.CreateTable<ByteArrayClass>();
155151

156152
byte[] criterion = null;
@@ -189,7 +185,7 @@ public void LargeByteArray()
189185
bytes = bytes
190186
};
191187

192-
var database = new SQLiteConnection(_sqlite3Platform, TestPath.CreateTemporaryDatabase());
188+
var database = new SQLiteConnection(TestPath.CreateTemporaryDatabase());
193189
database.CreateTable<ByteArrayClass>();
194190

195191
//Insert the ByteArrayClass

tests/SQLite.Net.Tests.Generic/CollateTest.cs renamed to SQLite.Net.Tests/CollateTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public override string ToString()
3232

3333
public class TestDb : SQLiteConnection
3434
{
35-
public TestDb(ISQLitePlatform sqlitePlatform, String path)
36-
: base(sqlitePlatform, path)
35+
public TestDb(String path)
36+
: base(path)
3737
{
3838
TraceListener = DebugTraceListener.Instance;
3939
CreateTable<TestObj>();
@@ -51,7 +51,7 @@ public void Collate()
5151
CollateNoCase = "Alpha ",
5252
};
5353

54-
var db = new TestDb(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());
54+
var db = new TestDb(TestPath.CreateTemporaryDatabase());
5555

5656
db.Insert(obj);
5757

@@ -121,8 +121,8 @@ public override string ToString()
121121

122122
public class TestDbSubtype : SQLiteConnection
123123
{
124-
public TestDbSubtype(ISQLitePlatform sqlitePlatform, String path)
125-
: base(sqlitePlatform, path)
124+
public TestDbSubtype(String path)
125+
: base(path)
126126
{
127127
TraceListener = DebugTraceListener.Instance;
128128
CreateTable<TestObjWithSubtypedAttributes>();
@@ -143,7 +143,7 @@ public void CollateAttributeSubtype()
143143
CollateNoCase = "Alpha ",
144144
};
145145

146-
var db = new TestDbSubtype(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());
146+
var db = new TestDbSubtype(TestPath.CreateTemporaryDatabase());
147147

148148
db.Insert(obj);
149149

0 commit comments

Comments
 (0)