From 72bcb26e090b06b021945e770116a4ffef96f25b Mon Sep 17 00:00:00 2001 From: Victor Hugo Barros Date: Tue, 11 Sep 2018 16:35:03 -0700 Subject: [PATCH 1/3] Support for JSON1 extension --- src/SQLite.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/SQLite.cs b/src/SQLite.cs index cc6689e9..1e7f7dce 100644 --- a/src/SQLite.cs +++ b/src/SQLite.cs @@ -35,6 +35,9 @@ using System.Linq.Expressions; using System.Text; using System.Threading; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.IO; #if USE_CSHARP_SQLITE using Sqlite3 = Community.CsharpSqlite.Sqlite3; @@ -2508,6 +2511,9 @@ public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks) else if (clrType == typeof (Guid)) { return "varchar(36)"; } + else if (clrType.GetTypeInfo ().IsDefined (typeof (DataContractAttribute))) { + return SQLite3.LibVersionNumber() >= 3009000 ? "json" : "text"; + } else { throw new NotSupportedException ("Don't know about " + clrType); } @@ -2834,6 +2840,15 @@ internal static void BindParameter (Sqlite3Statement stmt, int index, object val } else if (value is UriBuilder) { SQLite3.BindText (stmt, index, ((UriBuilder)value).ToString (), -1, NegativePointer); + } + else if (value.GetType ().GetTypeInfo ().IsDefined (typeof (DataContractAttribute))) { + using (var stream = new MemoryStream ()) + { + new DataContractJsonSerializer (value.GetType()).WriteObject(stream, value); + var bytes = stream.ToArray (); + var json = Encoding.UTF8.GetString (bytes, 0, bytes.Length); + SQLite3.BindText (stmt, index, json, -1, NegativePointer); + } } else { // Now we could possibly get an enum, retrieve cached info @@ -2950,7 +2965,14 @@ object ReadCol (Sqlite3Statement stmt, int index, SQLite3.ColType type, Type clr else if (clrType == typeof(UriBuilder)) { var text = SQLite3.ColumnString(stmt, index); return new UriBuilder(text); - } + } + else if (clrType.GetTypeInfo ().IsDefined (typeof (DataContractAttribute))) { + var json = SQLite3.ColumnString (stmt, index); + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes (json))) + { + return new DataContractJsonSerializer (clrType).ReadObject (stream); + } + } else { throw new NotSupportedException ("Don't know how to read " + clrType); } From 01d42ede5f0196e3fc2b149f7cd5726627ad2cb4 Mon Sep 17 00:00:00 2001 From: Victor Hugo Barros Date: Wed, 12 Sep 2018 16:10:20 -0700 Subject: [PATCH 2/3] upgrading to .net standard 2.0 and adding System.Runtime.Serialization assembly --- nuget/SQLite-net-base/SQLite-net-base.csproj | 2 +- nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj | 2 +- nuget/SQLite-net-std/SQLite-net-std.csproj | 2 +- tests/ApiDiff/ApiDiff.csproj | 2 ++ tests/SQLite.Tests.csproj | 2 ++ tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/nuget/SQLite-net-base/SQLite-net-base.csproj b/nuget/SQLite-net-base/SQLite-net-base.csproj index bf4403f9..bdeee13e 100644 --- a/nuget/SQLite-net-base/SQLite-net-base.csproj +++ b/nuget/SQLite-net-base/SQLite-net-base.csproj @@ -1,7 +1,7 @@ - netstandard1.1 + netstandard2.0 SQLite-net 1.0.0 SQLite-net Official .NET Standard Base Library diff --git a/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj b/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj index 86347b67..4d021f57 100644 --- a/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj +++ b/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj @@ -1,7 +1,7 @@ - netstandard1.1 + netstandard2.0 SQLite-net 1.0.0 SQLite-net Official SQLCipher .NET Standard Library diff --git a/nuget/SQLite-net-std/SQLite-net-std.csproj b/nuget/SQLite-net-std/SQLite-net-std.csproj index 6b68fdfb..faf28e8b 100644 --- a/nuget/SQLite-net-std/SQLite-net-std.csproj +++ b/nuget/SQLite-net-std/SQLite-net-std.csproj @@ -1,7 +1,7 @@ - netstandard1.1 + netstandard2.0 SQLite-net 1.0.0 SQLite-net Official .NET Standard Library diff --git a/tests/ApiDiff/ApiDiff.csproj b/tests/ApiDiff/ApiDiff.csproj index 577d5393..def94bf1 100644 --- a/tests/ApiDiff/ApiDiff.csproj +++ b/tests/ApiDiff/ApiDiff.csproj @@ -33,6 +33,8 @@ ..\..\packages\ListDiff.1.0.7\lib\netstandard1.0\ListDiff.dll + + diff --git a/tests/SQLite.Tests.csproj b/tests/SQLite.Tests.csproj index 674f1cbe..73571998 100644 --- a/tests/SQLite.Tests.csproj +++ b/tests/SQLite.Tests.csproj @@ -37,6 +37,8 @@ + + diff --git a/tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj b/tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj index 4acd4ebd..18e112f3 100644 --- a/tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj +++ b/tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj @@ -90,6 +90,7 @@ + From 7fc4a958004ae61f8784ea0f71ae71799f2791ee Mon Sep 17 00:00:00 2001 From: Victor Hugo Barros Date: Mon, 15 Oct 2018 16:48:00 -0700 Subject: [PATCH 3/3] adding support for Nuget Build Packaging --- nuget/SQLite-net-base/SQLite-net-base.csproj | 1 + nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj | 1 + nuget/SQLite-net-std/SQLite-net-std.csproj | 1 + nuget/SQLite-net/SQLite-net.csproj | 2 ++ nuget/SQLite-net/packages.config | 1 + 5 files changed, 6 insertions(+) diff --git a/nuget/SQLite-net-base/SQLite-net-base.csproj b/nuget/SQLite-net-base/SQLite-net-base.csproj index bdeee13e..8215d3e0 100644 --- a/nuget/SQLite-net-base/SQLite-net-base.csproj +++ b/nuget/SQLite-net-base/SQLite-net-base.csproj @@ -31,5 +31,6 @@ + diff --git a/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj b/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj index 4d021f57..24ee70da 100644 --- a/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj +++ b/nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj @@ -23,6 +23,7 @@ + diff --git a/nuget/SQLite-net-std/SQLite-net-std.csproj b/nuget/SQLite-net-std/SQLite-net-std.csproj index faf28e8b..13449ede 100644 --- a/nuget/SQLite-net-std/SQLite-net-std.csproj +++ b/nuget/SQLite-net-std/SQLite-net-std.csproj @@ -23,6 +23,7 @@ + diff --git a/nuget/SQLite-net/SQLite-net.csproj b/nuget/SQLite-net/SQLite-net.csproj index d6ffdb6a..9ed7ac06 100644 --- a/nuget/SQLite-net/SQLite-net.csproj +++ b/nuget/SQLite-net/SQLite-net.csproj @@ -1,5 +1,6 @@  + 10.0 @@ -76,4 +77,5 @@ --> + diff --git a/nuget/SQLite-net/packages.config b/nuget/SQLite-net/packages.config index a948fa85..63eb0e84 100644 --- a/nuget/SQLite-net/packages.config +++ b/nuget/SQLite-net/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file