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

📄 sqliteconvert.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Client.Data
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Runtime.InteropServices;
    using System.Text;

    public abstract class SQLiteConvert
    {
        internal SQLiteDateFormats _datetimeFormat;
        private static readonly string[] _datetimeFormats = new string[] { 
            "yyyy-MM-dd HH:mm:ss.fffffff", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMMddTHHmmssfffffff", "yyyy-MM-dd", "yy-MM-dd", "yyyyMMdd", "HH:mm:ss", "HH:mm", "THHmmss", "THHmm", "yyyy-MM-dd HH:mm:ss.fff", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss", 
            "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-ddTHH:mm:ss.ffffff", "HH:mm:ss.fff"
         };
        private static int[] _dbtypetocolumnsize;
        private static object[] _dbtypetonumericprecision;
        private static object[] _dbtypetonumericscale;
        private static Type[] _dbtypeToType;
        private static Type[] _typeaffinities;
        private static TypeAffinity[] _typecodeAffinities;
        private static SQLiteTypeNames[] _typeNames;
        private static DbType[] _typetodbtype;
        private static Encoding _utf8 = new UTF8Encoding();

        static SQLiteConvert()
        {
            Type[] typeArray = new Type[12];
            typeArray[1] = typeof(long);
            typeArray[2] = typeof(double);
            typeArray[3] = typeof(string);
            typeArray[4] = typeof(byte[]);
            typeArray[5] = typeof(DBNull);
            typeArray[10] = typeof(DateTime);
            _typeaffinities = typeArray;
            _typetodbtype = new DbType[] { 
                DbType.Object, DbType.Binary, DbType.Object, DbType.Boolean, DbType.SByte, DbType.SByte, DbType.Byte, DbType.Int16, DbType.UInt16, DbType.Int32, DbType.UInt32, DbType.Int64, DbType.UInt64, DbType.Single, DbType.Double, DbType.Decimal, 
                DbType.DateTime, DbType.Object, DbType.String
             };
            _dbtypetocolumnsize = new int[] { 
                0x7fffffff, 0x7fffffff, 1, 1, 8, 8, 8, 8, 8, 0x10, 2, 4, 8, 0x7fffffff, 1, 4, 
                0x7fffffff, 8, 2, 4, 8, 8, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff
             };
            _dbtypetonumericprecision = new object[] { 
                DBNull.Value, DBNull.Value, 3, DBNull.Value, 0x13, DBNull.Value, DBNull.Value, 0x35, 0x35, DBNull.Value, 5, 10, 0x13, DBNull.Value, 3, 0x18, 
                DBNull.Value, DBNull.Value, 5, 10, 0x13, 0x35, DBNull.Value, DBNull.Value, DBNull.Value
             };
            _dbtypetonumericscale = new object[] { 
                DBNull.Value, DBNull.Value, 0, DBNull.Value, 4, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, 0, 0, 0, DBNull.Value, 0, DBNull.Value, 
                DBNull.Value, DBNull.Value, 0, 0, 0, 0, DBNull.Value, DBNull.Value, DBNull.Value
             };
            _dbtypeToType = new Type[] { 
                typeof(string), typeof(byte[]), typeof(byte), typeof(bool), typeof(decimal), typeof(DateTime), typeof(DateTime), typeof(decimal), typeof(double), typeof(Guid), typeof(short), typeof(int), typeof(long), typeof(object), typeof(sbyte), typeof(float), 
                typeof(string), typeof(DateTime), typeof(ushort), typeof(uint), typeof(ulong), typeof(double), typeof(string), typeof(string), typeof(string), typeof(string)
             };
            _typecodeAffinities = new TypeAffinity[] { 
                TypeAffinity.Null, TypeAffinity.Blob, TypeAffinity.Null, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Double, TypeAffinity.Double, TypeAffinity.Double, 
                TypeAffinity.DateTime, TypeAffinity.Null, TypeAffinity.Text
             };
            _typeNames = new SQLiteTypeNames[] { 
                new SQLiteTypeNames("COUNTER", DbType.Int64), new SQLiteTypeNames("AUTOINCREMENT", DbType.Int64), new SQLiteTypeNames("IDENTITY", DbType.Int64), new SQLiteTypeNames("LONGTEXT", DbType.String), new SQLiteTypeNames("LONGCHAR", DbType.String), new SQLiteTypeNames("LONGVARCHAR", DbType.String), new SQLiteTypeNames("LONG", DbType.Int64), new SQLiteTypeNames("TINYINT", DbType.Byte), new SQLiteTypeNames("INTEGER", DbType.Int64), new SQLiteTypeNames("INT", DbType.Int32), new SQLiteTypeNames("VARCHAR", DbType.String), new SQLiteTypeNames("NVARCHAR", DbType.String), new SQLiteTypeNames("CHAR", DbType.String), new SQLiteTypeNames("NCHAR", DbType.String), new SQLiteTypeNames("TEXT", DbType.String), new SQLiteTypeNames("NTEXT", DbType.String), 
                new SQLiteTypeNames("STRING", DbType.String), new SQLiteTypeNames("DOUBLE", DbType.Double), new SQLiteTypeNames("FLOAT", DbType.Double), new SQLiteTypeNames("REAL", DbType.Single), new SQLiteTypeNames("BIT", DbType.Boolean), new SQLiteTypeNames("YESNO", DbType.Boolean), new SQLiteTypeNames("LOGICAL", DbType.Boolean), new SQLiteTypeNames("BOOL", DbType.Boolean), new SQLiteTypeNames("NUMERIC", DbType.Decimal), new SQLiteTypeNames("DECIMAL", DbType.Decimal), new SQLiteTypeNames("MONEY", DbType.Decimal), new SQLiteTypeNames("CURRENCY", DbType.Decimal), new SQLiteTypeNames("TIME", DbType.DateTime), new SQLiteTypeNames("DATE", DbType.DateTime), new SQLiteTypeNames("SMALLDATE", DbType.DateTime), new SQLiteTypeNames("BLOB", DbType.Binary), 
                new SQLiteTypeNames("BINARY", DbType.Binary), new SQLiteTypeNames("VARBINARY", DbType.Binary), new SQLiteTypeNames("IMAGE", DbType.Binary), new SQLiteTypeNames("GENERAL", DbType.Binary), new SQLiteTypeNames("OLEOBJECT", DbType.Binary), new SQLiteTypeNames("GUID", DbType.Guid), new SQLiteTypeNames("UNIQUEIDENTIFIER", DbType.Guid), new SQLiteTypeNames("MEMO", DbType.String), new SQLiteTypeNames("NOTE", DbType.String), new SQLiteTypeNames("SMALLINT", DbType.Int16), new SQLiteTypeNames("BIGINT", DbType.Int64)
             };
        }

        internal SQLiteConvert(SQLiteDateFormats fmt)
        {
            this._datetimeFormat = fmt;
        }

        internal static SQLiteType ColumnToType(SQLiteStatement stmt, int i)
        {
            SQLiteType type;
            type.Type = TypeNameToDbType(stmt._sql.ColumnType(stmt, i, out type.Affinity));
            return type;
        }

        internal static int DbTypeToColumnSize(DbType typ)
        {
            return _dbtypetocolumnsize[(int) typ];
        }

        internal static object DbTypeToNumericPrecision(DbType typ)
        {
            return _dbtypetonumericprecision[(int) typ];
        }

        internal static object DbTypeToNumericScale(DbType typ)
        {
            return _dbtypetonumericscale[(int) typ];
        }

        internal static Type DbTypeToType(DbType typ)
        {
            return _dbtypeToType[(int) typ];
        }

        public static string[] Split(string source, char separator)
        {
            char[] anyOf = new char[] { '"', separator };
            char[] chArray2 = new char[] { '"' };
            int startIndex = 0;
            List<string> list = new List<string>();
            while (source.Length > 0)
            {
                startIndex = source.IndexOfAny(anyOf, startIndex);
                if (startIndex == -1)
                {
                    break;
                }
                if (source[startIndex] == anyOf[0])
                {
                    source = source.Remove(startIndex, 1);
                    startIndex = source.IndexOfAny(chArray2, startIndex);
                    if (startIndex == -1)
                    {
                        source = "\"" + source;
                        break;
                    }
                    source = source.Remove(startIndex, 1);
                }
                else
                {
                    string text = source.Substring(0, startIndex).Trim();
                    source = source.Substring(startIndex + 1).Trim();
                    if (text.Length > 0)
                    {
                        list.Add(text);
                    }
                    startIndex = 0;
                }
            }
            if (source.Length > 0)
            {
                list.Add(source);
            }
            string[] textArray = new string[list.get_Count()];
            list.CopyTo(textArray, 0);
            return textArray;
        }

        internal static Type SQLiteTypeToType(SQLiteType t)
        {
            if (t.Type != DbType.Object)
            {
                return DbTypeToType(t.Type);
            }
            return _typeaffinities[(int) t.Affinity];
        }

        public DateTime ToDateTime(string dateText)
        {
            if (this._datetimeFormat == SQLiteDateFormats.Ticks)
            {
                return new DateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture));
            }
            return DateTime.ParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
        }

        internal DateTime ToDateTime(IntPtr ptr, int len)
        {
            return this.ToDateTime(this.ToString(ptr, len));
        }

        public string ToString(DateTime dateValue)
        {
            if (this._datetimeFormat == SQLiteDateFormats.Ticks)
            {
                return dateValue.Ticks.ToString(CultureInfo.InvariantCulture);
            }
            return dateValue.ToString(_datetimeFormats[0], CultureInfo.InvariantCulture);
        }

        public virtual string ToString(IntPtr nativestring, int nativestringlen)
        {
            return UTF8ToString(nativestring, nativestringlen);
        }

        public byte[] ToUTF8(DateTime dateTimeValue)
        {
            return this.ToUTF8(this.ToString(dateTimeValue));
        }

        public byte[] ToUTF8(string sourceText)
        {
            int index = _utf8.GetByteCount(sourceText) + 1;
            byte[] bytes = new byte[index];
            index = _utf8.GetBytes(sourceText, 0, sourceText.Length, bytes, 0);
            bytes[index] = 0;
            return bytes;
        }

        internal static DbType TypeNameToDbType(string Name)
        {
            if (!string.IsNullOrEmpty(Name))
            {
                int length = _typeNames.Length;
                for (int i = 0; i < length; i++)
                {
                    if (string.Compare(Name, 0, _typeNames[i].typeName, 0, _typeNames[i].typeName.Length, true, CultureInfo.InvariantCulture) == 0)
                    {
                        return _typeNames[i].dataType;
                    }
                }
            }
            return DbType.Object;
        }

        internal static TypeAffinity TypeToAffinity(Type typ)
        {
            TypeCode typeCode = Type.GetTypeCode(typ);
            if (typeCode != TypeCode.Object)
            {
                return _typecodeAffinities[(int) typeCode];
            }
            if ((typ != typeof(byte[])) && (typ != typeof(Guid)))
            {
                return TypeAffinity.Text;
            }
            return TypeAffinity.Blob;
        }

        internal static DbType TypeToDbType(Type typ)
        {
            TypeCode typeCode = Type.GetTypeCode(typ);
            if (typeCode != TypeCode.Object)
            {
                return _typetodbtype[(int) typeCode];
            }
            if (typ == typeof(byte[]))
            {
                return DbType.Binary;
            }
            if (typ == typeof(Guid))
            {
                return DbType.Guid;
            }
            return DbType.String;
        }

        public static string UTF8ToString(IntPtr nativestring, int nativestringlen)
        {
            if (nativestringlen == 0)
            {
                return "";
            }
            byte[] destination = new byte[nativestringlen];
            Marshal.Copy(nativestring, destination, 0, nativestringlen);
            return _utf8.GetString(destination, 0, nativestringlen);
        }
    }
}

⌨️ 快捷键说明

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