Пример #1
0
        public static void ThrowExceptionForRC(int rc, Sqlite3Handle db)
        {
            if (rc == Constants.SQLITE_OK
                || rc == Constants.SQLITE_ROW
                || rc == Constants.SQLITE_DONE)
            {
                return;
            }

            var message = db == null || db.IsInvalid
                ? NativeMethods.sqlite3_errstr(rc)
                : NativeMethods.sqlite3_errmsg(db);

            throw new SqliteException(Strings.FormatSqliteNativeError(rc, message), rc);
        }
Пример #2
0
        public static int sqlite3_exec(Sqlite3Handle pDb, string sql)
        {
            var zSql = MarshalEx.StringToHGlobalUTF8(sql);

            try
            {
                IntPtr tmp;
                return(Sqlite3.exec(pDb, zSql, IntPtr.Zero, IntPtr.Zero, out tmp));
            } finally {
                if (zSql != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zSql);
                }
            }
        }
        public static void ThrowExceptionForRC(int rc, Sqlite3Handle db)
        {
            if (rc == Constants.SQLITE_OK ||
                rc == Constants.SQLITE_ROW ||
                rc == Constants.SQLITE_DONE)
            {
                return;
            }

            var message = db == null || db.IsInvalid
                ? NativeMethods.sqlite3_errstr(rc)
                : NativeMethods.sqlite3_errmsg(db);

            throw new SqliteException(Strings.FormatSqliteNativeError(rc, message), rc);
        }
Пример #4
0
        public static string sqlite3_db_filename(Sqlite3Handle db, string zDbName)
        {
            var ptr = MarshalEx.StringToHGlobalUTF8(zDbName);

            try
            {
                return(MarshalEx.PtrToStringUTF8(Sqlite3.db_filename(db, ptr)));
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(ptr);
                }
            }
        }
        //TODO move to a utility class
        public static int sqlite3_step_blocking(Sqlite3Handle db, Sqlite3StmtHandle stmt, int milliseconds)
        {
            var timer = new Stopwatch();
            int rc;

            timer.Start();
            while (SQLITE_LOCKED == (rc = sqlite3_step(stmt)))
            {
                if (timer.ElapsedMilliseconds >= milliseconds)
                {
                    return(rc);
                }
                sqlite3_reset(stmt);
            }
            return(rc);
        }
Пример #6
0
        public static int sqlite3_prepare_v2(Sqlite3Handle db, string zSql, out Sqlite3StmtHandle ppStmt, out string pzTail)
        {
            int nByte;
            var zSqlPtr = MarshalEx.StringToHGlobalUTF8(zSql, out nByte);

            try
            {
                IntPtr pzTailPtr;
                var    rc = Sqlite3.prepare_v2(db, zSqlPtr, nByte, out ppStmt, out pzTailPtr);
                pzTail = MarshalEx.PtrToStringUTF8(pzTailPtr);

                return(rc);
            }
            finally
            {
                Marshal.FreeHGlobal(zSqlPtr);
            }
        }
Пример #7
0
        public static int sqlite3_open_v2(string filename, out Sqlite3Handle ppDb, int flags, string vfs)
        {
            var zFilename = MarshalEx.StringToHGlobalUTF8(filename);
            var zVfs      = string.IsNullOrEmpty(vfs) ? IntPtr.Zero : MarshalEx.StringToHGlobalUTF8(vfs);

            try
            {
                return(Sqlite3.open_v2(zFilename, out ppDb, flags, zVfs));
            }
            finally
            {
                if (zFilename != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zFilename);
                }
                if (zVfs != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zVfs);
                }
            }
        }
Пример #8
0
        public static int sqlite3_blob_open(Sqlite3Handle pDb, string db, string table, string column, long iRow,
                                            int flags, out Sqlite3BlobHandle ppBlob)
        {
            var zDb     = MarshalEx.StringToHGlobalUTF8(db);
            var zTable  = MarshalEx.StringToHGlobalUTF8(table);
            var zColumn = MarshalEx.StringToHGlobalUTF8(column);

            try {
                return(Sqlite3.blob_open(pDb, zDb, zTable, zColumn, iRow, flags, out ppBlob));
            } finally {
                if (zDb != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zDb);
                }
                if (zTable != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zTable);
                }
                if (zColumn != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zColumn);
                }
            }
        }
 private static extern int sqlite3_open_v2(IntPtr filename, out Sqlite3Handle ppDb, int flags, IntPtr vfs);
Пример #10
0
 private static extern IntPtr sqlite3_errmsg_raw(Sqlite3Handle db);
Пример #11
0
 private static extern IntPtr sqlite3_db_filename(Sqlite3Handle db, IntPtr zDbName);
Пример #12
0
 public static string sqlite3_errmsg(Sqlite3Handle db)
 => MarshalEx.PtrToStringUTF8(Sqlite3.errmsg(db));
Пример #13
0
 public static int sqlite3_busy_timeout(Sqlite3Handle db, int ms)
 => Sqlite3.busy_timeout(db, ms);
Пример #14
0
 public int blob_open(Sqlite3Handle ppDb, IntPtr zDb, IntPtr zTable, IntPtr zColumn, long iRow, int flags, out Sqlite3BlobHandle ppBlob)
 => sqlite3_blob_open(ppDb, zDb, zTable, zColumn, iRow, flags, out ppBlob);
Пример #15
0
 public int exec(Sqlite3Handle pDb, IntPtr zSql, IntPtr callback, IntPtr callbackArg, out IntPtr errMsg)
 => sqlite3_exec(pDb, zSql, callback, callbackArg, out errMsg);
 public int open_v2(IntPtr filename, out Sqlite3Handle ppDb, int flags, IntPtr vfs)
     => sqlite3_open_v2(filename, out ppDb, flags, vfs);
 public IntPtr errmsg(Sqlite3Handle db)
     => sqlite3_errmsg(db);
 public int enable_load_extension(Sqlite3Handle db, int onoff)
     => sqlite3_enable_load_extension(db, onoff);
 private static extern int sqlite3_enable_load_extension(Sqlite3Handle db, int onoff);
 public IntPtr db_filename(Sqlite3Handle db, IntPtr zDbName)
     => sqlite3_db_filename(db, zDbName);
Пример #21
0
 public int busy_timeout(Sqlite3Handle db, int ms)
 => sqlite3_busy_timeout(db, ms);
Пример #22
0
 private static extern int sqlite3_prepare_v2(Sqlite3Handle db, IntPtr zSql, int nByte, out Sqlite3StmtHandle ppStmt, out IntPtr pzTail);
Пример #23
0
 //TODO move to a utility class
 public static int sqlite3_step_blocking(Sqlite3Handle db, Sqlite3StmtHandle stmt, int milliseconds)
 {
     var timer = new Stopwatch();
     int rc;
     timer.Start();
     while (SQLITE_LOCKED == (rc = sqlite3_step(stmt)))
     {
         if (timer.ElapsedMilliseconds >= milliseconds)
         {
             return rc;
         }
         sqlite3_reset(stmt);
     }
     return rc;
 }
 public int prepare_v2(Sqlite3Handle db, IntPtr zSql, int nByte, out Sqlite3StmtHandle ppStmt, out IntPtr pzTail)
     => sqlite3_prepare_v2(db, zSql, nByte, out ppStmt, out pzTail);
Пример #25
0
 public IntPtr errmsg(Sqlite3Handle db)
 => sqlite3_errmsg(db);
 public int busy_timeout(Sqlite3Handle db, int ms)
     => sqlite3_busy_timeout(db, ms);
Пример #27
0
 public override string GetFilename(Sqlite3Handle db, string zDbName)
 => NativeMethods.sqlite3_db_filename(db, zDbName);
 private static extern int sqlite3_changes(Sqlite3Handle db);
 public virtual string GetFilename(Sqlite3Handle db, string zDbName)
     => null;
 public int changes(Sqlite3Handle db)
     => sqlite3_changes(db);
Пример #31
0
 public int changes(Sqlite3Handle db)
 => sqlite3_changes(db);
Пример #32
0
 public int prepare_v2(Sqlite3Handle db, IntPtr zSql, int nByte, out Sqlite3StmtHandle ppStmt, out IntPtr pzTail)
 => sqlite3_prepare_v2(db, zSql, nByte, out ppStmt, out pzTail);
Пример #33
0
 public static string sqlite3_db_filename(Sqlite3Handle db, string zDbName)
 {
     var ptr = MarshalEx.StringToHGlobalUTF8(zDbName);
     try
     {
         return MarshalEx.PtrToStringUTF8(sqlite3_db_filename(db, ptr));
     }
     finally
     {
         if (ptr != IntPtr.Zero)
         {
             Marshal.FreeHGlobal(ptr);
         }
     }
 }
        public override void Close()
        {
            if (_db == null
                || _db.IsInvalid)
            {
                return;
            }

            Transaction?.Dispose();
            _db.Dispose();
            _db = null;
            SetState(ConnectionState.Closed);
        }
