⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlite3.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
            IntPtr ptr = UnsafeNativeMethods.sqlite3_value_blob_interop(p);
            if (bDest == null)
            {
                return (long) num;
            }
            if ((length + nStart) > bDest.Length)
            {
                length = bDest.Length - nStart;
            }
            if ((length + nDataOffset) > num)
            {
                length = num - nDataOffset;
            }
            if (length > 0)
            {
                Marshal.Copy((IntPtr) (ptr.ToInt32() + nDataOffset), bDest, nStart, length);
            }
            else
            {
                length = 0;
            }
            return (long) length;
        }

        internal override double GetParamValueDouble(IntPtr ptr)
        {
            double num;
            UnsafeNativeMethods.sqlite3_value_double_interop(ptr, out num);
            return num;
        }

        internal override int GetParamValueInt32(IntPtr ptr)
        {
            return UnsafeNativeMethods.sqlite3_value_int_interop(ptr);
        }

        internal override long GetParamValueInt64(IntPtr ptr)
        {
            long num;
            UnsafeNativeMethods.sqlite3_value_int64_interop(ptr, out num);
            return num;
        }

        internal override string GetParamValueText(IntPtr ptr)
        {
            int nativestringlen;
            return this.ToString(UnsafeNativeMethods.sqlite3_value_text_interop(ptr, out nativestringlen), nativestringlen);
        }

        internal override TypeAffinity GetParamValueType(IntPtr ptr)
        {
            return UnsafeNativeMethods.sqlite3_value_type_interop(ptr);
        }

        internal override long GetRowIdForCursor(SQLiteStatement stmt, int cursor)
        {
            long rowid;
            if (UnsafeNativeMethods.sqlite3_cursor_rowid(stmt._sqlite_stmt, cursor, out rowid) == 0)
            {
                return rowid;
            }
            return (long) 0;
        }

        internal override string GetText(SQLiteStatement stmt, int index)
        {
            int nativestringlen;
            return this.ToString(UnsafeNativeMethods.sqlite3_column_text_interop(stmt._sqlite_stmt, index, out nativestringlen), nativestringlen);
        }

        internal override object GetValue(SQLiteStatement stmt, int index, ref SQLiteType typ)
        {
            if (typ.Affinity == TypeAffinity.Uninitialized)
            {
                typ = SQLiteConvert.ColumnToType(stmt, index);
            }
            if (this.IsNull(stmt, index))
            {
                return DBNull.Value;
            }
            Type type = SQLiteConvert.SQLiteTypeToType(typ);
            switch (SQLiteConvert.TypeToAffinity(type))
            {
                case TypeAffinity.Int64:
                    return Convert.ChangeType(this.GetInt64(stmt, index), type, null);

                case TypeAffinity.Double:
                    return Convert.ChangeType(this.GetDouble(stmt, index), type, null);

                case TypeAffinity.Blob:
                    if ((typ.Type != DbType.Guid) || (typ.Affinity != TypeAffinity.Text))
                    {
                        int nLength = (int) this.GetBytes(stmt, index, 0, null, 0, 0);
                        byte[] bDest = new byte[nLength];
                        this.GetBytes(stmt, index, 0, bDest, 0, nLength);
                        if ((typ.Type == DbType.Guid) && (nLength == 0x10))
                        {
                            return new Guid(bDest);
                        }
                        return bDest;
                    }
                    return new Guid(this.GetText(stmt, index));

                case TypeAffinity.DateTime:
                    return this.GetDateTime(stmt, index);
            }
            return this.GetText(stmt, index);
        }

        internal override bool IsNull(SQLiteStatement stmt, int index)
        {
            return (this.ColumnAffinity(stmt, index) == TypeAffinity.Null);
        }

        internal override void Open(string strFilename)
        {
            if (this._sql == null)
            {
                IntPtr db;
                int errorCode = UnsafeNativeMethods.sqlite3_open_interop(base.ToUTF8(strFilename), out db);
                if (errorCode > 0)
                {
                    throw new SQLiteException(errorCode, null);
                }
                this._sql = db;
                this._functionsArray = SQLiteFunction.BindFunctions(this);
            }
        }

        internal override SQLiteStatement Prepare(string strSql, SQLiteStatement previous, out string strRemain)
        {
            SQLiteStatement statement2;
            IntPtr stmt = IntPtr.Zero;
            IntPtr ptrRemain = IntPtr.Zero;
            int nRemain = 0;
            int errorCode = 0x11;
            int num3 = 0;
            byte[] buffer = base.ToUTF8(strSql);
            string typedefs = null;
            SQLiteStatement statement = null;
            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr pSql = handle.AddrOfPinnedObject();
            try
            {
                while ((errorCode == 0x11) && (num3 < 3))
                {
                    errorCode = UnsafeNativeMethods.sqlite3_prepare_interop(this._sql, pSql, buffer.Length - 1, out stmt, out ptrRemain, out nRemain);
                    num3++;
                    if ((errorCode == 1) && (string.Compare(this.SQLiteLastError(), "near \"TYPES\": syntax error", 5) == 0))
                    {
                        int index = strSql.IndexOf(';');
                        if (index == -1)
                        {
                            index = strSql.Length - 1;
                        }
                        typedefs = strSql.Substring(0, index + 1);
                        strSql = strSql.Substring(index + 1);
                        strRemain = "";
                        while ((statement == null) && (strSql.Length > 0))
                        {
                            statement = this.Prepare(strSql, previous, out strRemain);
                            strSql = strRemain;
                        }
                        if (statement != null)
                        {
                            statement.SetTypes(typedefs);
                        }
                        return statement;
                    }
                }
                if (errorCode > 0)
                {
                    throw new SQLiteException(errorCode, this.SQLiteLastError());
                }
                strRemain = SQLiteConvert.UTF8ToString(ptrRemain, nRemain);
                if (stmt != IntPtr.Zero)
                {
                    statement = new SQLiteStatement(this, stmt, strSql.Substring(0, strSql.Length - strRemain.Length), previous);
                }
                statement2 = statement;
            }
            finally
            {
                handle.Free();
            }
            return statement2;
        }

        internal override int Reset(SQLiteStatement stmt)
        {
            int errorCode = UnsafeNativeMethods.sqlite3_reset_interop(stmt._sqlite_stmt);
            switch (errorCode)
            {
                case 0x11:
                    string strRemain;
                    using (SQLiteStatement statement = this.Prepare(stmt._sqlStatement, null, out strRemain))
                    {
                        stmt._sqlite_stmt.Dispose();
                        stmt._sqlite_stmt = statement._sqlite_stmt;
                        statement._sqlite_stmt = null;
                        stmt.BindParameters();
                    }
                    return -1;

                case 6:
                    return errorCode;
            }
            if (errorCode > 0)
            {
                throw new SQLiteException(errorCode, this.SQLiteLastError());
            }
            return 0;
        }

        internal override void ReturnBlob(IntPtr context, byte[] value)
        {
            UnsafeNativeMethods.sqlite3_result_blob_interop(context, value, value.Length, (IntPtr) (-1));
        }

        internal override void ReturnDouble(IntPtr context, double value)
        {
            UnsafeNativeMethods.sqlite3_result_double_interop(context, ref value);
        }

        internal override void ReturnError(IntPtr context, string value)
        {
            UnsafeNativeMethods.sqlite3_result_error_interop(context, base.ToUTF8(value), value.Length);
        }

        internal override void ReturnInt32(IntPtr context, int value)
        {
            UnsafeNativeMethods.sqlite3_result_int_interop(context, value);
        }

        internal override void ReturnInt64(IntPtr context, long value)
        {
            UnsafeNativeMethods.sqlite3_result_int64_interop(context, ref value);
        }

        internal override void ReturnNull(IntPtr context)
        {
            UnsafeNativeMethods.sqlite3_result_null_interop(context);
        }

        internal override void ReturnText(IntPtr context, string value)
        {
            byte[] buffer = base.ToUTF8(value);
            UnsafeNativeMethods.sqlite3_result_text_interop(context, base.ToUTF8(value), buffer.Length - 1, (IntPtr) (-1));
        }

        internal override void SetCommitHook(SQLiteCommitCallback func)
        {
            UnsafeNativeMethods.sqlite3_commit_hook_interop(this._sql, func);
        }

        internal override void SetPassword(byte[] passwordBytes)
        {
            int errorCode = UnsafeNativeMethods.sqlite3_key_interop(this._sql, passwordBytes, passwordBytes.Length);
            if (errorCode > 0)
            {
                throw new SQLiteException(errorCode, this.SQLiteLastError());
            }
        }

        internal override void SetRollbackHook(SQLiteRollbackCallback func)
        {
            UnsafeNativeMethods.sqlite3_rollback_hook_interop(this._sql, func);
        }

        internal override void SetTimeout(int nTimeoutMS)
        {
            int errorCode = UnsafeNativeMethods.sqlite3_busy_timeout_interop(this._sql, nTimeoutMS);
            if (errorCode > 0)
            {
                throw new SQLiteException(errorCode, this.SQLiteLastError());
            }
        }

        internal override void SetUpdateHook(SQLiteUpdateCallback func)
        {
            UnsafeNativeMethods.sqlite3_update_hook_interop(this._sql, func);
        }

        internal override string SQLiteLastError()
        {
            return SQLiteBase.SQLiteLastError(this._sql);
        }

        internal override bool Step(SQLiteStatement stmt)
        {
            Random random = null;
            uint num = (uint) (Environment.TickCount + (stmt._command._commandTimeout * 0x3e8));
            while (true)
            {
                int errorCode = UnsafeNativeMethods.sqlite3_step_interop(stmt._sqlite_stmt);
                switch (errorCode)
                {
                    case 100:
                        return true;

                    case 0x65:
                        return false;
                }
                if (errorCode > 0)
                {
                    int num3 = this.Reset(stmt);
                    if (num3 == 0)
                    {
                        throw new SQLiteException(errorCode, this.SQLiteLastError());
                    }
                    if (((num3 == 6) || (num3 == 5)) && (stmt._command != null))
                    {
                        if (random == null)
                        {
                            random = new Random();
                        }
                        if ((Environment.TickCount - num) > 0)
                        {
                            throw new SQLiteException(num3, this.SQLiteLastError());
                        }
                        UnsafeNativeMethods.sqlite3_sleep_interop((uint) random.Next(1, 250));
                    }
                }
            }
        }

        internal override int Changes
        {
            get
            {
                return UnsafeNativeMethods.sqlite3_changes_interop(this._sql);
            }
        }

        internal override string Version
        {
            get
            {
                int nativestringlen;
                return this.ToString(UnsafeNativeMethods.sqlite3_libversion_interop(out nativestringlen), nativestringlen);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -