コード例 #1
0
        private static string GetDefaultTypeName(SQLiteConnection connection)
        {
            if (((connection != null ? connection.Flags : SQLiteConnectionFlags.None) & SQLiteConnectionFlags.NoConvertSettings) == SQLiteConnectionFlags.NoConvertSettings)
            {
                return(SQLiteConvert.FallbackDefaultTypeName);
            }
            string str          = "Use_SQLiteConvert_DefaultTypeName";
            object settingValue = null;
            string str1         = null;

            if (connection == null || !connection.TryGetCachedSetting(str, str1, out settingValue))
            {
                try
                {
                    settingValue = UnsafeNativeMethods.GetSettingValue(str, str1) ?? SQLiteConvert.FallbackDefaultTypeName;
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.SetCachedSetting(str, settingValue);
                    }
                }
            }
            return(SQLiteConvert.SettingValueToString(settingValue));
        }
コード例 #2
0
        public override bool TryGetValue(string keyword, out object value)
        {
            bool flag = base.TryGetValue(keyword, out value);

            if (!this._properties.ContainsKey(keyword))
            {
                return(flag);
            }
            PropertyDescriptor item = this._properties[keyword] as PropertyDescriptor;

            if (item == null)
            {
                return(flag);
            }
            if (!flag)
            {
                DefaultValueAttribute defaultValueAttribute = item.Attributes[typeof(DefaultValueAttribute)] as DefaultValueAttribute;
                if (defaultValueAttribute != null)
                {
                    value = defaultValueAttribute.Value;
                    flag  = true;
                }
            }
            else if (item.PropertyType == typeof(bool))
            {
                value = SQLiteConvert.ToBoolean(value);
            }
            else if (item.PropertyType != typeof(byte[]))
            {
                value = TypeDescriptor.GetConverter(item.PropertyType).ConvertFrom(value);
            }
            return(flag);
        }
コード例 #3
0
 static SQLiteConvert()
 {
     SQLiteConvert.FallbackDefaultTypeName = string.Empty;
     SQLiteConvert.UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     SQLiteConvert.OleAutomationEpochAsJulianDay = 2415018.5;
     SQLiteConvert.MinimumJd = SQLiteConvert.computeJD(DateTime.MinValue);
     SQLiteConvert.MaximumJd = SQLiteConvert.computeJD(DateTime.MaxValue);
     string[] strArrays = new string[] { "THHmmssK", "THHmmK", "HH:mm:ss.FFFFFFFK", "HH:mm:ssK", "HH:mmK", "yyyy-MM-dd HH:mm:ss.FFFFFFFK", "yyyy-MM-dd HH:mm:ssK", "yyyy-MM-dd HH:mmK", "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", "yyyy-MM-ddTHH:mmK", "yyyy-MM-ddTHH:mm:ssK", "yyyyMMddHHmmssK", "yyyyMMddHHmmK", "yyyyMMddTHHmmssFFFFFFFK", "THHmmss", "THHmm", "HH:mm:ss.FFFFFFF", "HH:mm:ss", "HH:mm", "yyyy-MM-dd HH:mm:ss.FFFFFFF", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-ddTHH:mm:ss.FFFFFFF", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMMddTHHmmssFFFFFFF", "yyyy-MM-dd", "yyyyMMdd", "yy-MM-dd" };
     SQLiteConvert._datetimeFormats     = strArrays;
     SQLiteConvert._datetimeFormatUtc   = SQLiteConvert._datetimeFormats[5];
     SQLiteConvert._datetimeFormatLocal = SQLiteConvert._datetimeFormats[19];
     SQLiteConvert._utf8 = new UTF8Encoding();
     Type[] typeArray = new Type[] { typeof(object), typeof(long), typeof(double), typeof(string), typeof(byte[]), typeof(object), typeof(DateTime), typeof(object) };
     SQLiteConvert._affinitytotype = typeArray;
     DbType[] dbTypeArray = 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 };
     SQLiteConvert._typetodbtype       = dbTypeArray;
     SQLiteConvert._dbtypetocolumnsize = new int[] { 2147483647, 2147483647, 1, 1, 8, 8, 8, 8, 8, 16, 2, 4, 8, 2147483647, 1, 4, 2147483647, 8, 2, 4, 8, 8, 2147483647, 2147483647, 2147483647, 2147483647 };
     object[] value = new object[] { DBNull.Value, DBNull.Value, 3, DBNull.Value, 19, DBNull.Value, DBNull.Value, 53, 53, DBNull.Value, 5, 10, 19, DBNull.Value, 3, 24, DBNull.Value, DBNull.Value, 5, 10, 19, 53, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value };
     SQLiteConvert._dbtypetonumericprecision = value;
     object[] objArray = 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, DBNull.Value };
     SQLiteConvert._dbtypetonumericscale = objArray;
     Type[] typeArray1 = 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) };
     SQLiteConvert._dbtypeToType = typeArray1;
     TypeAffinity[] typeAffinityArray = 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 };
     SQLiteConvert._typecodeAffinities = typeAffinityArray;
     SQLiteConvert._syncRoot           = new object();
     SQLiteConvert._typeNames          = null;
 }
コード例 #4
0
        internal static string GetLastError(SQLiteConnectionHandle hdl, IntPtr db)
        {
            if (hdl == null || db == IntPtr.Zero)
            {
                return("null connection or database handle");
            }
            string str = null;

            try
            {
            }
            finally
            {
                lock (hdl)
                {
                    if (hdl.IsInvalid || hdl.IsClosed)
                    {
                        str = "closed or invalid connection handle";
                    }
                    else
                    {
                        int num = 0;
                        str = SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg_interop(db, ref num), num);
                    }
                }
            }
            GC.KeepAlive(hdl);
            return(str);
        }
