diff --git a/.gitignore b/.gitignore
index 9554bc2..f68c05c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,4 +20,7 @@
*.pidb.meta
# Unity3D Generated File On Crash Reports
-sysinfo.txt
\ No newline at end of file
+sysinfo.txt
+
+.DS_Store
+.idea/
diff --git a/README.md b/README.md
index a551751..f1d57c7 100644
--- a/README.md
+++ b/README.md
@@ -17,18 +17,28 @@
# Watchout
* If You are on Windows, need to `libeay32.dll` from https://wiki.openssl.org/index.php/Binaries
* If You are on iOS, need to modify [link.xml](https://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html) for prevent stripping by Unity.
+* Check [Issues](https://github.com/netpyoung/SqlCipher4Unity3D/issues)
# The fast track
All you have to do to start using it in your project:
-1. [Download this .unitypackage](https://github.com/netpyoung/SqlCipher4Unity3D/raw/master/SqlCipher4Unity3D.unitypackage), extract its content on your Unity3D Project. It contains the dlls that Unity3d will need to access sqlite.
+1. [Download this .unitypackage](https://github.com/netpyoung/SqlCipher4Unity3D/raw/master/SqlCipher4Unity3D-v1.0.0.unitypackage), extract its content on your Unity3D Project. It contains the dlls that Unity3d will need to access sqlite.
4. **You’re done!**
+# Sqlchipher lib version
+* android : 3.5.9
+ - https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
+ - precompiled : https://github.com/sqlcipher/sqlcipher-android-tests/tree/master/app/libs
+
+
+
# Example
If you want to try it I've uploaded a small example that you will be able to find in the "Example" folder. Download the folder and open it with Unity3d to give it a try. It contains classes that will help you to start.
+# codefix
+https://github.com/Leopotam/vscode-csharpfixformat
# Acknowledgements
This project is based on the work of:
diff --git a/SqlCipher4Unity3D.unitypackage b/SqlCipher4Unity3D-v1.0.0.unitypackage
similarity index 52%
rename from SqlCipher4Unity3D.unitypackage
rename to SqlCipher4Unity3D-v1.0.0.unitypackage
index ace659a..4a030d3 100644
Binary files a/SqlCipher4Unity3D.unitypackage and b/SqlCipher4Unity3D-v1.0.0.unitypackage differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86.meta b/SqlCipher4Unity3D/Assets/Plugins.meta
similarity index 60%
rename from SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86.meta
rename to SqlCipher4Unity3D/Assets/Plugins.meta
index dcdd9b7..6bfb4bb 100644
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86.meta
+++ b/SqlCipher4Unity3D/Assets/Plugins.meta
@@ -1,9 +1,10 @@
fileFormatVersion: 2
-guid: 127f0aaf74b9540b4ad306d147930d41
+guid: b1b1fa6bb2d7a404a94caf3899990815
folderAsset: yes
-timeCreated: 1474990725
+timeCreated: 1529076095
licenseType: Free
DefaultImporter:
+ externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a.meta b/SqlCipher4Unity3D/Assets/Plugins/Editor.meta
similarity index 60%
rename from SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a.meta
rename to SqlCipher4Unity3D/Assets/Plugins/Editor.meta
index f834ad2..d11d2bf 100644
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a.meta
+++ b/SqlCipher4Unity3D/Assets/Plugins/Editor.meta
@@ -1,9 +1,10 @@
fileFormatVersion: 2
-guid: 6b2e0bb4f78bd4b2ca44c545632b0699
+guid: f4a705c98a92b40c7b46d4396b3c71b3
folderAsset: yes
-timeCreated: 1474993115
+timeCreated: 1529076095
licenseType: Free
DefaultImporter:
+ externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/example/Scenes.meta b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains.meta
similarity index 60%
rename from SqlCipher4Unity3D/Assets/example/Scenes.meta
rename to SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains.meta
index df90c30..45d3071 100644
--- a/SqlCipher4Unity3D/Assets/example/Scenes.meta
+++ b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains.meta
@@ -1,9 +1,10 @@
fileFormatVersion: 2
-guid: b8ab4eabea1d94b49808216caa3ed5d0
+guid: 50395a360f242446aa26c190bebebe26
folderAsset: yes
-timeCreated: 1453576960
+timeCreated: 1529076095
licenseType: Free
DefaultImporter:
+ externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll
new file mode 100644
index 0000000..7a5211f
Binary files /dev/null and b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll differ
diff --git a/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta
new file mode 100644
index 0000000..51a257e
--- /dev/null
+++ b/SqlCipher4Unity3D/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta
@@ -0,0 +1,32 @@
+fileFormatVersion: 2
+guid: 1e4b845353e8f4746a99f67bd4576954
+timeCreated: 1529076122
+licenseType: Free
+PluginImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ iconMap: {}
+ executionOrder: {}
+ isPreloaded: 0
+ isOverridable: 0
+ platformData:
+ - first:
+ Any:
+ second:
+ enabled: 0
+ settings: {}
+ - first:
+ Editor: Editor
+ second:
+ enabled: 1
+ settings:
+ DefaultValueInitialized: true
+ - first:
+ Windows Store Apps: WindowsStoreApps
+ second:
+ enabled: 0
+ settings:
+ CPU: AnyCPU
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/.DS_Store b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/.DS_Store
new file mode 100644
index 0000000..0b9632c
Binary files /dev/null and b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/.DS_Store differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/.DS_Store b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/.DS_Store
new file mode 100644
index 0000000..8e08b6a
Binary files /dev/null and b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/.DS_Store differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar
new file mode 100644
index 0000000..dbe692a
Binary files /dev/null and b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar.meta b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar.meta
new file mode 100644
index 0000000..34d7532
--- /dev/null
+++ b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/android-database-sqlcipher-3.5.9.aar.meta
@@ -0,0 +1,31 @@
+fileFormatVersion: 2
+guid: 19954fdde7bc74f71b4faa2b958e62eb
+timeCreated: 1529075790
+licenseType: Free
+PluginImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ iconMap: {}
+ executionOrder: {}
+ isPreloaded: 0
+ isOverridable: 0
+ platformData:
+ - first:
+ Android: Android
+ second:
+ enabled: 1
+ settings: {}
+ - first:
+ Any:
+ second:
+ enabled: 0
+ settings: {}
+ - first:
+ Editor: Editor
+ second:
+ enabled: 0
+ settings:
+ DefaultValueInitialized: true
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so
deleted file mode 100755
index 3a66a2f..0000000
Binary files a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so and /dev/null differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so.meta b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so.meta
deleted file mode 100644
index c546f05..0000000
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/armeabi-v7a/libsqlcipher.so.meta
+++ /dev/null
@@ -1,55 +0,0 @@
-fileFormatVersion: 2
-guid: f933ca8a3455e488495ae127ffbe92a3
-timeCreated: 1474993115
-licenseType: Free
-PluginImporter:
- serializedVersion: 1
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- platformData:
- Android:
- enabled: 1
- settings:
- CPU: ARMv7
- Any:
- enabled: 0
- settings: {}
- Editor:
- enabled: 0
- settings:
- CPU: AnyCPU
- DefaultValueInitialized: true
- OS: AnyOS
- Linux:
- enabled: 0
- settings:
- CPU: x86
- Linux64:
- enabled: 0
- settings:
- CPU: x86_64
- OSXIntel:
- enabled: 0
- settings:
- CPU: AnyCPU
- OSXIntel64:
- enabled: 0
- settings:
- CPU: AnyCPU
- Win:
- enabled: 0
- settings:
- CPU: AnyCPU
- Win64:
- enabled: 0
- settings:
- CPU: AnyCPU
- iOS:
- enabled: 0
- settings:
- CompileFlags:
- FrameworkDependencies:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so
deleted file mode 100755
index fe16038..0000000
Binary files a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so and /dev/null differ
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so.meta b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so.meta
deleted file mode 100644
index 6b661f3..0000000
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Plugins/Android/libs/x86/libsqlcipher.so.meta
+++ /dev/null
@@ -1,55 +0,0 @@
-fileFormatVersion: 2
-guid: 301805b21c6614d5b82c1d5b9a17f965
-timeCreated: 1474990725
-licenseType: Free
-PluginImporter:
- serializedVersion: 1
- iconMap: {}
- executionOrder: {}
- isPreloaded: 0
- platformData:
- Android:
- enabled: 1
- settings:
- CPU: x86
- Any:
- enabled: 0
- settings: {}
- Editor:
- enabled: 0
- settings:
- CPU: AnyCPU
- DefaultValueInitialized: true
- OS: AnyOS
- Linux:
- enabled: 0
- settings:
- CPU: x86
- Linux64:
- enabled: 0
- settings:
- CPU: x86_64
- OSXIntel:
- enabled: 0
- settings:
- CPU: AnyCPU
- OSXIntel64:
- enabled: 0
- settings:
- CPU: AnyCPU
- Win:
- enabled: 0
- settings:
- CPU: AnyCPU
- Win64:
- enabled: 0
- settings:
- CPU: AnyCPU
- iOS:
- enabled: 0
- settings:
- CompileFlags:
- FrameworkDependencies:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3.cs b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3.cs
index 822c5ff..e931e56 100644
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3.cs
+++ b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3.cs
@@ -1,491 +1,280 @@
-//
-// Copyright (c) 2009-2012 Krueger Systems, Inc.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#if WINDOWS_PHONE && !USE_WP8_NATIVE_SQLITE
-#define USE_CSHARP_SQLITE
-#endif
-
-using System;
-using System.Diagnostics;
using System.Runtime.InteropServices;
-using System.Collections.Generic;
-using System.Reflection;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Threading;
-
-#if USE_CSHARP_SQLITE
-using Sqlite3 = Community.CsharpSqlite.Sqlite3;
-using Sqlite3DatabaseHandle = Community.CsharpSqlite.Sqlite3.sqlite3;
-using Sqlite3Statement = Community.CsharpSqlite.Sqlite3.Vdbe;
-#elif USE_WP8_NATIVE_SQLITE
-using Sqlite3 = Sqlite.Sqlite3;
-using Sqlite3DatabaseHandle = Sqlite.Database;
-using Sqlite3Statement = Sqlite.Statement;
-#else
+using System.Text;
using Sqlite3DatabaseHandle = System.IntPtr;
using Sqlite3Statement = System.IntPtr;
-#endif
-
namespace SqlCipher4Unity3D
{
- public static partial class SQLite3
- {
- public enum Result : int {
- OK = 0,
- Error = 1,
- Internal = 2,
- Perm = 3,
- Abort = 4,
- Busy = 5,
- Locked = 6,
- NoMem = 7,
- ReadOnly = 8,
- Interrupt = 9,
- IOError = 10,
- Corrupt = 11,
- NotFound = 12,
- Full = 13,
- CannotOpen = 14,
- LockErr = 15,
- Empty = 16,
- SchemaChngd = 17,
- TooBig = 18,
- Constraint = 19,
- Mismatch = 20,
- Misuse = 21,
- NotImplementedLFS = 22,
- AccessDenied = 23,
- Format = 24,
- Range = 25,
- NonDBFile = 26,
- Notice = 27,
- Warning = 28,
- Row = 100,
- Done = 101
- }
-
- public enum ExtendedResult : int {
- IOErrorRead = (Result.IOError | (1 << 8)),
- IOErrorShortRead = (Result.IOError | (2 << 8)),
- IOErrorWrite = (Result.IOError | (3 << 8)),
- IOErrorFsync = (Result.IOError | (4 << 8)),
- IOErrorDirFSync = (Result.IOError | (5 << 8)),
- IOErrorTruncate = (Result.IOError | (6 << 8)),
- IOErrorFStat = (Result.IOError | (7 << 8)),
- IOErrorUnlock = (Result.IOError | (8 << 8)),
- IOErrorRdlock = (Result.IOError | (9 << 8)),
- IOErrorDelete = (Result.IOError | (10 << 8)),
- IOErrorBlocked = (Result.IOError | (11 << 8)),
- IOErrorNoMem = (Result.IOError | (12 << 8)),
- IOErrorAccess = (Result.IOError | (13 << 8)),
- IOErrorCheckReservedLock = (Result.IOError | (14 << 8)),
- IOErrorLock = (Result.IOError | (15 << 8)),
- IOErrorClose = (Result.IOError | (16 << 8)),
- IOErrorDirClose = (Result.IOError | (17 << 8)),
- IOErrorSHMOpen = (Result.IOError | (18 << 8)),
- IOErrorSHMSize = (Result.IOError | (19 << 8)),
- IOErrorSHMLock = (Result.IOError | (20 << 8)),
- IOErrorSHMMap = (Result.IOError | (21 << 8)),
- IOErrorSeek = (Result.IOError | (22 << 8)),
- IOErrorDeleteNoEnt = (Result.IOError | (23 << 8)),
- IOErrorMMap = (Result.IOError | (24 << 8)),
- LockedSharedcache = (Result.Locked | (1 << 8)),
- BusyRecovery = (Result.Busy | (1 << 8)),
- CannottOpenNoTempDir = (Result.CannotOpen | (1 << 8)),
- CannotOpenIsDir = (Result.CannotOpen | (2 << 8)),
- CannotOpenFullPath = (Result.CannotOpen | (3 << 8)),
- CorruptVTab = (Result.Corrupt | (1 << 8)),
- ReadonlyRecovery = (Result.ReadOnly | (1 << 8)),
- ReadonlyCannotLock = (Result.ReadOnly | (2 << 8)),
- ReadonlyRollback = (Result.ReadOnly | (3 << 8)),
- AbortRollback = (Result.Abort | (2 << 8)),
- ConstraintCheck = (Result.Constraint | (1 << 8)),
- ConstraintCommitHook = (Result.Constraint | (2 << 8)),
- ConstraintForeignKey = (Result.Constraint | (3 << 8)),
- ConstraintFunction = (Result.Constraint | (4 << 8)),
- ConstraintNotNull = (Result.Constraint | (5 << 8)),
- ConstraintPrimaryKey = (Result.Constraint | (6 << 8)),
- ConstraintTrigger = (Result.Constraint | (7 << 8)),
- ConstraintUnique = (Result.Constraint | (8 << 8)),
- ConstraintVTab = (Result.Constraint | (9 << 8)),
- NoticeRecoverWAL = (Result.Notice | (1 << 8)),
- NoticeRecoverRollback = (Result.Notice | (2 << 8))
- }
-
-
- public enum ConfigOption : int {
- SingleThread = 1,
- MultiThread = 2,
- Serialized = 3
- }
-
- public enum ColType : int {
- Integer = 1,
- Float = 2,
- Text = 3,
- Blob = 4,
- Null = 5
- }
- }
-
-
- public static partial class SQLite3 {
+ public static partial class SQLite3
+ {
+ public enum ColType
+ {
+ Integer = 1,
+ Float = 2,
+ Text = 3,
+ Blob = 4,
+ Null = 5
+ }
+
+ public enum ConfigOption
+ {
+ SingleThread = 1,
+ MultiThread = 2,
+ Serialized = 3
+ }
+
+ public enum ExtendedResult
+ {
+ IOErrorRead = Result.IOError | (1 << 8),
+ IOErrorShortRead = Result.IOError | (2 << 8),
+ IOErrorWrite = Result.IOError | (3 << 8),
+ IOErrorFsync = Result.IOError | (4 << 8),
+ IOErrorDirFSync = Result.IOError | (5 << 8),
+ IOErrorTruncate = Result.IOError | (6 << 8),
+ IOErrorFStat = Result.IOError | (7 << 8),
+ IOErrorUnlock = Result.IOError | (8 << 8),
+ IOErrorRdlock = Result.IOError | (9 << 8),
+ IOErrorDelete = Result.IOError | (10 << 8),
+ IOErrorBlocked = Result.IOError | (11 << 8),
+ IOErrorNoMem = Result.IOError | (12 << 8),
+ IOErrorAccess = Result.IOError | (13 << 8),
+ IOErrorCheckReservedLock = Result.IOError | (14 << 8),
+ IOErrorLock = Result.IOError | (15 << 8),
+ IOErrorClose = Result.IOError | (16 << 8),
+ IOErrorDirClose = Result.IOError | (17 << 8),
+ IOErrorSHMOpen = Result.IOError | (18 << 8),
+ IOErrorSHMSize = Result.IOError | (19 << 8),
+ IOErrorSHMLock = Result.IOError | (20 << 8),
+ IOErrorSHMMap = Result.IOError | (21 << 8),
+ IOErrorSeek = Result.IOError | (22 << 8),
+ IOErrorDeleteNoEnt = Result.IOError | (23 << 8),
+ IOErrorMMap = Result.IOError | (24 << 8),
+ LockedSharedcache = Result.Locked | (1 << 8),
+ BusyRecovery = Result.Busy | (1 << 8),
+ CannottOpenNoTempDir = Result.CannotOpen | (1 << 8),
+ CannotOpenIsDir = Result.CannotOpen | (2 << 8),
+ CannotOpenFullPath = Result.CannotOpen | (3 << 8),
+ CorruptVTab = Result.Corrupt | (1 << 8),
+ ReadonlyRecovery = Result.ReadOnly | (1 << 8),
+ ReadonlyCannotLock = Result.ReadOnly | (2 << 8),
+ ReadonlyRollback = Result.ReadOnly | (3 << 8),
+ AbortRollback = Result.Abort | (2 << 8),
+ ConstraintCheck = Result.Constraint | (1 << 8),
+ ConstraintCommitHook = Result.Constraint | (2 << 8),
+ ConstraintForeignKey = Result.Constraint | (3 << 8),
+ ConstraintFunction = Result.Constraint | (4 << 8),
+ ConstraintNotNull = Result.Constraint | (5 << 8),
+ ConstraintPrimaryKey = Result.Constraint | (6 << 8),
+ ConstraintTrigger = Result.Constraint | (7 << 8),
+ ConstraintUnique = Result.Constraint | (8 << 8),
+ ConstraintVTab = Result.Constraint | (9 << 8),
+ NoticeRecoverWAL = Result.Notice | (1 << 8),
+ NoticeRecoverRollback = Result.Notice | (2 << 8)
+ }
+
+ public enum Result
+ {
+ OK = 0,
+ Error = 1,
+ Internal = 2,
+ Perm = 3,
+ Abort = 4,
+ Busy = 5,
+ Locked = 6,
+ NoMem = 7,
+ ReadOnly = 8,
+ Interrupt = 9,
+ IOError = 10,
+ Corrupt = 11,
+ NotFound = 12,
+ Full = 13,
+ CannotOpen = 14,
+ LockErr = 15,
+ Empty = 16,
+ SchemaChngd = 17,
+ TooBig = 18,
+ Constraint = 19,
+ Mismatch = 20,
+ Misuse = 21,
+ NotImplementedLFS = 22,
+ AccessDenied = 23,
+ Format = 24,
+ Range = 25,
+ NonDBFile = 26,
+ Notice = 27,
+ Warning = 28,
+ Row = 100,
+ Done = 101
+ }
+ }
+
+ public static partial class SQLite3
+ {
#if UNITY_EDITOR
- const string DLL_NAME = "sqlcipher";
+ private const string DLL_NAME = "sqlcipher";
#elif UNITY_ANDROID
const string DLL_NAME = "sqlcipher";
#elif UNITY_IOS
const string DLL_NAME = "__Internal";
#endif
-#if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_open", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Open ([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db);
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_open_v2", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Open ([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db, int flags, IntPtr zvfs);
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]
- public static extern Result Open(byte[] filename, out IntPtr db, int flags, IntPtr zvfs);
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_key", CallingConvention = CallingConvention.Cdecl)]
- public static extern Result Key(IntPtr db, [MarshalAs(UnmanagedType.LPStr)]string key, int keylen);
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_open16", CallingConvention = CallingConvention.Cdecl)]
- public static extern Result Open16([MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr db);
-
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_enable_load_extension", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result EnableLoadExtension (IntPtr db, int onoff);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_open", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Open([MarshalAs(UnmanagedType.LPStr)] string filename,
+ out Sqlite3DatabaseHandle db);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_close", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Close (IntPtr db);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Open([MarshalAs(UnmanagedType.LPStr)] string filename, out Sqlite3DatabaseHandle db,
+ int flags, Sqlite3DatabaseHandle zvfs);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_initialize", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Initialize();
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_open_v2", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Open(byte[] filename, out Sqlite3DatabaseHandle db, int flags,
+ Sqlite3DatabaseHandle zvfs);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_shutdown", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Shutdown();
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_key", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Key(Sqlite3DatabaseHandle db, [MarshalAs(UnmanagedType.LPStr)] string key,
+ int keylen);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_config", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Config (ConfigOption option);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_open16", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Open16([MarshalAs(UnmanagedType.LPWStr)] string filename,
+ out Sqlite3DatabaseHandle db);
- //[DllImport(DLL_NAME, EntryPoint = "sqlite3_win32_set_directory", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Unicode)]
- //public static extern int SetDirectory (uint directoryType, string directoryPath);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_enable_load_extension", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result EnableLoadExtension(Sqlite3DatabaseHandle db, int onoff);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_busy_timeout", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result BusyTimeout (IntPtr db, int milliseconds);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_close", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Close(Sqlite3DatabaseHandle db);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_changes", CallingConvention=CallingConvention.Cdecl)]
- public static extern int Changes (IntPtr db);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_initialize", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Initialize();
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_prepare_v2", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Prepare2 (IntPtr db, [MarshalAs(UnmanagedType.LPStr)] string sql, int numBytes, out IntPtr stmt, IntPtr pzTail);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_shutdown", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Shutdown();
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_step", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Step (IntPtr stmt);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_config", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Config(ConfigOption option);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_reset", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Reset (IntPtr stmt);
+ //[DllImport(DLL_NAME, EntryPoint = "sqlite3_win32_set_directory", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Unicode)]
+ //public static extern int SetDirectory (uint directoryType, string directoryPath);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_finalize", CallingConvention=CallingConvention.Cdecl)]
- public static extern Result Finalize (IntPtr stmt);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_busy_timeout", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result BusyTimeout(Sqlite3DatabaseHandle db, int milliseconds);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_last_insert_rowid", CallingConvention=CallingConvention.Cdecl)]
- public static extern long LastInsertRowid (IntPtr db);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_changes", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int Changes(Sqlite3DatabaseHandle db);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_errmsg16", CallingConvention=CallingConvention.Cdecl)]
- public static extern IntPtr Errmsg (IntPtr db);
- public static string GetErrmsg (IntPtr db) {
- return Marshal.PtrToStringUni (Errmsg (db));
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_prepare_v2", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Prepare2(Sqlite3DatabaseHandle db, [MarshalAs(UnmanagedType.LPStr)] string sql,
+ int numBytes, out Sqlite3DatabaseHandle stmt, Sqlite3DatabaseHandle pzTail);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_parameter_index", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindParameterIndex (IntPtr stmt, [MarshalAs(UnmanagedType.LPStr)] string name);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_step", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Step(Sqlite3DatabaseHandle stmt);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_null", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindNull (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_reset", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Reset(Sqlite3DatabaseHandle stmt);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_int", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindInt (IntPtr stmt, int index, int val);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_finalize", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Result Finalize(Sqlite3DatabaseHandle stmt);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_int64", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindInt64 (IntPtr stmt, int index, long val);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_last_insert_rowid", CallingConvention = CallingConvention.Cdecl)]
+ public static extern long LastInsertRowid(Sqlite3DatabaseHandle db);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_double", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindDouble (IntPtr stmt, int index, double val);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_errmsg16", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Sqlite3DatabaseHandle Errmsg(Sqlite3DatabaseHandle db);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_text16", CallingConvention=CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
- public static extern int BindText (IntPtr stmt, int index, [MarshalAs(UnmanagedType.LPWStr)] string val, int n, IntPtr free);
+ public static string GetErrmsg(Sqlite3DatabaseHandle db)
+ {
+ return Marshal.PtrToStringUni(Errmsg(db));
+ }
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_blob", CallingConvention=CallingConvention.Cdecl)]
- public static extern int BindBlob (IntPtr stmt, int index, byte[] val, int n, IntPtr free);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_parameter_index", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindParameterIndex(Sqlite3DatabaseHandle stmt,
+ [MarshalAs(UnmanagedType.LPStr)] string name);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_count", CallingConvention=CallingConvention.Cdecl)]
- public static extern int ColumnCount (IntPtr stmt);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_null", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindNull(Sqlite3DatabaseHandle stmt, int index);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_name", CallingConvention=CallingConvention.Cdecl)]
- public static extern IntPtr ColumnName (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_int", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindInt(Sqlite3DatabaseHandle stmt, int index, int val);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_name16", CallingConvention=CallingConvention.Cdecl)]
- static extern IntPtr ColumnName16Internal (IntPtr stmt, int index);
- public static string ColumnName16(IntPtr stmt, int index) {
- return Marshal.PtrToStringUni(ColumnName16Internal(stmt, index));
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_int64", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindInt64(Sqlite3DatabaseHandle stmt, int index, long val);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_type", CallingConvention=CallingConvention.Cdecl)]
- public static extern ColType ColumnType (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_double", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindDouble(Sqlite3DatabaseHandle stmt, int index, double val);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_int", CallingConvention=CallingConvention.Cdecl)]
- public static extern int ColumnInt (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_text16", CallingConvention = CallingConvention.Cdecl,
+ CharSet = CharSet.Unicode)]
+ public static extern int BindText(Sqlite3DatabaseHandle stmt, int index,
+ [MarshalAs(UnmanagedType.LPWStr)] string val, int n, Sqlite3DatabaseHandle free);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_int64", CallingConvention=CallingConvention.Cdecl)]
- public static extern long ColumnInt64 (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_bind_blob", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BindBlob(Sqlite3DatabaseHandle stmt, int index, byte[] val, int n,
+ Sqlite3DatabaseHandle free);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_double", CallingConvention=CallingConvention.Cdecl)]
- public static extern double ColumnDouble (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_count", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int ColumnCount(Sqlite3DatabaseHandle stmt);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_text", CallingConvention=CallingConvention.Cdecl)]
- public static extern IntPtr ColumnText (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_name", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Sqlite3DatabaseHandle ColumnName(Sqlite3DatabaseHandle stmt, int index);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_text16", CallingConvention=CallingConvention.Cdecl)]
- public static extern IntPtr ColumnText16 (IntPtr stmt, int index);
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_name16", CallingConvention = CallingConvention.Cdecl)]
+ private static extern Sqlite3DatabaseHandle ColumnName16Internal(Sqlite3DatabaseHandle stmt, int index);
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_blob", CallingConvention=CallingConvention.Cdecl)]
- public static extern IntPtr ColumnBlob (IntPtr stmt, int index);
+ public static string ColumnName16(Sqlite3DatabaseHandle stmt, int index)
+ {
+ return Marshal.PtrToStringUni(ColumnName16Internal(stmt, index));
+ }
- [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_bytes", CallingConvention=CallingConvention.Cdecl)]
- public static extern int ColumnBytes (IntPtr stmt, int index);
- public static string ColumnString (IntPtr stmt, int index) {
- return Marshal.PtrToStringUni (SQLite3.ColumnText16 (stmt, index));
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_type", CallingConvention = CallingConvention.Cdecl)]
+ public static extern ColType ColumnType(Sqlite3DatabaseHandle stmt, int index);
- public static byte[] ColumnByteArray (IntPtr stmt, int index) {
- int length = ColumnBytes (stmt, index);
- var result = new byte[length];
- if (length > 0)
- Marshal.Copy (ColumnBlob (stmt, index), result, 0, length);
- return result;
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_int", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int ColumnInt(Sqlite3DatabaseHandle stmt, int index);
- [DllImport (DLL_NAME, EntryPoint = "sqlite3_extended_errcode", CallingConvention = CallingConvention.Cdecl)]
- public static extern ExtendedResult ExtendedErrCode (IntPtr db);
-
- [DllImport (DLL_NAME, EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)]
- public static extern int LibVersionNumber ();
-
-
- #if NETFX_CORE
- [DllImport (DLL_NAME, EntryPoint = "sqlite3_prepare_v2", CallingConvention = CallingConvention.Cdecl)]
- static extern Result Prepare2 (IntPtr db, byte[] queryBytes, int numBytes, out IntPtr stmt, IntPtr pzTail);
- #endif
-
- public static IntPtr Prepare2 (IntPtr db, string query) {
- IntPtr stmt;
- #if NETFX_CORE
- byte[] queryBytes = System.Text.UTF8Encoding.UTF8.GetBytes (query);
- var r = Prepare2 (db, queryBytes, queryBytes.Length, out stmt, IntPtr.Zero);
- #else
- var r = Prepare2 (db, query, System.Text.UTF8Encoding.UTF8.GetByteCount (query), out stmt, IntPtr.Zero);
- #endif
- if (r != Result.OK) {
- throw SQLiteException.New (r, GetErrmsg (db));
- }
- return stmt;
- }
-
-
-#endif
-
-
- }
-
-
- public static partial class SQLite3
- {
-#if USE_CSHARP_SQLITE
- public static Result Open(string filename, out Sqlite3DatabaseHandle db, int flags, IntPtr zVfs) {
- return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, null);
- }
-
- public static int BindText(Sqlite3Statement stmt, int index, string val, int n, IntPtr free) {
- return Sqlite3.sqlite3_bind_text(stmt, index, val, n, null);
- }
-
- public static int BindBlob(Sqlite3Statement stmt, int index, byte[] val, int n, IntPtr free) {
- return Sqlite3.sqlite3_bind_blob(stmt, index, val, n, null);
- }
-
- public static Sqlite3Statement Prepare2(Sqlite3DatabaseHandle db, string query) {
- Sqlite3Statement stmt = new Sqlite3Statement();
- var r = Sqlite3.sqlite3_prepare_v2(db, query, -1, ref stmt, 0);
- if (r != 0) {
- throw SQLiteException.New((Result)r, GetErrmsg(db));
- }
- return stmt;
- }
-#elif USE_WP8_NATIVE_SQLITE
- public static Result Open(string filename, out Sqlite3DatabaseHandle db, int flags, IntPtr zVfs) {
- return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, "");
- }
-
- public static int BindText(Sqlite3Statement stmt, int index, string val, int n, IntPtr free) {
- return Sqlite3.sqlite3_bind_text(stmt, index, val, n);
- }
-
- public static int BindBlob(Sqlite3Statement stmt, int index, byte[] val, int n, IntPtr free) {
- return Sqlite3.sqlite3_bind_blob(stmt, index, val, n, null);
- }
-
- public static Sqlite3Statement Prepare2(Sqlite3DatabaseHandle db, string query) {
- Sqlite3Statement stmt = default(Sqlite3Statement);
- var r = Sqlite3.sqlite3_prepare_v2(db, query, out stmt);
-
- if (r != 0) {
- throw SQLiteException.New((Result)r, GetErrmsg(db));
- }
- return stmt;
- }
-#endif
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_int64", CallingConvention = CallingConvention.Cdecl)]
+ public static extern long ColumnInt64(Sqlite3DatabaseHandle stmt, int index);
-#if USE_CSHARP_SQLITE || USE_WP8_NATIVE_SQLITE
- public static Result Open(string filename, out Sqlite3DatabaseHandle db) {
- return (Result) Sqlite3.sqlite3_open(filename, out db);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_double", CallingConvention = CallingConvention.Cdecl)]
+ public static extern double ColumnDouble(Sqlite3DatabaseHandle stmt, int index);
- public static Result Close(Sqlite3DatabaseHandle db) {
- return (Result)Sqlite3.sqlite3_close(db);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_text", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Sqlite3DatabaseHandle ColumnText(Sqlite3DatabaseHandle stmt, int index);
- public static Result BusyTimeout(Sqlite3DatabaseHandle db, int milliseconds) {
- return (Result)Sqlite3.sqlite3_busy_timeout(db, milliseconds);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_text16", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Sqlite3DatabaseHandle ColumnText16(Sqlite3DatabaseHandle stmt, int index);
- public static int Changes(Sqlite3DatabaseHandle db) {
- return Sqlite3.sqlite3_changes(db);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_blob", CallingConvention = CallingConvention.Cdecl)]
+ public static extern Sqlite3DatabaseHandle ColumnBlob(Sqlite3DatabaseHandle stmt, int index);
- public static Result Step(Sqlite3Statement stmt) {
- return (Result)Sqlite3.sqlite3_step(stmt);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_column_bytes", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int ColumnBytes(Sqlite3DatabaseHandle stmt, int index);
- public static Result Reset(Sqlite3Statement stmt) {
- return (Result)Sqlite3.sqlite3_reset(stmt);
- }
+ public static string ColumnString(Sqlite3DatabaseHandle stmt, int index)
+ {
+ return Marshal.PtrToStringUni(ColumnText16(stmt, index));
+ }
- public static Result Finalize(Sqlite3Statement stmt) {
- return (Result)Sqlite3.sqlite3_finalize(stmt);
- }
+ public static byte[] ColumnByteArray(Sqlite3DatabaseHandle stmt, int index)
+ {
+ int length = ColumnBytes(stmt, index);
+ byte[] result = new byte[length];
+ if (length > 0)
+ Marshal.Copy(ColumnBlob(stmt, index), result, 0, length);
+ return result;
+ }
- public static long LastInsertRowid(Sqlite3DatabaseHandle db) {
- return Sqlite3.sqlite3_last_insert_rowid(db);
- }
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_extended_errcode", CallingConvention = CallingConvention.Cdecl)]
+ public static extern ExtendedResult ExtendedErrCode(Sqlite3DatabaseHandle db);
- public static string GetErrmsg(Sqlite3DatabaseHandle db) {
- return Sqlite3.sqlite3_errmsg(db);
- }
-
- public static int BindParameterIndex(Sqlite3Statement stmt, string name) {
- return Sqlite3.sqlite3_bind_parameter_index(stmt, name);
- }
-
- public static int BindNull(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_bind_null(stmt, index);
- }
-
- public static int BindInt(Sqlite3Statement stmt, int index, int val) {
- return Sqlite3.sqlite3_bind_int(stmt, index, val);
- }
-
- public static int BindInt64(Sqlite3Statement stmt, int index, long val) {
- return Sqlite3.sqlite3_bind_int64(stmt, index, val);
- }
-
- public static int BindDouble(Sqlite3Statement stmt, int index, double val) {
- return Sqlite3.sqlite3_bind_double(stmt, index, val);
- }
-
- public static int ColumnCount(Sqlite3Statement stmt) {
- return Sqlite3.sqlite3_column_count(stmt);
- }
-
- public static string ColumnName(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_name(stmt, index);
- }
-
- public static string ColumnName16(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_name(stmt, index);
- }
-
- public static ColType ColumnType(Sqlite3Statement stmt, int index) {
- return (ColType)Sqlite3.sqlite3_column_type(stmt, index);
- }
-
- public static int ColumnInt(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_int(stmt, index);
- }
-
- public static long ColumnInt64(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_int64(stmt, index);
- }
-
- public static double ColumnDouble(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_double(stmt, index);
- }
-
- public static string ColumnText(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_text(stmt, index);
- }
-
- public static string ColumnText16(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_text(stmt, index);
- }
-
- public static byte[] ColumnBlob(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_blob(stmt, index);
- }
-
- public static int ColumnBytes(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_bytes(stmt, index);
- }
-
- public static string ColumnString(Sqlite3Statement stmt, int index) {
- return Sqlite3.sqlite3_column_text(stmt, index);
- }
-
- public static byte[] ColumnByteArray(Sqlite3Statement stmt, int index) {
- return ColumnBlob(stmt, index);
- }
-
- public static Result EnableLoadExtension(Sqlite3DatabaseHandle db, int onoff) {
- return (Result)Sqlite3.sqlite3_enable_load_extension(db, onoff);
- }
-
- public static ExtendedResult ExtendedErrCode(Sqlite3DatabaseHandle db) {
- return (ExtendedResult)Sqlite3.sqlite3_extended_errcode(db);
- }
-#endif
- }
-}
+ [DllImport(DLL_NAME, EntryPoint = "sqlite3_libversion_number", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int LibVersionNumber();
+ public static Sqlite3DatabaseHandle Prepare2(Sqlite3DatabaseHandle db, string query)
+ {
+ Sqlite3DatabaseHandle stmt;
+ Result r = Prepare2(db, query, Encoding.UTF8.GetByteCount(query), out stmt, Sqlite3DatabaseHandle.Zero);
+ if (r != Result.OK) throw SQLiteException.New(r, GetErrmsg(db));
+ return stmt;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3Connection.cs b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3Connection.cs
index 7637a87..9e96e8e 100644
--- a/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3Connection.cs
+++ b/SqlCipher4Unity3D/Assets/SqlCipher4Unity3D/Sqlite3Connection.cs
@@ -1,2616 +1,2568 @@
-using System.Collections;
-using System;
+using System;
+using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
-using System.Linq;
-using System.Diagnostics;
+using System.Text;
using System.Threading;
-
-
-#if USE_CSHARP_SQLITE
-using Sqlite3 = Community.CsharpSqlite.Sqlite3;
-using Sqlite3DatabaseHandle = Community.CsharpSqlite.Sqlite3.sqlite3;
-using Sqlite3Statement = Community.CsharpSqlite.Sqlite3.Vdbe;
-#elif USE_WP8_NATIVE_SQLITE
-using Sqlite3 = Sqlite.Sqlite3;
-using Sqlite3DatabaseHandle = Sqlite.Database;
-using Sqlite3Statement = Sqlite.Statement;
-#else
+using SQLite.Attribute;
using Sqlite3DatabaseHandle = System.IntPtr;
using Sqlite3Statement = System.IntPtr;
-#endif
namespace SqlCipher4Unity3D
{
- using SQLite.Attribute;
- ///
- /// Represents an open connection to a SQLite database.
- ///
- public partial class SQLiteConnection : IDisposable {
- private bool _open;
- private TimeSpan _busyTimeout;
- private Dictionary _mappings = null;
- private Dictionary _tables = null;
- private System.Diagnostics.Stopwatch _sw;
- private long _elapsedMilliseconds = 0;
-
- private int _transactionDepth = 0;
- private System.Random _rand = new System.Random ();
-
- public Sqlite3DatabaseHandle Handle { get; private set; }
- internal static readonly Sqlite3DatabaseHandle NullHandle = default(Sqlite3DatabaseHandle);
-
- public string DatabasePath { get; private set; }
-
- public bool TimeExecution { get; set; }
-
- public bool Trace { get; set; }
-
- public bool StoreDateTimeAsTicks { get; private set; }
-
- ///
- /// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
- ///
- ///
- /// Specifies the path to the database file.
- ///
- ///
- /// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
- /// absolutely do want to store them as Ticks in all new projects. The default of false is
- /// only here for backwards compatibility. There is a *significant* speed advantage, with no
- /// down sides, when setting storeDateTimeAsTicks = true.
- ///
- public SQLiteConnection (string databasePath, string password = null, bool storeDateTimeAsTicks = false)
- : this (databasePath, password, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, storeDateTimeAsTicks)
- {
- }
-
- ///
- /// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
- ///
- ///
- /// Specifies the path to the database file.
- ///
- ///
- /// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
- /// absolutely do want to store them as Ticks in all new projects. The default of false is
- /// only here for backwards compatibility. There is a *significant* speed advantage, with no
- /// down sides, when setting storeDateTimeAsTicks = true.
- ///
- public SQLiteConnection (string databasePath, string password, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = false) {
- if (string.IsNullOrEmpty (databasePath))
- throw new ArgumentException ("Must be specified", "databasePath");
-
- DatabasePath = databasePath;
-
- #if NETFX_CORE
- SQLite3.SetDirectory(/*temp directory type*/2, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
- #endif
-
- Sqlite3DatabaseHandle handle;
-
- #if SILVERLIGHT || USE_CSHARP_SQLITE
- var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);
- #else
- // open using the byte[]
- // in the case where the path may include Unicode
- // force open to using UTF-8 using sqlite3_open_v2
- var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
- var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
- #endif
-
- Handle = handle;
- if (r != SQLite3.Result.OK) {
- throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
- }
-
- if (!string.IsNullOrEmpty(password)) {
- var result = SQLite3.Key(handle, password, password.Length);
- if (result != SQLite3.Result.OK) {
- throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
- }
- }
-
- _open = true;
-
- StoreDateTimeAsTicks = storeDateTimeAsTicks;
-
- BusyTimeout = TimeSpan.FromSeconds (0.1);
- }
-
- static SQLiteConnection () {
- if (_preserveDuringLinkMagic) {
- var ti = new ColumnInfo ();
- ti.Name = "magic";
- }
- }
-
- public void EnableLoadExtension(int onoff) {
- SQLite3.Result r = SQLite3.EnableLoadExtension(Handle, onoff);
- if (r != SQLite3.Result.OK) {
- string msg = SQLite3.GetErrmsg (Handle);
- throw SQLiteException.New (r, msg);
- }
- }
-
- static byte[] GetNullTerminatedUtf8 (string s) {
- var utf8Length = System.Text.Encoding.UTF8.GetByteCount (s);
- var bytes = new byte [utf8Length + 1];
- utf8Length = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0);
- return bytes;
- }
-
- ///
- /// Used to list some code that we want the MonoTouch linker
- /// to see, but that we never want to actually execute.
- ///
- static bool _preserveDuringLinkMagic;
-
- ///
- /// Sets a busy handler to sleep the specified amount of time when a table is locked.
- /// The handler will sleep multiple times until a total time of has accumulated.
- ///
- public TimeSpan BusyTimeout {
- get { return _busyTimeout; }
- set {
- _busyTimeout = value;
- if (Handle != NullHandle) {
- SQLite3.BusyTimeout (Handle, (int)_busyTimeout.TotalMilliseconds);
- }
- }
- }
-
- ///
- /// Returns the mappings from types to tables that the connection
- /// currently understands.
- ///
- public IEnumerable TableMappings {
- get {
- return _tables != null ? _tables.Values : Enumerable.Empty ();
- }
- }
-
- ///
- /// Retrieves the mapping that is automatically generated for the given type.
- ///
- ///
- /// The type whose mapping to the database is returned.
- ///
- ///
- /// Optional flags allowing implicit PK and indexes based on naming conventions
- ///
- ///
- /// The mapping represents the schema of the columns of the database and contains
- /// methods to set and get properties of objects.
- ///
- public TableMapping GetMapping(Type type, CreateFlags createFlags = CreateFlags.None)
- {
- if (_mappings == null) {
- _mappings = new Dictionary ();
- }
- TableMapping map;
- if (!_mappings.TryGetValue (type.FullName, out map)) {
- map = new TableMapping (type, createFlags);
- _mappings [type.FullName] = map;
- }
- return map;
- }
-
- ///
- /// Retrieves the mapping that is automatically generated for the given type.
- ///
- ///
- /// The mapping represents the schema of the columns of the database and contains
- /// methods to set and get properties of objects.
- ///
- public TableMapping GetMapping ()
- {
- return GetMapping (typeof (T));
- }
-
- private struct IndexedColumn
- {
- public int Order;
- public string ColumnName;
- }
-
- private struct IndexInfo
- {
- public string IndexName;
- public string TableName;
- public bool Unique;
- public List Columns;
- }
-
- ///
- /// Executes a "drop table" on the database. This is non-recoverable.
- ///
- public int DropTable()
- {
- var map = GetMapping (typeof (T));
-
- var query = string.Format("drop table if exists \"{0}\"", map.TableName);
-
- return Execute (query);
- }
-
- public int DropTable(Type t)
- {
- var map = GetMapping(t);
-
- var query = string.Format("drop table if exists \"{0}\"", map.TableName);
-
- return Execute(query);
- }
-
- ///
- /// Executes a "create table if not exists" on the database. It also
- /// creates any specified indexes on the columns of the table. It uses
- /// a schema automatically generated from the specified type. You can
- /// later access this schema by calling GetMapping.
- ///
- ///
- /// The number of entries added to the database schema.
- ///
- public int CreateTable(CreateFlags createFlags = CreateFlags.None)
- {
- return CreateTable(typeof (T), createFlags);
- }
-
- ///
- /// Executes a "create table if not exists" on the database. It also
- /// creates any specified indexes on the columns of the table. It uses
- /// a schema automatically generated from the specified type. You can
- /// later access this schema by calling GetMapping.
- ///
- /// Type to reflect to a database table.
- /// Optional flags allowing implicit PK and indexes based on naming conventions.
- ///
- /// The number of entries added to the database schema.
- ///
- public int CreateTable(Type ty, CreateFlags createFlags = CreateFlags.None)
- {
- if (_tables == null) {
- _tables = new Dictionary ();
- }
- TableMapping map;
- if (!_tables.TryGetValue (ty.FullName, out map)) {
- map = GetMapping (ty, createFlags);
- _tables.Add (ty.FullName, map);
- }
- var query = "create table if not exists \"" + map.TableName + "\"(\n";
-
- var decls = map.Columns.Select (p => Orm.SqlDecl (p, StoreDateTimeAsTicks));
- var decl = string.Join (",\n", decls.ToArray ());
- query += decl;
- query += ")";
-
- var count = Execute (query);
-
- if (count == 0) { //Possible bug: This always seems to return 0?
- // Table already exists, migrate it
- MigrateTable (map);
- }
-
- var indexes = new Dictionary ();
- foreach (var c in map.Columns) {
- foreach (var i in c.Indices) {
- var iname = i.Name ?? map.TableName + "_" + c.Name;
- IndexInfo iinfo;
- if (!indexes.TryGetValue (iname, out iinfo)) {
- iinfo = new IndexInfo {
- IndexName = iname,
- TableName = map.TableName,
- Unique = i.Unique,
- Columns = new List ()
- };
- indexes.Add (iname, iinfo);
- }
-
- if (i.Unique != iinfo.Unique)
- throw new Exception ("All the columns in an index must have the same value for their Unique property");
-
- iinfo.Columns.Add (new IndexedColumn {
- Order = i.Order,
- ColumnName = c.Name
- });
- }
- }
-
- foreach (var indexName in indexes.Keys) {
- var index = indexes[indexName];
- var columns = index.Columns.OrderBy(i => i.Order).Select(i => i.ColumnName).ToArray();
- count += CreateIndex(indexName, index.TableName, columns, index.Unique);
- }
-
- return count;
- }
-
- ///
- /// Creates an index for the specified table and columns.
- ///
- /// Name of the index to create
- /// Name of the database table
- /// An array of column names to index
- /// Whether the index should be unique
- public int CreateIndex(string indexName, string tableName, string[] columnNames, bool unique = false)
- {
- const string sqlFormat = "create {2} index if not exists \"{3}\" on \"{0}\"(\"{1}\")";
- var sql = String.Format(sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : "", indexName);
- return Execute(sql);
- }
-
- ///
- /// Creates an index for the specified table and column.
- ///
- /// Name of the index to create
- /// Name of the database table
- /// Name of the column to index
- /// Whether the index should be unique
- public int CreateIndex(string indexName, string tableName, string columnName, bool unique = false)
- {
- return CreateIndex(indexName, tableName, new string[] { columnName }, unique);
- }
-
- ///
- /// Creates an index for the specified table and column.
- ///
- /// Name of the database table
- /// Name of the column to index
- /// Whether the index should be unique
- public int CreateIndex(string tableName, string columnName, bool unique = false)
- {
- return CreateIndex(tableName + "_" + columnName, tableName, columnName, unique);
- }
-
- ///
- /// Creates an index for the specified table and columns.
- ///
- /// Name of the database table
- /// An array of column names to index
- /// Whether the index should be unique
- public int CreateIndex(string tableName, string[] columnNames, bool unique = false)
- {
- return CreateIndex(tableName + "_" + string.Join ("_", columnNames), tableName, columnNames, unique);
- }
-
- ///
- /// Creates an index for the specified object property.
- /// e.g. CreateIndex(c => c.Name);
- ///
- /// Type to reflect to a database table.
- /// Property to index
- /// Whether the index should be unique
- public void CreateIndex(Expression> property, bool unique = false)
- {
- MemberExpression mx;
- if (property.Body.NodeType == ExpressionType.Convert)
- {
- mx = ((UnaryExpression)property.Body).Operand as MemberExpression;
- }
- else
- {
- mx= (property.Body as MemberExpression);
- }
- var propertyInfo = mx.Member as PropertyInfo;
- if (propertyInfo == null)
- {
- throw new ArgumentException("The lambda expression 'property' should point to a valid Property");
- }
-
- var propName = propertyInfo.Name;
-
- var map = GetMapping();
- var colName = map.FindColumnWithPropertyName(propName).Name;
-
- CreateIndex(map.TableName, colName, unique);
- }
-
- public class ColumnInfo
- {
- // public int cid { get; set; }
-
- [Column ("name")]
- public string Name { get; set; }
-
- // [Column ("type")]
- // public string ColumnType { get; set; }
-
- public int notnull { get; set; }
-
- // public string dflt_value { get; set; }
-
- // public int pk { get; set; }
-
- public override string ToString ()
- {
- return Name;
- }
- }
-
- public List GetTableInfo (string tableName)
- {
- var query = "pragma table_info(\"" + tableName + "\")";
- return Query (query);
- }
-
- void MigrateTable (TableMapping map)
- {
- var existingCols = GetTableInfo (map.TableName);
-
- var toBeAdded = new List ();
-
- foreach (var p in map.Columns) {
- var found = false;
- foreach (var c in existingCols) {
- found = (string.Compare (p.Name, c.Name, StringComparison.OrdinalIgnoreCase) == 0);
- if (found)
- break;
- }
- if (!found) {
- toBeAdded.Add (p);
- }
- }
-
- foreach (var p in toBeAdded) {
- var addCol = "alter table \"" + map.TableName + "\" add column " + Orm.SqlDecl (p, StoreDateTimeAsTicks);
- Execute (addCol);
- }
- }
-
- ///
- /// Creates a new SQLiteCommand. Can be overridden to provide a sub-class.
- ///
- ///
- protected virtual SQLiteCommand NewCommand ()
- {
- return new SQLiteCommand (this);
- }
-
- ///
- /// Creates a new SQLiteCommand given the command text with arguments. Place a '?'
- /// in the command text for each of the arguments.
- ///
- ///
- /// The fully escaped SQL.
- ///
- ///
- /// Arguments to substitute for the occurences of '?' in the command text.
- ///
- ///
- /// A
- ///
- public SQLiteCommand CreateCommand (string cmdText, params object[] ps)
- {
- if (!_open)
- throw SQLiteException.New (SQLite3.Result.Error, "Cannot create commands from unopened database");
-
- var cmd = NewCommand ();
- cmd.CommandText = cmdText;
- foreach (var o in ps) {
- cmd.Bind (o);
- }
- return cmd;
- }
-
- ///
- /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
- /// in the command text for each of the arguments and then executes that command.
- /// Use this method instead of Query when you don't expect rows back. Such cases include
- /// INSERTs, UPDATEs, and DELETEs.
- /// You can set the Trace or TimeExecution properties of the connection
- /// to profile execution.
- ///
- ///
- /// The fully escaped SQL.
- ///
- ///
- /// Arguments to substitute for the occurences of '?' in the query.
- ///
- ///
- /// The number of rows modified in the database as a result of this execution.
- ///
- public int Execute (string query, params object[] args)
- {
- var cmd = CreateCommand (query, args);
-
- if (TimeExecution) {
- if (_sw == null) {
- _sw = new Stopwatch ();
- }
- _sw.Reset ();
- _sw.Start ();
- }
-
- var r = cmd.ExecuteNonQuery ();
-
- if (TimeExecution) {
- _sw.Stop ();
- _elapsedMilliseconds += _sw.ElapsedMilliseconds;
- System.Diagnostics.Debug.WriteLine (string.Format ("Finished in {0} ms ({1:0.0} s total)", _sw.ElapsedMilliseconds, _elapsedMilliseconds / 1000.0));
- }
-
- return r;
- }
-
- public T ExecuteScalar (string query, params object[] args)
- {
- var cmd = CreateCommand (query, args);
-
- if (TimeExecution) {
- if (_sw == null) {
- _sw = new Stopwatch ();
- }
- _sw.Reset ();
- _sw.Start ();
- }
-
- var r = cmd.ExecuteScalar ();
-
- if (TimeExecution) {
- _sw.Stop ();
- _elapsedMilliseconds += _sw.ElapsedMilliseconds;
- System.Diagnostics.Debug.WriteLine (string.Format ("Finished in {0} ms ({1:0.0} s total)", _sw.ElapsedMilliseconds, _elapsedMilliseconds / 1000.0));
- }
-
- return r;
- }
-
- ///
- /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
- /// in the command text for each of the arguments and then executes that command.
- /// It returns each row of the result using the mapping automatically generated for
- /// the given type.
- ///
- ///
- /// The fully escaped SQL.
- ///
- ///
- /// Arguments to substitute for the occurences of '?' in the query.
- ///
- ///
- /// An enumerable with one result for each row returned by the query.
- ///
- public List Query (string query, params object[] args) where T : new()
- {
- var cmd = CreateCommand (query, args);
- return cmd.ExecuteQuery ();
- }
-
- ///
- /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
- /// in the command text for each of the arguments and then executes that command.
- /// It returns each row of the result using the mapping automatically generated for
- /// the given type.
- ///
- ///
- /// The fully escaped SQL.
- ///
- ///
- /// Arguments to substitute for the occurences of '?' in the query.
- ///
- ///
- /// An enumerable with one result for each row returned by the query.
- /// The enumerator will call sqlite3_step on each call to MoveNext, so the database
- /// connection must remain open for the lifetime of the enumerator.
- ///
- public IEnumerable DeferredQuery(string query, params object[] args) where T : new()
- {
- var cmd = CreateCommand(query, args);
- return cmd.ExecuteDeferredQuery();
- }
-
- ///
- /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
- /// in the command text for each of the arguments and then executes that command.
- /// It returns each row of the result using the specified mapping. This function is
- /// only used by libraries in order to query the database via introspection. It is
- /// normally not used.
- ///
- ///
- /// A to use to convert the resulting rows
- /// into objects.
- ///
- ///
- /// The fully escaped SQL.
- ///
- ///
- /// Arguments to substitute for the occurences of '?' in the query.
- ///
- ///
- /// An enumerable with one result for each row returned by the query.
- ///
- public List