From 0c05cac7add53b1a385667ba17e56fdae759824f Mon Sep 17 00:00:00 2001 From: David Thornley Date: Mon, 27 Apr 2015 11:48:00 +1000 Subject: [PATCH 1/3] Added SourceID support throughout platforms (marshals to sqlite3_sourceid API) --- src/SQLite.Net.Platform.Generic/SQLiteApiGeneric.cs | 5 +++++ .../SQLiteApiGenericInternal.cs | 3 +++ src/SQLite.Net.Platform.Win32/SQLiteApiWin32.cs | 5 +++++ src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs | 3 +++ src/SQLite.Net.Platform.WinRT/SQLiteApiWinRT.cs | 8 ++++++++ src/SQLite.Net.Platform.WindowsPhone8/SQLiteApiWP8.cs | 8 ++++++++ .../SQLiteApiAndroid.cs | 5 +++++ .../SQLiteApiAndroidInternal.cs | 3 +++ .../SQLiteApiIOS.cs | 5 +++++ .../SQLiteApiIOSInternal.cs | 3 +++ src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOS.cs | 5 +++++ .../SQLiteApiIOSInternal.cs | 3 +++ src/SQLite.Net/Interop/ISQLiteApi.cs | 1 + 13 files changed, 57 insertions(+) diff --git a/src/SQLite.Net.Platform.Generic/SQLiteApiGeneric.cs b/src/SQLite.Net.Platform.Generic/SQLiteApiGeneric.cs index 7d1423f02..5878dbdee 100644 --- a/src/SQLite.Net.Platform.Generic/SQLiteApiGeneric.cs +++ b/src/SQLite.Net.Platform.Generic/SQLiteApiGeneric.cs @@ -25,6 +25,11 @@ public int LibVersionNumber() return SQLiteApiGenericInternal.sqlite3_libversion_number(); } + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLiteApiGenericInternal.sqlite3_sourceid()); + } + public Result EnableLoadExtension(IDbHandle db, int onoff) { var internalDbHandle = (DbHandle) db; diff --git a/src/SQLite.Net.Platform.Generic/SQLiteApiGenericInternal.cs b/src/SQLite.Net.Platform.Generic/SQLiteApiGenericInternal.cs index ac74e1307..8e8a81a66 100644 --- a/src/SQLite.Net.Platform.Generic/SQLiteApiGenericInternal.cs +++ b/src/SQLite.Net.Platform.Generic/SQLiteApiGenericInternal.cs @@ -155,6 +155,9 @@ public static extern Result sqlite3_prepare_v2(IntPtr db, [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport("sqlite3", EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net.Platform.Win32/SQLiteApiWin32.cs b/src/SQLite.Net.Platform.Win32/SQLiteApiWin32.cs index 1cb84f71e..a9f636e85 100644 --- a/src/SQLite.Net.Platform.Win32/SQLiteApiWin32.cs +++ b/src/SQLite.Net.Platform.Win32/SQLiteApiWin32.cs @@ -24,6 +24,11 @@ public int LibVersionNumber() { return SQLiteApiWin32Internal.sqlite3_libversion_number(); } + + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLiteApiWin32Internal.sqlite3_sourceid()); + } public Result EnableLoadExtension(IDbHandle db, int onoff) { diff --git a/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs b/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs index f8366e893..8924bd8af 100644 --- a/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs +++ b/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs @@ -191,6 +191,9 @@ public static byte[] ColumnByteArray(IntPtr stmt, int index) [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net.Platform.WinRT/SQLiteApiWinRT.cs b/src/SQLite.Net.Platform.WinRT/SQLiteApiWinRT.cs index 6c4920a7a..0f737ac8c 100644 --- a/src/SQLite.Net.Platform.WinRT/SQLiteApiWinRT.cs +++ b/src/SQLite.Net.Platform.WinRT/SQLiteApiWinRT.cs @@ -157,6 +157,11 @@ public int LibVersionNumber() return SQLite3.sqlite3_libversion_number(); } + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLite3.sqlite3_sourceid()); + } + public Result EnableLoadExtension(IDbHandle db, int onoff) { return (Result)1; @@ -451,6 +456,9 @@ public static byte[] ColumnByteArray(IntPtr stmt, int index) [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport("sqlite3", EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net.Platform.WindowsPhone8/SQLiteApiWP8.cs b/src/SQLite.Net.Platform.WindowsPhone8/SQLiteApiWP8.cs index effaa6461..aee9cc0bf 100644 --- a/src/SQLite.Net.Platform.WindowsPhone8/SQLiteApiWP8.cs +++ b/src/SQLite.Net.Platform.WindowsPhone8/SQLiteApiWP8.cs @@ -31,6 +31,14 @@ public int LibVersionNumber() // return Sqlite3.sqlite3_libversion_number(); } + public string SourceID() + { + // not supported + return String.Empty; +// return Sqlite3.sqlite3_sourceid(); + } + + public Result EnableLoadExtension(IDbHandle db, int onoff) { var dbHandle = (DbHandle) db; diff --git a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroid.cs b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroid.cs index be7db78de..f5d96ac3a 100644 --- a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroid.cs +++ b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroid.cs @@ -25,6 +25,11 @@ public int LibVersionNumber() return SQLiteApiAndroidInternal.sqlite3_libversion_number(); } + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLiteApiAndroidInternal.sqlite3_sourceid()); + } + public Result EnableLoadExtension(IDbHandle db, int onoff) { var internalDbHandle = (DbHandle) db; diff --git a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs index e8af6e14a..2ce4ebffb 100644 --- a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs +++ b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs @@ -157,6 +157,9 @@ public static extern Result sqlite3_prepare_v2(IntPtr db, [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport(DllName, EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOS.cs b/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOS.cs index 1970a51c0..4058a2f83 100644 --- a/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOS.cs +++ b/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOS.cs @@ -24,6 +24,11 @@ public int LibVersionNumber() { return SQLiteApiIOSInternal.sqlite3_libversion_number(); } + + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLiteApiIOSInternal.sqlite3_sourceid()); + } public Result EnableLoadExtension(IDbHandle db, int onoff) { diff --git a/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOSInternal.cs b/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOSInternal.cs index 23548f1cd..c05c16de1 100644 --- a/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOSInternal.cs +++ b/src/SQLite.Net.Platform.XamarinIOS.Unified/SQLiteApiIOSInternal.cs @@ -157,6 +157,9 @@ public static extern Result sqlite3_prepare_v2(IntPtr db, [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport(DllName, EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOS.cs b/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOS.cs index 5b8acdaec..64245e3e6 100644 --- a/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOS.cs +++ b/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOS.cs @@ -20,6 +20,11 @@ public int LibVersionNumber() { return SQLiteApiIOSInternal.sqlite3_libversion_number(); } + public string SourceID() + { + return Marshal.PtrToStringAuto(SQLiteApiIOSInternal.sqlite3_sourceid()); + } + public Result EnableLoadExtension(IDbHandle db, int onoff) { var internalDbHandle = (DbHandle)db; return SQLiteApiIOSInternal.sqlite3_enable_load_extension(internalDbHandle.DbPtr, onoff); diff --git a/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOSInternal.cs b/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOSInternal.cs index e5332d455..840a40855 100644 --- a/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOSInternal.cs +++ b/src/SQLite.Net.Platform.XamarinIOS/SQLiteApiIOSInternal.cs @@ -157,6 +157,9 @@ public static extern Result sqlite3_prepare_v2(IntPtr db, [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); + [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr sqlite3_sourceid(); + #region Backup [DllImport(DllName, EntryPoint = "sqlite3_backup_init", CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SQLite.Net/Interop/ISQLiteApi.cs b/src/SQLite.Net/Interop/ISQLiteApi.cs index 01dda9afb..9901d2ee3 100644 --- a/src/SQLite.Net/Interop/ISQLiteApi.cs +++ b/src/SQLite.Net/Interop/ISQLiteApi.cs @@ -32,6 +32,7 @@ public interface ISQLiteApi ExtendedResult ExtendedErrCode(IDbHandle db); int LibVersionNumber(); + string SourceID(); Result EnableLoadExtension(IDbHandle db, int onoff); Result Close(IDbHandle db); Result Initialize(); From dd15dd4dfb855cede5035a5a27ed8c2ff8873fb6 Mon Sep 17 00:00:00 2001 From: David Thornley Date: Mon, 4 May 2015 15:39:20 +1000 Subject: [PATCH 2/3] * Fixed DLLImport reference for Win32. --- src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs b/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs index 8924bd8af..f4e583751 100644 --- a/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs +++ b/src/SQLite.Net.Platform.Win32/SQliteApiWin32Internal.cs @@ -191,7 +191,7 @@ public static byte[] ColumnByteArray(IntPtr stmt, int index) [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); - [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + [DllImport("SQLite.Interop.dll", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr sqlite3_sourceid(); #region Backup From bbda6b554afb92825a71b6d97deb861a2dc0f71d Mon Sep 17 00:00:00 2001 From: David Thornley Date: Mon, 4 May 2015 15:40:46 +1000 Subject: [PATCH 3/3] * Corrected DLLImport name usage (now consistently using DllName const string). --- .../SQLiteApiAndroidInternal.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs index 2ce4ebffb..bb9a69c64 100644 --- a/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs +++ b/src/SQLite.Net.Platform.XamarinAndroid/SQLiteApiAndroidInternal.cs @@ -62,10 +62,10 @@ public static extern int sqlite3_bind_text16(IntPtr stmt, [DllImport(DllName, EntryPoint = "sqlite3_close", CallingConvention = CallingConvention.Cdecl)] public static extern Result sqlite3_close(IntPtr db); - [DllImport("sqlite3", EntryPoint = "sqlite3_initialize", CallingConvention = CallingConvention.Cdecl)] + [DllImport(DllName, EntryPoint = "sqlite3_initialize", CallingConvention = CallingConvention.Cdecl)] public static extern Result sqlite3_initialize(); - [DllImport("sqlite3", EntryPoint = "sqlite3_shutdown", CallingConvention = CallingConvention.Cdecl)] + [DllImport(DllName, EntryPoint = "sqlite3_shutdown", CallingConvention = CallingConvention.Cdecl)] public static extern Result sqlite3_shutdown(); [DllImport(DllName, EntryPoint = "sqlite3_column_blob", CallingConvention = CallingConvention.Cdecl)] @@ -151,13 +151,13 @@ public static extern Result sqlite3_prepare_v2(IntPtr db, [DllImport(DllName, EntryPoint = "sqlite3_column_name16", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr sqlite3_column_name16(IntPtr stmt, int index); - [DllImport("sqlite3", EntryPoint = "sqlite3_extended_errcode", CallingConvention = CallingConvention.Cdecl)] + [DllImport(DllName, EntryPoint = "sqlite3_extended_errcode", CallingConvention = CallingConvention.Cdecl)] public static extern ExtendedResult sqlite3_extended_errcode(IntPtr db); - [DllImport("sqlite3", EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] + [DllImport(DllName, EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)] public static extern int sqlite3_libversion_number(); - [DllImport("sqlite3", EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] + [DllImport(DllName, EntryPoint = "sqlite3_sourceid", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr sqlite3_sourceid(); #region Backup