コード例 #5
0
        internal static bool ResetConnection(SQLiteConnectionHandle hdl, IntPtr db, bool canThrow)
        {
            SQLiteErrorCode sQLiteErrorCode;

            if (hdl == null || db == IntPtr.Zero)
            {
                return(false);
            }
            bool flag = false;

            try
            {
            }
            finally
            {
                lock (hdl)
                {
                    if (canThrow && hdl.IsInvalid)
                    {
                        throw new InvalidOperationException("The connection handle is invalid.");
                    }
                    if (canThrow && hdl.IsClosed)
                    {
                        throw new InvalidOperationException("The connection handle is closed.");
                    }
                    if (!hdl.IsInvalid && !hdl.IsClosed)
                    {
                        IntPtr zero = IntPtr.Zero;
                        do
                        {
                            zero = UnsafeNativeMethods.sqlite3_next_stmt(db, zero);
                            if (zero == IntPtr.Zero)
                            {
                                continue;
                            }
                            sQLiteErrorCode = UnsafeNativeMethods.sqlite3_reset_interop(zero);
                        }while (zero != IntPtr.Zero);
                        if (!SQLiteBase.IsAutocommit(hdl, db))
                        {
                            sQLiteErrorCode = UnsafeNativeMethods.sqlite3_exec(db, SQLiteConvert.ToUTF8("ROLLBACK"), IntPtr.Zero, IntPtr.Zero, ref zero);
                            if (sQLiteErrorCode == SQLiteErrorCode.Ok)
                            {
                                flag = true;
                            }
                            else if (canThrow)
                            {
                                throw new SQLiteException(sQLiteErrorCode, SQLiteBase.GetLastError(hdl, db));
                            }
                        }
                        else
                        {
                            flag = true;
                        }
                    }
                }
            }
            GC.KeepAlive(hdl);
            return(flag);
        }
コード例 #6
0
 internal static Type SQLiteTypeToType(SQLiteType t)
 {
     if (t.Type != DbType.Object)
     {
         return(SQLiteConvert.DbTypeToType(t.Type));
     }
     return(SQLiteConvert._affinitytotype[(int)t.Affinity]);
 }
コード例 #7
0
 public static bool ToBoolean(object source)
 {
     if (source is bool)
     {
         return((bool)source);
     }
     return(SQLiteConvert.ToBoolean(SQLiteConvert.ToStringWithProvider(source, CultureInfo.InvariantCulture)));
 }
コード例 #8
0
        public static DateTime ToDateTime(double julianDay, DateTimeKind kind)
        {
            long     jd        = SQLiteConvert.DoubleToJd(julianDay);
            DateTime dateTime  = SQLiteConvert.computeYMD(jd, null);
            DateTime dateTime1 = SQLiteConvert.computeHMS(jd, null);

            return(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime1.Hour, dateTime1.Minute, dateTime1.Second, dateTime1.Millisecond, kind));
        }
コード例 #9
0
        public static string ToString(DateTime dateValue, SQLiteDateFormats format, DateTimeKind kind, string formatString)
        {
            DateTime dateTime;

            switch (format)
            {
            case SQLiteDateFormats.Ticks:
            {
                return(dateValue.Ticks.ToString(CultureInfo.InvariantCulture));
            }

            case SQLiteDateFormats.ISO8601:
            {
                if (dateValue.Kind != DateTimeKind.Unspecified)
                {
                    return(dateValue.ToString(SQLiteConvert.GetDateTimeKindFormat(dateValue.Kind, formatString), CultureInfo.InvariantCulture));
                }
                dateTime = DateTime.SpecifyKind(dateValue, kind);
                return(dateTime.ToString(SQLiteConvert.GetDateTimeKindFormat(kind, formatString), CultureInfo.InvariantCulture));
            }

            case SQLiteDateFormats.JulianDay:
            {
                return(SQLiteConvert.ToJulianDay(dateValue).ToString(CultureInfo.InvariantCulture));
            }

            case SQLiteDateFormats.UnixEpoch:
            {
                TimeSpan timeSpan = dateValue.Subtract(SQLiteConvert.UnixEpoch);
                return((timeSpan.Ticks / (long)10000000).ToString());
            }

            case SQLiteDateFormats.InvariantCulture:
            {
                return(dateValue.ToString((formatString != null ? formatString : "yyyy-MM-ddTHH:mm:ss.fffffffK"), CultureInfo.InvariantCulture));
            }

            case SQLiteDateFormats.CurrentCulture:
            {
                return(dateValue.ToString((formatString != null ? formatString : "yyyy-MM-ddTHH:mm:ss.fffffffK"), CultureInfo.CurrentCulture));
            }

            default:
            {
                if (dateValue.Kind != DateTimeKind.Unspecified)
                {
                    return(dateValue.ToString(SQLiteConvert.GetDateTimeKindFormat(dateValue.Kind, formatString), CultureInfo.InvariantCulture));
                }
                dateTime = DateTime.SpecifyKind(dateValue, kind);
                return(dateTime.ToString(SQLiteConvert.GetDateTimeKindFormat(kind, formatString), CultureInfo.InvariantCulture));
            }
            }
        }
コード例 #10
0
        internal static string DbTypeToTypeName(SQLiteConnection connection, DbType dbType, SQLiteConnectionFlags flags)
        {
            SQLiteDbTypeMapping sQLiteDbTypeMapping;
            SQLiteDbTypeMapping sQLiteDbTypeMapping1;
            string str;
            string defaultTypeName = null;

            if (connection != null)
            {
                flags |= connection.Flags;
                if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes)
                {
                    SQLiteDbTypeMap sQLiteDbTypeMap = connection._typeNames;
                    if (sQLiteDbTypeMap != null && sQLiteDbTypeMap.TryGetValue(dbType, out sQLiteDbTypeMapping))
                    {
                        return(sQLiteDbTypeMapping.typeName);
                    }
                }
                defaultTypeName = connection.DefaultTypeName;
            }
            if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
            {
                if (defaultTypeName != null)
                {
                    return(defaultTypeName);
                }
                defaultTypeName = SQLiteConvert.GetDefaultTypeName(connection);
                SQLiteConvert.DefaultTypeNameWarning(dbType, flags, defaultTypeName);
                return(defaultTypeName);
            }
            lock (SQLiteConvert._syncRoot)
            {
                if (SQLiteConvert._typeNames == null)
                {
                    SQLiteConvert._typeNames = SQLiteConvert.GetSQLiteDbTypeMap();
                }
                if (!SQLiteConvert._typeNames.TryGetValue(dbType, out sQLiteDbTypeMapping1))
                {
                    if (defaultTypeName != null)
                    {
                        return(defaultTypeName);
                    }
                    defaultTypeName = SQLiteConvert.GetDefaultTypeName(connection);
                    SQLiteConvert.DefaultTypeNameWarning(dbType, flags, defaultTypeName);
                    return(defaultTypeName);
                }
                else
                {
                    str = sQLiteDbTypeMapping1.typeName;
                }
            }
            return(str);
        }
