Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JSON1 extension #752

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nuget/SQLite-net-base/SQLite-net-base.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>SQLite-net</AssemblyName>
<Version>1.0.0</Version>
<AssemblyTitle>SQLite-net Official .NET Standard Base Library</AssemblyTitle>
Expand Down Expand Up @@ -31,5 +31,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.core" Version="1.1.11" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>SQLite-net</AssemblyName>
<Version>1.0.0</Version>
<AssemblyTitle>SQLite-net Official SQLCipher .NET Standard Library</AssemblyTitle>
Expand All @@ -23,6 +23,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_sqlcipher" Version="1.1.11" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\SQLite.cs">
Expand Down
3 changes: 2 additions & 1 deletion nuget/SQLite-net-std/SQLite-net-std.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>SQLite-net</AssemblyName>
<Version>1.0.0</Version>
<AssemblyTitle>SQLite-net Official .NET Standard Library</AssemblyTitle>
Expand All @@ -23,6 +23,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="1.1.11" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\SQLite.cs">
Expand Down
2 changes: 2 additions & 0 deletions nuget/SQLite-net/SQLite-net.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.props" Condition="Exists('..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -76,4 +77,5 @@
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets" Condition="Exists('..\..\packages\NuGet.Build.Packaging.0.2.2\build\NuGet.Build.Packaging.targets')" />
</Project>
1 change: 1 addition & 0 deletions nuget/SQLite-net/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.Build.Packaging" version="0.2.2" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.11" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="SQLitePCLRaw.core" version="1.1.11" targetFramework="portable45-net45+win8+wp8+wpa81" />
</packages>
24 changes: 23 additions & 1 deletion src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ApiDiff/ApiDiff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<Reference Include="ListDiff">
<HintPath>..\..\packages\ListDiff.1.0.7\lib\netstandard1.0\ListDiff.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
2 changes: 2 additions & 0 deletions tests/SQLite.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
<Reference Include="MonoTouch.NUnitLite" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="LaunchScreen.storyboard" />
Expand Down