123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- //
- // Copyright (c) 2009-2024 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
- #if !USE_SQLITEPCL_RAW
- using System.Runtime.InteropServices;
- #endif
- #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;
- #elif USE_SQLITEPCL_RAW
- using Sqlite3DatabaseHandle = SQLitePCL.sqlite3;
- using Sqlite3BackupHandle = SQLitePCL.sqlite3_backup;
- using Sqlite3Statement = SQLitePCL.sqlite3_stmt;
- using Sqlite3 = SQLitePCL.raw;
- #else
- using Sqlite3DatabaseHandle = System.IntPtr;
- using Sqlite3BackupHandle = System.IntPtr;
- #endif
- #pragma warning disable 1591 // XML Doc Comments
- namespace SQLite
- {
- public static class SQLite3
- {
- static SQLite3()
- {
- if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
- {
- nativeLoader = new NativeLibraryLoader.NativeLoader("libsqlite3.so.0");
- nativeLoader.SearchDirectories.Add("/usr/lib/");
- }
- else
- {
- nativeLoader = new NativeLibraryLoader.NativeLoader("e_sqlite3.dll");
- nativeLoader.SearchDirectories.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"runtimes"));
- }
- nativeLoader.Init();
- }
- private static NativeLibraryLoader.NativeLoader nativeLoader;
- 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
- }
- //const string LibraryPath = "libsqlite3.so.0";
- const string LibraryPath = "e_sqlite3.dll";
- #if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE && !USE_SQLITEPCL_RAW
- public static int Threadsafe() => nativeLoader.LoadFunction<ThreadsafeDelegate>("sqlite3_threadsafe").Invoke();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int ThreadsafeDelegate();
- public static Result Open(string filename, out IntPtr db) => nativeLoader.LoadFunction<OpenDelegate>("sqlite3_open").Invoke(filename, out db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result OpenDelegate([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db);
- public static Result Open(string filename, out IntPtr db, int flags, string zvfs) => nativeLoader.LoadFunction<OpenV2Delegate>("sqlite3_open_v2").Invoke(filename, out db, flags, zvfs);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result OpenV2Delegate([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db, int flags, [MarshalAs(UnmanagedType.LPStr)] string zvfs);
- public static Result Open(byte[] filename, out IntPtr db, int flags, string zvfs) => nativeLoader.LoadFunction<OpenV2BytesDelegate>("sqlite3_open_v2").Invoke(filename, out db, flags, zvfs);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result OpenV2BytesDelegate(byte[] filename, out IntPtr db, int flags, [MarshalAs(UnmanagedType.LPStr)] string zvfs);
- public static Result Open16(string filename, out IntPtr db) => nativeLoader.LoadFunction<Open16Delegate>("sqlite3_open16").Invoke(filename, out db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
- delegate Result Open16Delegate([MarshalAs(UnmanagedType.LPWStr)] string filename, out IntPtr db);
- public static Result EnableLoadExtension(IntPtr db, int onoff) => nativeLoader.LoadFunction<EnableLoadExtensionDelegate>("sqlite3_enable_load_extension").Invoke(db, onoff);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result EnableLoadExtensionDelegate(IntPtr db, int onoff);
- public static Result Close(IntPtr db) => nativeLoader.LoadFunction<CloseDelegate>("sqlite3_close").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result CloseDelegate(IntPtr db);
- public static Result Close2(IntPtr db) => nativeLoader.LoadFunction<Close2Delegate>("sqlite3_close_v2").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result Close2Delegate(IntPtr db);
- public static Result Initialize() => nativeLoader.LoadFunction<InitializeDelegate>("sqlite3_initialize").Invoke();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result InitializeDelegate();
- public static Result Shutdown() => nativeLoader.LoadFunction<ShutdownDelegate>("sqlite3_shutdown").Invoke();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result ShutdownDelegate();
- public static Result Config(ConfigOption option) => nativeLoader.LoadFunction<ConfigDelegate>("sqlite3_config").Invoke(option);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result ConfigDelegate(ConfigOption option);
- public static int SetDirectory(uint directoryType, string directoryPath) => nativeLoader.LoadFunction<SetDirectoryDelegate>("sqlite3_win32_set_directory").Invoke(directoryType, directoryPath);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
- delegate int SetDirectoryDelegate(uint directoryType, string directoryPath);
- public static Result BusyTimeout(IntPtr db, int milliseconds) => nativeLoader.LoadFunction<BusyTimeoutDelegate>("sqlite3_busy_timeout").Invoke(db, milliseconds);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result BusyTimeoutDelegate(IntPtr db, int milliseconds);
- public static int Changes(IntPtr db) => nativeLoader.LoadFunction<ChangesDelegate>("sqlite3_changes").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int ChangesDelegate(IntPtr db);
- public static Result Prepare2(IntPtr db, string sql, int numBytes, out IntPtr stmt, IntPtr pzTail) => nativeLoader.LoadFunction<Prepare2Delegate>("sqlite3_prepare_v2").Invoke(db, sql, numBytes, out stmt, pzTail);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result Prepare2Delegate(IntPtr db, [MarshalAs(UnmanagedType.LPStr)] string sql, int numBytes, out IntPtr stmt, IntPtr pzTail);
- #if NETFX_CORE
- public static Result Prepare2(IntPtr db, byte[] queryBytes, int numBytes, out IntPtr stmt, IntPtr pzTail) => nativeLoader.LoadFunction<Prepare2BytesDelegate>("sqlite3_prepare_v2").Invoke(db, queryBytes, numBytes, out stmt, pzTail);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result Prepare2BytesDelegate(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;
- }
- public static Result Step(IntPtr stmt) => nativeLoader.LoadFunction<StepDelegate>("sqlite3_step").Invoke(stmt);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result StepDelegate(IntPtr stmt);
- public static Result Reset(IntPtr stmt) => nativeLoader.LoadFunction<ResetDelegate>("sqlite3_reset").Invoke(stmt);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result ResetDelegate(IntPtr stmt);
- public static Result Finalize(IntPtr stmt) => nativeLoader.LoadFunction<FinalizeDelegate>("sqlite3_finalize").Invoke(stmt);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result FinalizeDelegate(IntPtr stmt);
- public static long LastInsertRowid(IntPtr db) => nativeLoader.LoadFunction<LastInsertRowidDelegate>("sqlite3_last_insert_rowid").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate long LastInsertRowidDelegate(IntPtr db);
- public static IntPtr Errmsg(IntPtr db) => nativeLoader.LoadFunction<ErrmsgDelegate>("sqlite3_errmsg16").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ErrmsgDelegate(IntPtr db);
- public static string GetErrmsg(IntPtr db)
- {
- return Marshal.PtrToStringUni(Errmsg(db));
- }
- public static int BindParameterIndex(IntPtr stmt, string name) => nativeLoader.LoadFunction<BindParameterIndexDelegate>("sqlite3_bind_parameter_index").Invoke(stmt, name);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindParameterIndexDelegate(IntPtr stmt, [MarshalAs(UnmanagedType.LPStr)] string name);
- public static int BindNull(IntPtr stmt, int index) => nativeLoader.LoadFunction<BindNullDelegate>("sqlite3_bind_null").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindNullDelegate(IntPtr stmt, int index);
- public static int BindInt(IntPtr stmt, int index, int val) => nativeLoader.LoadFunction<BindIntDelegate>("sqlite3_bind_int").Invoke(stmt, index, val);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindIntDelegate(IntPtr stmt, int index, int val);
- public static int BindInt64(IntPtr stmt, int index, long val) => nativeLoader.LoadFunction<BindInt64Delegate>("sqlite3_bind_int64").Invoke(stmt, index, val);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindInt64Delegate(IntPtr stmt, int index, long val);
- public static int BindDouble(IntPtr stmt, int index, double val) => nativeLoader.LoadFunction<BindDoubleDelegate>("sqlite3_bind_double").Invoke(stmt, index, val);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindDoubleDelegate(IntPtr stmt, int index, double val);
- public static int BindText(IntPtr stmt, int index, string val, int n, IntPtr free) => nativeLoader.LoadFunction<BindTextDelegate>("sqlite3_bind_text16").Invoke(stmt, index, val, n, free);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
- delegate int BindTextDelegate(IntPtr stmt, int index, [MarshalAs(UnmanagedType.LPWStr)] string val, int n, IntPtr free);
- public static int BindBlob(IntPtr stmt, int index, byte[] val, int n, IntPtr free) => nativeLoader.LoadFunction<BindBlobDelegate>("sqlite3_bind_blob").Invoke(stmt, index, val, n, free);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int BindBlobDelegate(IntPtr stmt, int index, byte[] val, int n, IntPtr free);
- public static int ColumnCount(IntPtr stmt) => nativeLoader.LoadFunction<ColumnCountDelegate>("sqlite3_column_count").Invoke(stmt);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int ColumnCountDelegate(IntPtr stmt);
- public static IntPtr ColumnName(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnNameDelegate>("sqlite3_column_name").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ColumnNameDelegate(IntPtr stmt, int index);
- static IntPtr ColumnName16Internal(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnName16Delegate>("sqlite3_column_name16").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ColumnName16Delegate(IntPtr stmt, int index);
- public static string ColumnName16(IntPtr stmt, int index)
- {
- return Marshal.PtrToStringUni(ColumnName16Internal(stmt, index));
- }
- public static ColType ColumnType(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnTypeDelegate>("sqlite3_column_type").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate ColType ColumnTypeDelegate(IntPtr stmt, int index);
- public static int ColumnInt(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnIntDelegate>("sqlite3_column_int").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int ColumnIntDelegate(IntPtr stmt, int index);
- public static long ColumnInt64(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnInt64Delegate>("sqlite3_column_int64").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate long ColumnInt64Delegate(IntPtr stmt, int index);
- public static double ColumnDouble(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnDoubleDelegate>("sqlite3_column_double").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate double ColumnDoubleDelegate(IntPtr stmt, int index);
- public static IntPtr ColumnText(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnTextDelegate>("sqlite3_column_text").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ColumnTextDelegate(IntPtr stmt, int index);
- public static IntPtr ColumnText16(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnText16Delegate>("sqlite3_column_text16").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ColumnText16Delegate(IntPtr stmt, int index);
- public static IntPtr ColumnBlob(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnBlobDelegate>("sqlite3_column_blob").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate IntPtr ColumnBlobDelegate(IntPtr stmt, int index);
- public static int ColumnBytes(IntPtr stmt, int index) => nativeLoader.LoadFunction<ColumnBytesDelegate>("sqlite3_column_bytes").Invoke(stmt, index);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int ColumnBytesDelegate(IntPtr stmt, int index);
- public static string ColumnString(IntPtr stmt, int index)
- {
- return Marshal.PtrToStringUni(SQLite3.ColumnText16(stmt, 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;
- }
- public static Result GetResult(Sqlite3DatabaseHandle db) => nativeLoader.LoadFunction<GetResultDelegate>("sqlite3_errcode").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result GetResultDelegate(Sqlite3DatabaseHandle db);
- public static ExtendedResult ExtendedErrCode(IntPtr db) => nativeLoader.LoadFunction<ExtendedErrCodeDelegate>("sqlite3_extended_errcode").Invoke(db);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate ExtendedResult ExtendedErrCodeDelegate(IntPtr db);
- public static int LibVersionNumber() => nativeLoader.LoadFunction<LibVersionNumberDelegate>("sqlite3_libversion_number").Invoke();
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate int LibVersionNumberDelegate();
- public static Sqlite3BackupHandle BackupInit(Sqlite3DatabaseHandle destDb, string destName, Sqlite3DatabaseHandle sourceDb, string sourceName) => nativeLoader.LoadFunction<BackupInitDelegate>("sqlite3_backup_init").Invoke(destDb, destName, sourceDb, sourceName);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Sqlite3BackupHandle BackupInitDelegate(Sqlite3DatabaseHandle destDb, [MarshalAs(UnmanagedType.LPStr)] string destName, Sqlite3DatabaseHandle sourceDb, [MarshalAs(UnmanagedType.LPStr)] string sourceName);
- public static Result BackupStep(Sqlite3BackupHandle backup, int numPages) => nativeLoader.LoadFunction<BackupStepDelegate>("sqlite3_backup_step").Invoke(backup, numPages);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result BackupStepDelegate(Sqlite3BackupHandle backup, int numPages);
- public static Result BackupFinish(Sqlite3BackupHandle backup) => nativeLoader.LoadFunction<BackupFinishDelegate>("sqlite3_backup_finish").Invoke(backup);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Result BackupFinishDelegate(Sqlite3BackupHandle backup);
- #else
- public static Result Open (string filename, out Sqlite3DatabaseHandle db)
- {
- return (Result)Sqlite3.sqlite3_open (filename, out db);
- }
- public static Result Open (string filename, out Sqlite3DatabaseHandle db, int flags, string vfsName)
- {
- #if USE_WP8_NATIVE_SQLITE
- return (Result)Sqlite3.sqlite3_open_v2(filename, out db, flags, vfsName ?? "");
- #else
- return (Result)Sqlite3.sqlite3_open_v2 (filename, out db, flags, vfsName);
- #endif
- }
- public static Result Close (Sqlite3DatabaseHandle db)
- {
- return (Result)Sqlite3.sqlite3_close (db);
- }
- public static Result Close2 (Sqlite3DatabaseHandle db)
- {
- return (Result)Sqlite3.sqlite3_close_v2 (db);
- }
- public static Result BusyTimeout (Sqlite3DatabaseHandle db, int milliseconds)
- {
- return (Result)Sqlite3.sqlite3_busy_timeout (db, milliseconds);
- }
- public static int Changes (Sqlite3DatabaseHandle db)
- {
- return Sqlite3.sqlite3_changes (db);
- }
- public static Sqlite3Statement Prepare2 (Sqlite3DatabaseHandle db, string query)
- {
- Sqlite3Statement stmt = default (Sqlite3Statement);
- #if USE_WP8_NATIVE_SQLITE || USE_SQLITEPCL_RAW
- var r = Sqlite3.sqlite3_prepare_v2 (db, query, out stmt);
- #else
- stmt = new Sqlite3Statement();
- var r = Sqlite3.sqlite3_prepare_v2(db, query, -1, ref stmt, 0);
- #endif
- if (r != 0) {
- throw SQLiteException.New ((Result)r, GetErrmsg (db));
- }
- return stmt;
- }
- public static Result Step (Sqlite3Statement stmt)
- {
- return (Result)Sqlite3.sqlite3_step (stmt);
- }
- public static Result Reset (Sqlite3Statement stmt)
- {
- return (Result)Sqlite3.sqlite3_reset (stmt);
- }
- public static Result Finalize (Sqlite3Statement stmt)
- {
- return (Result)Sqlite3.sqlite3_finalize (stmt);
- }
- public static long LastInsertRowid (Sqlite3DatabaseHandle db)
- {
- return Sqlite3.sqlite3_last_insert_rowid (db);
- }
- public static string GetErrmsg (Sqlite3DatabaseHandle db)
- {
- return Sqlite3.sqlite3_errmsg (db).utf8_to_string ();
- }
- 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 BindText (Sqlite3Statement stmt, int index, string val, int n, IntPtr free)
- {
- #if USE_WP8_NATIVE_SQLITE
- return Sqlite3.sqlite3_bind_text(stmt, index, val, n);
- #elif USE_SQLITEPCL_RAW
- return Sqlite3.sqlite3_bind_text (stmt, index, val);
- #else
- return Sqlite3.sqlite3_bind_text(stmt, index, val, n, null);
- #endif
- }
- public static int BindBlob (Sqlite3Statement stmt, int index, byte[] val, int n, IntPtr free)
- {
- #if USE_WP8_NATIVE_SQLITE
- return Sqlite3.sqlite3_bind_blob(stmt, index, val, n);
- #elif USE_SQLITEPCL_RAW
- return Sqlite3.sqlite3_bind_blob (stmt, index, val);
- #else
- return Sqlite3.sqlite3_bind_blob(stmt, index, val, n, null);
- #endif
- }
- 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).utf8_to_string ();
- }
- public static string ColumnName16 (Sqlite3Statement stmt, int index)
- {
- return Sqlite3.sqlite3_column_name (stmt, index).utf8_to_string ();
- }
- 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).utf8_to_string ();
- }
- public static string ColumnText16 (Sqlite3Statement stmt, int index)
- {
- return Sqlite3.sqlite3_column_text (stmt, index).utf8_to_string ();
- }
- public static byte[] ColumnBlob (Sqlite3Statement stmt, int index)
- {
- return Sqlite3.sqlite3_column_blob (stmt, index).ToArray ();
- }
- 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).utf8_to_string ();
- }
- public static byte[] ColumnByteArray (Sqlite3Statement stmt, int index)
- {
- int length = ColumnBytes (stmt, index);
- if (length > 0) {
- return ColumnBlob (stmt, index);
- }
- return new byte[0];
- }
- public static Result EnableLoadExtension (Sqlite3DatabaseHandle db, int onoff)
- {
- return (Result)Sqlite3.sqlite3_enable_load_extension (db, onoff);
- }
- public static int LibVersionNumber ()
- {
- return Sqlite3.sqlite3_libversion_number ();
- }
- public static Result GetResult (Sqlite3DatabaseHandle db)
- {
- return (Result)Sqlite3.sqlite3_errcode (db);
- }
- public static ExtendedResult ExtendedErrCode (Sqlite3DatabaseHandle db)
- {
- return (ExtendedResult)Sqlite3.sqlite3_extended_errcode (db);
- }
- public static Sqlite3BackupHandle BackupInit (Sqlite3DatabaseHandle destDb, string destName, Sqlite3DatabaseHandle sourceDb, string sourceName)
- {
- return Sqlite3.sqlite3_backup_init (destDb, destName, sourceDb, sourceName);
- }
- public static Result BackupStep (Sqlite3BackupHandle backup, int numPages)
- {
- return (Result)Sqlite3.sqlite3_backup_step (backup, numPages);
- }
- public static Result BackupFinish (Sqlite3BackupHandle backup)
- {
- return (Result)Sqlite3.sqlite3_backup_finish (backup);
- }
- #endif
- public enum ColType : int
- {
- Integer = 1,
- Float = 2,
- Text = 3,
- Blob = 4,
- Null = 5
- }
- }
- }
|