Пример #35
0
 public static string sqlite3_errmsg(Sqlite3Handle db) => MarshalEx.PtrToStringUTF8(sqlite3_errmsg_raw(db));
 public static int sqlite3_enable_load_extension(Sqlite3Handle db, int onoff)
     => Sqlite3.enable_load_extension(db, onoff);
Пример #37
0
 public static int sqlite3_open_v2(string filename, out Sqlite3Handle ppDb, int flags, string vfs)
 {
     var zFilename = MarshalEx.StringToHGlobalUTF8(filename);
     var zVfs = string.IsNullOrEmpty(vfs) ? IntPtr.Zero : MarshalEx.StringToHGlobalUTF8(vfs);
     try
     {
         return sqlite3_open_v2(zFilename, out ppDb, flags, zVfs);
     }
     finally
     {
         if (zFilename != IntPtr.Zero)
         {
             Marshal.FreeHGlobal(zFilename);
         }
         if (zVfs != IntPtr.Zero)
         {
             Marshal.FreeHGlobal(zVfs);
         }
     }
 }
 public static int sqlite3_busy_timeout(Sqlite3Handle db, int ms)
     => Sqlite3.busy_timeout(db, ms);
Пример #39
0
        public static int sqlite3_prepare_v2(Sqlite3Handle db, string zSql, out Sqlite3StmtHandle ppStmt, out string pzTail)
        {
            int nByte;
            var zSqlPtr = MarshalEx.StringToHGlobalUTF8(zSql, out nByte);
            try
            {
                // TODO: Something fancy with indexes?
                IntPtr pzTailPtr;
                var rc = sqlite3_prepare_v2(db, zSqlPtr, nByte, out ppStmt, out pzTailPtr);
                pzTail = MarshalEx.PtrToStringUTF8(pzTailPtr);

                return rc;
            }
            finally
            {
                Marshal.FreeHGlobal(zSqlPtr);
            }
        }
 public static int sqlite3_changes(Sqlite3Handle db)
     => Sqlite3.changes(db);
Пример #41
0
 private static extern int sqlite3_exec(Sqlite3Handle ppDb, IntPtr zSql, IntPtr callback, IntPtr callbackArg, out IntPtr errMsg);
 private static extern IntPtr sqlite3_db_filename(Sqlite3Handle db, IntPtr zDbName);
 private static extern IntPtr sqlite3_errmsg_raw(Sqlite3Handle db);
 private static extern int sqlite3_open_v2(IntPtr filename, out Sqlite3Handle ppDb, int flags, IntPtr vfs);
Пример #45
0
 private static extern int sqlite3_blob_open(Sqlite3Handle pDb, IntPtr zDb, IntPtr zTable, IntPtr zColumn, long iRow, int flags, out Sqlite3BlobHandle ppBlob);
 private static extern int sqlite3_prepare_v2(Sqlite3Handle db, IntPtr zSql, int nByte, out Sqlite3StmtHandle ppStmt, out IntPtr pzTail);
Пример #47
0
 public static string GetFilename(Sqlite3Handle db, string zDbName)
 => _strategy.GetFilename(db, zDbName);
Пример #48
0
 public int open_v2(IntPtr filename, out Sqlite3Handle ppDb, int flags, IntPtr vfs)
 => sqlite3_open_v2(filename, out ppDb, flags, vfs);
Пример #49
0
 public virtual string GetFilename(Sqlite3Handle db, string zDbName)
 => null;
 public override string GetFilename(Sqlite3Handle db, string zDbName)
     => NativeMethods.sqlite3_db_filename(db, zDbName);
Пример #51
0
 public static int sqlite3_changes(Sqlite3Handle db)
 => Sqlite3.changes(db);
Пример #52
0
 public static extern int sqlite3_busy_timeout(Sqlite3Handle db, int ms);
Пример #53
0
 public static int sqlite3_enable_load_extension(Sqlite3Handle db, int onoff)
 => Sqlite3.enable_load_extension(db, onoff);
Пример #54
0
 public static extern int sqlite3_changes(Sqlite3Handle db);
 public static extern int sqlite3_busy_timeout(Sqlite3Handle db, int ms);
Пример #56
0
 private static extern int sqlite3_changes(Sqlite3Handle db);
 public static extern int sqlite3_changes(Sqlite3Handle db);
 public static string GetFilename(Sqlite3Handle db, string zDbName)
     => _strategy.GetFilename(db, zDbName);