コード例 #11
0
 internal override DateTime GetDateTime(SQLiteStatement stmt, int index)
 {
     if (this._datetimeFormat == SQLiteDateFormats.Ticks)
     {
         return(SQLiteConvert.TicksToDateTime(this.GetInt64(stmt, index), this._datetimeKind));
     }
     if (this._datetimeFormat == SQLiteDateFormats.JulianDay)
     {
         return(SQLiteConvert.ToDateTime(this.GetDouble(stmt, index), this._datetimeKind));
     }
     if (this._datetimeFormat != SQLiteDateFormats.UnixEpoch)
     {
         return(base.ToDateTime(this.GetText(stmt, index)));
     }
     return(SQLiteConvert.UnixEpochToDateTime(this.GetInt64(stmt, index), this._datetimeKind));
 }
コード例 #12
0
        private static DbType GetDefaultDbType(SQLiteConnection connection)
        {
            DbType dbType;

            if (((connection != null ? connection.Flags : SQLiteConnectionFlags.None) & SQLiteConnectionFlags.NoConvertSettings) == SQLiteConnectionFlags.NoConvertSettings)
            {
                return(DbType.Object);
            }
            bool   flag         = false;
            string str          = "Use_SQLiteConvert_DefaultDbType";
            object settingValue = null;
            string str1         = null;

            if (connection == null || !connection.TryGetCachedSetting(str, str1, out settingValue))
            {
                settingValue = UnsafeNativeMethods.GetSettingValue(str, str1);
                if (settingValue == null)
                {
                    settingValue = DbType.Object;
                }
            }
            else
            {
                flag = true;
            }
            try
            {
                if (settingValue as DbType? == DbType.AnsiString)
                {
                    settingValue = SQLiteConnection.TryParseEnum(typeof(DbType), SQLiteConvert.SettingValueToString(settingValue), true);
                    if (settingValue as DbType? == DbType.AnsiString)
                    {
                        settingValue = DbType.Object;
                    }
                }
                dbType = (DbType)settingValue;
            }
            finally
            {
                if (!flag && connection != null)
                {
                    connection.SetCachedSetting(str, settingValue);
                }
            }
            return(dbType);
        }
コード例 #13
0
        private void InvokeBindValueCallback(int index, SQLiteParameter parameter, out bool complete)
        {
            SQLiteTypeCallbacks sQLiteTypeCallback;

            complete = false;
            SQLiteConnectionFlags sQLiteConnectionFlag = this._flags;
            SQLiteStatement       sQLiteStatement      = this;

            sQLiteStatement._flags = sQLiteStatement._flags & (SQLiteConnectionFlags.LogPrepare | SQLiteConnectionFlags.LogPreBind | SQLiteConnectionFlags.LogBind | SQLiteConnectionFlags.LogCallbackException | SQLiteConnectionFlags.LogBackup | SQLiteConnectionFlags.NoExtensionFunctions | SQLiteConnectionFlags.BindUInt32AsInt64 | SQLiteConnectionFlags.BindAllAsText | SQLiteConnectionFlags.GetAllAsText | SQLiteConnectionFlags.NoLoadExtension | SQLiteConnectionFlags.NoCreateModule | SQLiteConnectionFlags.NoBindFunctions | SQLiteConnectionFlags.NoLogModule | SQLiteConnectionFlags.LogModuleError | SQLiteConnectionFlags.LogModuleException | SQLiteConnectionFlags.TraceWarning | SQLiteConnectionFlags.ConvertInvariantText | SQLiteConnectionFlags.BindInvariantText | SQLiteConnectionFlags.NoConnectionPool | SQLiteConnectionFlags.UseConnectionPool | SQLiteConnectionFlags.UseConnectionTypes | SQLiteConnectionFlags.NoGlobalTypes | SQLiteConnectionFlags.StickyHasRows | SQLiteConnectionFlags.StrictEnlistment | SQLiteConnectionFlags.MapIsolationLevels | SQLiteConnectionFlags.DetectTextAffinity | SQLiteConnectionFlags.DetectStringType | SQLiteConnectionFlags.NoConvertSettings | SQLiteConnectionFlags.BindDateTimeWithKind | SQLiteConnectionFlags.RollbackOnException | SQLiteConnectionFlags.DenyOnException | SQLiteConnectionFlags.InterruptOnException | SQLiteConnectionFlags.UnbindFunctionsOnClose | SQLiteConnectionFlags.NoVerifyTextAffinity | SQLiteConnectionFlags.UseConnectionReadValueCallbacks | SQLiteConnectionFlags.UseParameterNameForTypeName | SQLiteConnectionFlags.UseParameterDbTypeForTypeName | SQLiteConnectionFlags.NoVerifyTypeAffinity | SQLiteConnectionFlags.AllowNestedTransactions | SQLiteConnectionFlags.BindDecimalAsText | SQLiteConnectionFlags.GetDecimalAsText | SQLiteConnectionFlags.BindInvariantDecimal | SQLiteConnectionFlags.GetInvariantDecimal | SQLiteConnectionFlags.BindAndGetAllAsText | SQLiteConnectionFlags.ConvertAndBindInvariantText | SQLiteConnectionFlags.BindAndGetAllAsInvariantText | SQLiteConnectionFlags.ConvertAndBindAndGetAllAsInvariantText | SQLiteConnectionFlags.UseParameterAnythingForTypeName | SQLiteConnectionFlags.LogAll | SQLiteConnectionFlags.LogDefault | SQLiteConnectionFlags.Default | SQLiteConnectionFlags.DefaultAndLogAll);
            try
            {
                if (parameter != null)
                {
                    SQLiteConnection connection = SQLiteStatement.GetConnection(this);
                    if (connection != null)
                    {
                        string typeName = parameter.TypeName;
                        if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterNameForTypeName) == SQLiteConnectionFlags.UseParameterNameForTypeName)
                        {
                            typeName = parameter.ParameterName;
                        }
                        if (typeName == null && (this._flags & SQLiteConnectionFlags.UseParameterDbTypeForTypeName) == SQLiteConnectionFlags.UseParameterDbTypeForTypeName)
                        {
                            typeName = SQLiteConvert.DbTypeToTypeName(connection, parameter.DbType, this._flags);
                        }
                        if (typeName != null)
                        {
                            if (connection.TryGetTypeCallbacks(typeName, out sQLiteTypeCallback) && sQLiteTypeCallback != null)
                            {
                                SQLiteBindValueCallback bindValueCallback = sQLiteTypeCallback.BindValueCallback;
                                if (bindValueCallback != null)
                                {
                                    object bindValueUserData = sQLiteTypeCallback.BindValueUserData;
                                    bindValueCallback(this._sql, this._command, sQLiteConnectionFlag, parameter, typeName, index, bindValueUserData, out complete);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                this._flags |= SQLiteConnectionFlags.UseConnectionBindValueCallbacks;
            }
        }
コード例 #14
0
 internal static bool LooksLikeDateTime(SQLiteConvert convert, string text)
 {
     if (convert == null)
     {
         return(false);
     }
     try
     {
         if (string.Equals(convert.ToString(convert.ToDateTime(text)), text, StringComparison.Ordinal))
         {
             return(true);
         }
     }
     catch
     {
     }
     return(false);
 }
コード例 #15
0
        private static DateTime computeHMS(long jd, DateTime?badValue)
        {
            DateTime dateTime;

            if (!SQLiteConvert.isValidJd(jd))
            {
                if (!badValue.HasValue)
                {
                    throw new ArgumentException("Not a supported Julian Day value.");
                }
                return(badValue.Value);
            }
            int     num  = (int)((jd + (long)43200000) % (long)86400000);
            decimal num1 = num / new decimal(10000, 0, 0, false, 1);

            num = (int)num1;
            int num2 = (int)((num1 - num) * new decimal(10000, 0, 0, false, 1));

            num1 -= num;
            int num3 = num / 3600;

            num = num - num3 * 3600;
            int num4 = num / 60;

            num1 = num1 + (num - num4 * 60);
            int num5 = (int)num1;

            try
            {
                DateTime minValue = DateTime.MinValue;
                dateTime = new DateTime(minValue.Year, minValue.Month, minValue.Day, num3, num4, num5, num2);
            }
            catch
            {
                if (!badValue.HasValue)
                {
                    throw;
                }
                dateTime = badValue.Value;
            }
            return(dateTime);
        }
コード例 #16
0
        private static DateTime computeYMD(long jd, DateTime?badValue)
        {
            DateTime dateTime;

            if (!SQLiteConvert.isValidJd(jd))
            {
                if (!badValue.HasValue)
                {
                    throw new ArgumentException("Not a supported Julian Day value.");
                }
                return(badValue.Value);
            }
            int num  = (int)((jd + (long)43200000) / (long)86400000);
            int num1 = (int)(((double)num - 1867216.25) / 36524.25);

            num1 = num + 1 + num1 - num1 / 4;
            int num2 = num1 + 1524;
            int num3 = (int)(((double)num2 - 122.1) / 365.25);
            int num4 = 36525 * num3 / 100;
            int num5 = (int)((double)(num2 - num4) / 30.6001);
            int num6 = (int)(30.6001 * (double)num5);
            int num7 = num2 - num4 - num6;
            int num8 = (num5 < 14 ? num5 - 1 : num5 - 13);
            int num9 = (num8 > 2 ? num3 - 4716 : num3 - 4715);

            try
            {
                dateTime = new DateTime(num9, num8, num7);
            }
            catch
            {
                if (!badValue.HasValue)
                {
                    throw;
                }
                dateTime = badValue.Value;
            }
            return(dateTime);
        }
コード例 #17
0
        public static DateTime ToDateTime(string dateText, SQLiteDateFormats format, DateTimeKind kind, string formatString)
        {
            string str;

            string[]           strArrays;
            DateTimeFormatInfo invariantInfo;
            DateTimeStyles     dateTimeStyle;
            string             str1;
            string             str2;
            DateTimeFormatInfo dateTimeFormatInfo;
            DateTimeStyles     dateTimeStyle1;

            switch (format)
            {
            case SQLiteDateFormats.Ticks:
            {
                return(SQLiteConvert.TicksToDateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture), kind));
            }

            case SQLiteDateFormats.ISO8601:
            {
                if (formatString != null)
                {
                    str1 = dateText;
                    str2 = formatString;
                    dateTimeFormatInfo = DateTimeFormatInfo.InvariantInfo;
                    dateTimeStyle1     = (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None);
                    return(DateTime.SpecifyKind(DateTime.ParseExact(str1, str2, dateTimeFormatInfo, dateTimeStyle1), kind));
                }
                str           = dateText;
                strArrays     = SQLiteConvert._datetimeFormats;
                invariantInfo = DateTimeFormatInfo.InvariantInfo;
                dateTimeStyle = (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None);
                return(DateTime.SpecifyKind(DateTime.ParseExact(str, strArrays, invariantInfo, dateTimeStyle), kind));
            }

            case SQLiteDateFormats.JulianDay:
            {
                return(SQLiteConvert.ToDateTime(Convert.ToDouble(dateText, CultureInfo.InvariantCulture), kind));
            }

            case SQLiteDateFormats.UnixEpoch:
            {
                return(SQLiteConvert.UnixEpochToDateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture), kind));
            }

            case SQLiteDateFormats.InvariantCulture:
            {
                if (formatString == null)
                {
                    return(DateTime.SpecifyKind(DateTime.Parse(dateText, DateTimeFormatInfo.InvariantInfo, (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None)), kind));
                }
                return(DateTime.SpecifyKind(DateTime.ParseExact(dateText, formatString, DateTimeFormatInfo.InvariantInfo, (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None)), kind));
            }

            case SQLiteDateFormats.CurrentCulture:
            {
                if (formatString == null)
                {
                    return(DateTime.SpecifyKind(DateTime.Parse(dateText, DateTimeFormatInfo.CurrentInfo, (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None)), kind));
                }
                return(DateTime.SpecifyKind(DateTime.ParseExact(dateText, formatString, DateTimeFormatInfo.CurrentInfo, (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None)), kind));
            }

            default:
            {
                if (formatString != null)
                {
                    str1 = dateText;
                    str2 = formatString;
                    dateTimeFormatInfo = DateTimeFormatInfo.InvariantInfo;
                    dateTimeStyle1     = (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None);
                    return(DateTime.SpecifyKind(DateTime.ParseExact(str1, str2, dateTimeFormatInfo, dateTimeStyle1), kind));
                }
                str           = dateText;
                strArrays     = SQLiteConvert._datetimeFormats;
                invariantInfo = DateTimeFormatInfo.InvariantInfo;
                dateTimeStyle = (kind == DateTimeKind.Utc ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.None);
                return(DateTime.SpecifyKind(DateTime.ParseExact(str, strArrays, invariantInfo, dateTimeStyle), kind));
            }
            }
        }
コード例 #18
0
 public DateTime ToDateTime(string dateText)
 {
     return(SQLiteConvert.ToDateTime(dateText, this._datetimeFormat, this._datetimeKind, this._datetimeFormatString));
 }
コード例 #19
0
 public byte[] ToUTF8(DateTime dateTimeValue)
 {
     return(SQLiteConvert.ToUTF8(this.ToString(dateTimeValue)));
 }
コード例 #20
0
 public string ToString(DateTime dateValue)
 {
     return(SQLiteConvert.ToString(dateValue, this._datetimeFormat, this._datetimeKind, this._datetimeFormatString));
 }
コード例 #21
0
 public static double ToJulianDay(DateTime value)
 {
     return(SQLiteConvert.JdToDouble(SQLiteConvert.computeJD(value)));
 }
コード例 #22
0
        private static void LogCallback(IntPtr pUserData, int errorCode, IntPtr pMessage)
        {
            bool flag;
            SQLiteLogEventHandler sQLiteLogEventHandler;

            lock (SQLiteLog.syncRoot)
            {
                flag = SQLiteLog._enabled;
                if (SQLiteLog._handlers == null)
                {
                    sQLiteLogEventHandler = null;
                }
                else
                {
                    sQLiteLogEventHandler = SQLiteLog._handlers.Clone() as SQLiteLogEventHandler;
                }
            }
            if (flag && sQLiteLogEventHandler != null)
            {
                sQLiteLogEventHandler(null, new LogEventArgs(pUserData, (object)errorCode, SQLiteConvert.UTF8ToString(pMessage, -1), null));
            }
        }
コード例 #23
0
        internal static DbType TypeNameToDbType(SQLiteConnection connection, string typeName, SQLiteConnectionFlags flags)
        {
            SQLiteDbTypeMapping sQLiteDbTypeMapping;
            SQLiteDbTypeMapping sQLiteDbTypeMapping1;
            DbType dbType;
            DbType?defaultDbType = null;

            if (connection != null)
            {
                flags |= connection.Flags;
                if ((flags & SQLiteConnectionFlags.UseConnectionTypes) == SQLiteConnectionFlags.UseConnectionTypes)
                {
                    SQLiteDbTypeMap sQLiteDbTypeMap = connection._typeNames;
                    if (sQLiteDbTypeMap != null && typeName != null)
                    {
                        if (sQLiteDbTypeMap.TryGetValue(typeName, out sQLiteDbTypeMapping))
                        {
                            return(sQLiteDbTypeMapping.dataType);
                        }
                        int num = typeName.IndexOf('(');
                        if (num > 0 && sQLiteDbTypeMap.TryGetValue(typeName.Substring(0, num).TrimEnd(new char[0]), out sQLiteDbTypeMapping))
                        {
                            return(sQLiteDbTypeMapping.dataType);
                        }
                    }
                }
                defaultDbType = connection.DefaultDbType;
            }
            if ((flags & SQLiteConnectionFlags.NoGlobalTypes) == SQLiteConnectionFlags.NoGlobalTypes)
            {
                if (defaultDbType.HasValue)
                {
                    return(defaultDbType.Value);
                }
                defaultDbType = new DbType?(SQLiteConvert.GetDefaultDbType(connection));
                SQLiteConvert.DefaultDbTypeWarning(typeName, flags, defaultDbType);
                return(defaultDbType.Value);
            }
            lock (SQLiteConvert._syncRoot)
            {
                if (SQLiteConvert._typeNames == null)
                {
                    SQLiteConvert._typeNames = SQLiteConvert.GetSQLiteDbTypeMap();
                }
                if (typeName != null)
                {
                    if (!SQLiteConvert._typeNames.TryGetValue(typeName, out sQLiteDbTypeMapping1))
                    {
                        int num1 = typeName.IndexOf('(');
                        if (num1 > 0 && SQLiteConvert._typeNames.TryGetValue(typeName.Substring(0, num1).TrimEnd(new char[0]), out sQLiteDbTypeMapping1))
                        {
                            dbType = sQLiteDbTypeMapping1.dataType;
                            return(dbType);
                        }
                    }
                    else
                    {
                        dbType = sQLiteDbTypeMapping1.dataType;
                        return(dbType);
                    }
                }
                if (defaultDbType.HasValue)
                {
                    return(defaultDbType.Value);
                }
                defaultDbType = new DbType?(SQLiteConvert.GetDefaultDbType(connection));
                SQLiteConvert.DefaultDbTypeWarning(typeName, flags, defaultDbType);
                return(defaultDbType.Value);
            }
            return(dbType);
        }
コード例 #24
0
 public DateTime ToDateTime(double julianDay)
 {
     return(SQLiteConvert.ToDateTime(julianDay, this._datetimeKind));
 }
コード例 #25
0
        internal SQLiteKeyReader(SQLiteConnection cnn, SQLiteDataReader reader, SQLiteStatement stmt)
        {
            List <string>                       item;
            Dictionary <string, int>            strs       = new Dictionary <string, int>();
            Dictionary <string, List <string> > strs1      = new Dictionary <string, List <string> >();
            List <SQLiteKeyReader.KeyInfo>      keyInfos   = new List <SQLiteKeyReader.KeyInfo>();
            List <SQLiteKeyReader.RowIdInfo>    rowIdInfos = new List <SQLiteKeyReader.RowIdInfo>();

            this._stmt = stmt;
            using (DataTable schema = cnn.GetSchema("Catalogs"))
            {
                foreach (DataRow row in schema.Rows)
                {
                    strs.Add((string)row["CATALOG_NAME"], Convert.ToInt32(row["ID"], CultureInfo.InvariantCulture));
                }
            }
            using (DataTable schemaTable = reader.GetSchemaTable(false, false))
            {
                foreach (DataRow dataRow in schemaTable.Rows)
                {
                    if (dataRow[SchemaTableOptionalColumn.BaseCatalogName] == DBNull.Value)
                    {
                        continue;
                    }
                    string str   = (string)dataRow[SchemaTableOptionalColumn.BaseCatalogName];
                    string item1 = (string)dataRow[SchemaTableColumn.BaseTableName];
                    if (strs1.ContainsKey(str))
                    {
                        item = strs1[str];
                    }
                    else
                    {
                        item = new List <string>();
                        strs1.Add(str, item);
                    }
                    if (item.Contains(item1))
                    {
                        continue;
                    }
                    item.Add(item1);
                }
                foreach (KeyValuePair <string, List <string> > keyValuePair in strs1)
                {
                    for (int i = 0; i < keyValuePair.Value.Count; i++)
                    {
                        string   str1     = keyValuePair.Value[i];
                        DataRow  dataRow1 = null;
                        string[] key      = new string[] { keyValuePair.Key, null, str1 };
                        using (DataTable dataTable = cnn.GetSchema("Indexes", key))
                        {
                            for (int j = 0; j < 2 && dataRow1 == null; j++)
                            {
                                foreach (DataRow row1 in dataTable.Rows)
                                {
                                    if (j != 0 || !(bool)row1["PRIMARY_KEY"])
                                    {
                                        if (j != 1 || !(bool)row1["UNIQUE"])
                                        {
                                            continue;
                                        }
                                        dataRow1 = row1;
                                        break;
                                    }
                                    else
                                    {
                                        dataRow1 = row1;
                                        break;
                                    }
                                }
                            }
                            if (dataRow1 != null)
                            {
                                string[] strArrays = new string[] { keyValuePair.Key, null, str1 };
                                using (DataTable schema1 = cnn.GetSchema("Tables", strArrays))
                                {
                                    int      num            = strs[keyValuePair.Key];
                                    int      num1           = Convert.ToInt32(schema1.Rows[0]["TABLE_ROOTPAGE"], CultureInfo.InvariantCulture);
                                    int      cursorForTable = stmt._sql.GetCursorForTable(stmt, num, num1);
                                    string[] key1           = new string[] { keyValuePair.Key, null, str1, (string)dataRow1["INDEX_NAME"] };
                                    using (DataTable dataTable1 = cnn.GetSchema("IndexColumns", key1))
                                    {
                                        bool flag = (string)dataRow1["INDEX_NAME"] == string.Concat("sqlite_master_PK_", str1);
                                        SQLiteKeyReader.KeyQuery keyQuery = null;
                                        List <string>            strs2    = new List <string>();
                                        for (int k = 0; k < dataTable1.Rows.Count; k++)
                                        {
                                            string stringOrNull = SQLiteConvert.GetStringOrNull(dataTable1.Rows[k]["COLUMN_NAME"]);
                                            bool   flag1        = true;
                                            foreach (DataRow row2 in schemaTable.Rows)
                                            {
                                                if (row2.IsNull(SchemaTableColumn.BaseColumnName) || !((string)row2[SchemaTableColumn.BaseColumnName] == stringOrNull) || !((string)row2[SchemaTableColumn.BaseTableName] == str1) || !((string)row2[SchemaTableOptionalColumn.BaseCatalogName] == keyValuePair.Key))
                                                {
                                                    continue;
                                                }
                                                if (flag)
                                                {
                                                    SQLiteKeyReader.RowIdInfo rowIdInfo = new SQLiteKeyReader.RowIdInfo()
                                                    {
                                                        databaseName = keyValuePair.Key,
                                                        tableName    = str1,
                                                        column       = (int)row2[SchemaTableColumn.ColumnOrdinal]
                                                    };
                                                    rowIdInfos.Add(rowIdInfo);
                                                }
                                                dataTable1.Rows.RemoveAt(k);
                                                k--;
                                                flag1 = false;
                                                break;
                                            }
                                            if (flag1)
                                            {
                                                strs2.Add(stringOrNull);
                                            }
                                        }
                                        if (!flag && strs2.Count > 0)
                                        {
                                            string[] strArrays1 = new string[strs2.Count];
                                            strs2.CopyTo(strArrays1);
                                            keyQuery = new SQLiteKeyReader.KeyQuery(cnn, keyValuePair.Key, str1, strArrays1);
                                        }
                                        for (int l = 0; l < dataTable1.Rows.Count; l++)
                                        {
                                            string stringOrNull1            = SQLiteConvert.GetStringOrNull(dataTable1.Rows[l]["COLUMN_NAME"]);
                                            SQLiteKeyReader.KeyInfo keyInfo = new SQLiteKeyReader.KeyInfo()
                                            {
                                                rootPage     = num1,
                                                cursor       = cursorForTable,
                                                database     = num,
                                                databaseName = keyValuePair.Key,
                                                tableName    = str1,
                                                columnName   = stringOrNull1,
                                                query        = keyQuery,
                                                column       = l
                                            };
                                            keyInfos.Add(keyInfo);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                keyValuePair.Value.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }
            this._keyInfo = new SQLiteKeyReader.KeyInfo[keyInfos.Count];
            keyInfos.CopyTo(this._keyInfo);
            this._rowIdInfo = new SQLiteKeyReader.RowIdInfo[rowIdInfos.Count];
            rowIdInfos.CopyTo(this._rowIdInfo);
        }
コード例 #26
0
        public static SQLiteBlob Create(SQLiteDataReader dataReader, int i, bool readOnly)
        {
            SQLiteConnection connection = SQLiteDataReader.GetConnection(dataReader);

            if (connection == null)
            {
                throw new InvalidOperationException("Connection not available");
            }
            SQLite3 sQLite3 = connection._sql as SQLite3;

            if (sQLite3 == null)
            {
                throw new InvalidOperationException("Connection has no wrapper");
            }
            SQLiteConnectionHandle sQLiteConnectionHandle = sQLite3._sql;

            if (sQLiteConnectionHandle == null)
            {
                throw new InvalidOperationException("Connection has an invalid handle.");
            }
            long?rowId = dataReader.GetRowId(i);

            if (!rowId.HasValue)
            {
                throw new InvalidOperationException("No RowId is available");
            }
            SQLiteBlobHandle sQLiteBlobHandle = null;

            try
            {
            }
            finally
            {
                IntPtr          zero            = IntPtr.Zero;
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3_blob_open(sQLiteConnectionHandle, SQLiteConvert.ToUTF8(dataReader.GetDatabaseName(i)), SQLiteConvert.ToUTF8(dataReader.GetTableName(i)), SQLiteConvert.ToUTF8(dataReader.GetName(i)), rowId.Value, (readOnly ? 0 : 1), ref zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    throw new SQLiteException(sQLiteErrorCode, null);
                }
                sQLiteBlobHandle = new SQLiteBlobHandle(sQLiteConnectionHandle, zero);
            }
            object[] objArray = new object[] { typeof(SQLiteBlob), dataReader, i, readOnly };
            SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, dataReader, sQLiteBlobHandle, null, objArray));
            return(new SQLiteBlob(sQLite3, sQLiteBlobHandle));
        }
コード例 #27
0
 public virtual string ToString(IntPtr nativestring, int nativestringlen)
 {
     return(SQLiteConvert.UTF8ToString(nativestring, nativestringlen));
 }
コード例 #28
0
        private void BindParameter(int index, SQLiteParameter param)
        {
            bool                  flag;
            SQLiteBase            sQLiteBase;
            SQLiteConnectionFlags sQLiteConnectionFlag;
            int    num;
            string str;

            if (param == null)
            {
                throw new SQLiteException("Insufficient parameters supplied to the command");
            }
            if ((this._flags & SQLiteConnectionFlags.UseConnectionBindValueCallbacks) == SQLiteConnectionFlags.UseConnectionBindValueCallbacks)
            {
                this.InvokeBindValueCallback(index, param, out flag);
                if (flag)
                {
                    return;
                }
            }
            object value  = param.Value;
            DbType dbType = param.DbType;

            if (value != null && dbType == DbType.Object)
            {
                dbType = SQLiteConvert.TypeToDbType(value.GetType());
            }
            if (HelperMethods.LogPreBind(this._flags))
            {
                IntPtr      _sqliteStmt    = this._sqlite_stmt;
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { _sqliteStmt, index, dbType, value };
                SQLiteLog.LogMessage(HelperMethods.StringFormat(currentCulture, "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...", objArray));
            }
            if (value == null || Convert.IsDBNull(value))
            {
                this._sql.Bind_Null(this, this._flags, index);
                return;
            }
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;
            bool        flag1            = (this._flags & SQLiteConnectionFlags.BindInvariantText) == SQLiteConnectionFlags.BindInvariantText;
            CultureInfo cultureInfo      = CultureInfo.CurrentCulture;

            if ((this._flags & SQLiteConnectionFlags.ConvertInvariantText) == SQLiteConnectionFlags.ConvertInvariantText)
            {
                cultureInfo = invariantCulture;
            }
            if ((this._flags & SQLiteConnectionFlags.BindAllAsText) == SQLiteConnectionFlags.BindAllAsText)
            {
                if (value is DateTime)
                {
                    this._sql.Bind_DateTime(this, this._flags, index, (DateTime)value);
                    return;
                }
                this._sql.Bind_Text(this, this._flags, index, (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo)));
                return;
            }
            bool flag2 = (this._flags & SQLiteConnectionFlags.BindInvariantDecimal) == SQLiteConnectionFlags.BindInvariantDecimal;

            if ((this._flags & SQLiteConnectionFlags.BindDecimalAsText) == SQLiteConnectionFlags.BindDecimalAsText && value is decimal)
            {
                this._sql.Bind_Text(this, this._flags, index, (flag1 || flag2 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo)));
                return;
            }
            switch (dbType)
            {
            case DbType.Binary:
            {
                this._sql.Bind_Blob(this, this._flags, index, (byte[])value);
                return;
            }

            case DbType.Byte:
            {
                this._sql.Bind_UInt32(this, this._flags, index, Convert.ToByte(value, cultureInfo));
                return;
            }

            case DbType.Boolean:
            {
                this._sql.Bind_Boolean(this, this._flags, index, SQLiteConvert.ToBoolean(value, cultureInfo, true));
                return;
            }

            case DbType.Currency:
            case DbType.Double:
            case DbType.Single:
            {
                this._sql.Bind_Double(this, this._flags, index, Convert.ToDouble(value, cultureInfo));
                return;
            }

            case DbType.Date:
            case DbType.DateTime:
            case DbType.Time:
            {
                this._sql.Bind_DateTime(this, this._flags, index, (value is string?this._sql.ToDateTime((string)value) : Convert.ToDateTime(value, cultureInfo)));
                return;
            }

            case DbType.Decimal:
            {
                this._sql.Bind_Text(this, this._flags, index, (flag1 || flag2 ? SQLiteConvert.ToStringWithProvider(Convert.ToDecimal(value, cultureInfo), invariantCulture) : SQLiteConvert.ToStringWithProvider(Convert.ToDecimal(value, cultureInfo), cultureInfo)));
                return;
            }

            case DbType.Guid:
            {
                if (this._command.Connection._binaryGuid)
                {
                    SQLiteBase            sQLiteBase1           = this._sql;
                    SQLiteConnectionFlags sQLiteConnectionFlag1 = this._flags;
                    Guid guid = (Guid)value;
                    sQLiteBase1.Bind_Blob(this, sQLiteConnectionFlag1, index, guid.ToByteArray());
                    return;
                }
                this._sql.Bind_Text(this, this._flags, index, (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo)));
                return;
            }

            case DbType.Int16:
            {
                this._sql.Bind_Int32(this, this._flags, index, Convert.ToInt16(value, cultureInfo));
                return;
            }

            case DbType.Int32:
            {
                this._sql.Bind_Int32(this, this._flags, index, Convert.ToInt32(value, cultureInfo));
                return;
            }

            case DbType.Int64:
            {
                this._sql.Bind_Int64(this, this._flags, index, Convert.ToInt64(value, cultureInfo));
                return;
            }

            case DbType.Object:
            case DbType.String:
            {
                sQLiteBase           = this._sql;
                sQLiteConnectionFlag = this._flags;
                num = index;
                str = (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo));
                sQLiteBase.Bind_Text(this, sQLiteConnectionFlag, num, str);
                return;
            }

            case DbType.SByte:
            {
                this._sql.Bind_Int32(this, this._flags, index, Convert.ToSByte(value, cultureInfo));
                return;
            }

            case DbType.UInt16:
            {
                this._sql.Bind_UInt32(this, this._flags, index, Convert.ToUInt16(value, cultureInfo));
                return;
            }

            case DbType.UInt32:
            {
                this._sql.Bind_UInt32(this, this._flags, index, Convert.ToUInt32(value, cultureInfo));
                return;
            }

            case DbType.UInt64:
            {
                this._sql.Bind_UInt64(this, this._flags, index, Convert.ToUInt64(value, cultureInfo));
                return;
            }

            default:
            {
                sQLiteBase           = this._sql;
                sQLiteConnectionFlag = this._flags;
                num = index;
                str = (flag1 ? SQLiteConvert.ToStringWithProvider(value, invariantCulture) : SQLiteConvert.ToStringWithProvider(value, cultureInfo));
                sQLiteBase.Bind_Text(this, sQLiteConnectionFlag, num, str);
                return;
            }
            }
        }
コード例 #29
0
        internal static bool ToBoolean(object obj, IFormatProvider provider, bool viaFramework)
        {
            object[]    objArray;
            CultureInfo currentCulture;

            if (obj == null)
            {
                return(false);
            }
            TypeCode typeCode = Type.GetTypeCode(obj.GetType());

            switch (typeCode)
            {
            case TypeCode.Empty:
            case TypeCode.DBNull:
            {
                return(false);
            }

            case TypeCode.Object:
            case TypeCode.DateTime:
            case TypeCode.Object | TypeCode.DateTime:
            {
                currentCulture = CultureInfo.CurrentCulture;
                objArray       = new object[] { typeCode };
                throw new SQLiteException(HelperMethods.StringFormat(currentCulture, "Cannot convert type {0} to boolean", objArray));
            }

            case TypeCode.Boolean:
            {
                return((bool)obj);
            }

            case TypeCode.Char:
            {
                if ((char)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.SByte:
            {
                if ((sbyte)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Byte:
            {
                if ((byte)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Int16:
            {
                if ((short)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.UInt16:
            {
                if ((ushort)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Int32:
            {
                if ((int)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.UInt32:
            {
                if ((uint)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Int64:
            {
                if ((long)obj == (long)0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.UInt64:
            {
                if ((ulong)obj == (long)0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Single:
            {
                if ((float)obj == 0f)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Double:
            {
                if ((double)obj == 0)
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.Decimal:
            {
                if ((decimal)obj == new decimal(0))
                {
                    return(false);
                }
                return(true);
            }

            case TypeCode.String:
            {
                if (viaFramework)
                {
                    return(Convert.ToBoolean(obj, provider));
                }
                return(SQLiteConvert.ToBoolean(SQLiteConvert.ToStringWithProvider(obj, provider)));
            }

            default:
            {
                currentCulture = CultureInfo.CurrentCulture;
                objArray       = new object[] { typeCode };
                throw new SQLiteException(HelperMethods.StringFormat(currentCulture, "Cannot convert type {0} to boolean", objArray));
            }
            }
        }
コード例 #30
0
        internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
        {
            SQLiteErrorCode sQLiteErrorCode;

            if (this._sql != null)
            {
                this.Close(true);
            }
            if (this._sql != null)
            {
                throw new SQLiteException("connection handle is still active");
            }
            this._usePool  = usePool;
            this._fileName = strFilename;
            this._flags    = connectionFlags;
            if (usePool)
            {
                this._sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out this._poolVersion);
                SQLiteConnectionHandle sQLiteConnectionHandle = this._sql;
                object[] objArray = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool, this._poolVersion };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.OpenedFromPool, null, null, null, null, sQLiteConnectionHandle, strFilename, objArray));
            }
            if (this._sql == null)
            {
                try
                {
                }
                finally
                {
                    IntPtr zero = IntPtr.Zero;
                    int    num  = ((connectionFlags & SQLiteConnectionFlags.NoExtensionFunctions) != SQLiteConnectionFlags.NoExtensionFunctions ? 1 : 0);
                    if (vfsName != null || num != 0)
                    {
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16_interop(SQLiteConvert.ToUTF8(strFilename), SQLiteConvert.ToUTF8(vfsName), openFlags, num, ref zero);
                    }
                    else
                    {
                        if ((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create && !File.Exists(strFilename))
                        {
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename);
                        }
                        if (vfsName != null)
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray1      = new object[] { vfsName };
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, HelperMethods.StringFormat(currentCulture, "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", objArray1));
                        }
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16(strFilename, ref zero);
                    }
                    if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                    {
                        throw new SQLiteException(sQLiteErrorCode, null);
                    }
                    this._sql = new SQLiteConnectionHandle(zero, true);
                }
                lock (this._sql)
                {
                }
                SQLiteConnectionHandle sQLiteConnectionHandle1 = this._sql;
                object[] objArray2 = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, null, sQLiteConnectionHandle1, strFilename, objArray2));
            }
            if ((connectionFlags & SQLiteConnectionFlags.NoBindFunctions) != SQLiteConnectionFlags.NoBindFunctions)
            {
                if (this._functions == null)
                {
                    this._functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>();
                }
                foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> value in SQLiteFunction.BindFunctions(this, connectionFlags))
                {
                    this._functions[value.Key] = value.Value;
                }
            }
            this.SetTimeout(0);
            GC.KeepAlive(this._sql);
        }