Example #1
0
        internal SQLite3(SQLiteDateFormats fmt)
            : base(fmt)
        {
#if MONOTOUCH
            gch = GCHandle.Alloc(this);
#endif
        }
Example #2
0
    internal SQLite3(SQLiteDateFormats fmt)
      : base(fmt)
    {
#if MONOTOUCH
      gch = GCHandle.Alloc (this);
#endif
    }
Example #3
0
 private static string GetConnectionString(
     string dataSource,
     bool binaryGuid,
     DateTimeKind dateTimeKind,
     SQLiteDateFormats dateTimeFormat,
     SQLiteJournalModeEnum journalMode,
     SynchronizationModes syncMode,
     int pageSize,
     int cacheSize)
 {
     Ensure.NotNullOrEmptyOrWhiteSpace(dataSource);
     return(new SQLiteConnectionStringBuilder
     {
         DataSource = dataSource,
         FailIfMissing = false,
         Pooling = false,
         BinaryGUID = binaryGuid,
         DateTimeKind = dateTimeKind,
         DateTimeFormat = dateTimeFormat,
         JournalMode = journalMode,
         SyncMode = syncMode,
         UseUTF16Encoding = false,
         ReadOnly = false,
         LegacyFormat = false,
         PageSize = pageSize,
         // reverts back to default on conn.Close has to first be set when Mode is NOT WAL & before any table is created.
         CacheSize = cacheSize // reverts back to default on conn.Close, has to first be set when Mode is NOT WAL
     }.ToString());
 }
Example #4
0
 protected SQLiteFunction(SQLiteDateFormats format, DateTimeKind kind, string formatString, bool utf16) : this()
 {
     if (utf16)
     {
         this._base = new SQLite3_UTF16(format, kind, formatString, IntPtr.Zero, null, false);
         return;
     }
     this._base = new SQLite3(format, kind, formatString, IntPtr.Zero, null, false);
 }
        /// <summary>
        /// Converts a string into a DateTime, using the specified DateTimeFormat and DateTimeKind.
        /// </summary>
        /// <remarks>
        /// Acceptable ISO8601 DateTime formats are:
        /// <list type="bullet">
        /// <item><description>THHmmssK</description></item>
        /// <item><description>THHmmK</description></item>
        /// <item><description>HH:mm:ss.FFFFFFFK</description></item>
        /// <item><description>HH:mm:ssK</description></item>
        /// <item><description>HH:mmK</description></item>
        /// <item><description>yyyy-MM-dd HH:mm:ss.FFFFFFFK</description></item>
        /// <item><description>yyyy-MM-dd HH:mm:ssK</description></item>
        /// <item><description>yyyy-MM-dd HH:mmK</description></item>
        /// <item><description>yyyy-MM-ddTHH:mm:ss.FFFFFFFK</description></item>
        /// <item><description>yyyy-MM-ddTHH:mmK</description></item>
        /// <item><description>yyyy-MM-ddTHH:mm:ssK</description></item>
        /// <item><description>yyyyMMddHHmmssK</description></item>
        /// <item><description>yyyyMMddHHmmK</description></item>
        /// <item><description>yyyyMMddTHHmmssFFFFFFFK</description></item>
        /// <item><description>THHmmss</description></item>
        /// <item><description>THHmm</description></item>
        /// <item><description>HH:mm:ss.FFFFFFF</description></item>
        /// <item><description>HH:mm:ss</description></item>
        /// <item><description>HH:mm</description></item>
        /// <item><description>yyyy-MM-dd HH:mm:ss.FFFFFFF</description></item>
        /// <item><description>yyyy-MM-dd HH:mm:ss</description></item>
        /// <item><description>yyyy-MM-dd HH:mm</description></item>
        /// <item><description>yyyy-MM-ddTHH:mm:ss.FFFFFFF</description></item>
        /// <item><description>yyyy-MM-ddTHH:mm</description></item>
        /// <item><description>yyyy-MM-ddTHH:mm:ss</description></item>
        /// <item><description>yyyyMMddHHmmss</description></item>
        /// <item><description>yyyyMMddHHmm</description></item>
        /// <item><description>yyyyMMddTHHmmssFFFFFFF</description></item>
        /// <item><description>yyyy-MM-dd</description></item>
        /// <item><description>yyyyMMdd</description></item>
        /// <item><description>yy-MM-dd</description></item>
        /// </list>
        /// If the string cannot be matched to one of the above formats, an exception will be thrown.
        /// </remarks>
        /// <param name="dateText">The string containing either a long integer number of 100-nanosecond units since
        /// System.DateTime.MinValue, a Julian day double, an integer number of seconds since the Unix epoch, a
        /// culture-independent formatted date and time string, a formatted date and time string in the current
        /// culture, or an ISO8601-format string.</param>
        /// <param name="format">The SQLiteDateFormats to use.</param>
        /// <param name="kind">The DateTimeKind to use.</param>
        /// <returns>A DateTime value</returns>
        public static DateTime ToDateTime(string dateText, SQLiteDateFormats format, DateTimeKind kind)
        {
            switch (format)
            {
            case SQLiteDateFormats.Ticks:
            {
                return(new DateTime(Convert.ToInt64(
                                        dateText, CultureInfo.InvariantCulture), kind));
            }

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

            case SQLiteDateFormats.UnixEpoch:
            {
                return(DateTime.SpecifyKind(
                           UnixEpoch.AddSeconds(Convert.ToInt32(
                                                    dateText, CultureInfo.InvariantCulture)), kind));
            }

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

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

            default:
            {
                return(DateTime.SpecifyKind(DateTime.ParseExact(
                                                dateText, _datetimeFormats,
                                                DateTimeFormatInfo.InvariantInfo,
                                                kind == DateTimeKind.Utc ?
                                                DateTimeStyles.AdjustToUniversal :
                                                DateTimeStyles.None),
                                            kind));
            }
            }
        }
Example #6
0
 /// <summary>
 /// Constructs the object used to interact with the SQLite core library
 /// using the UTF-8 text encoding.
 /// </summary>
 /// <param name="fmt">
 /// The DateTime format to be used when converting string values to a
 /// DateTime and binding DateTime parameters.
 /// </param>
 /// <param name="kind">
 /// The <see cref="DateTimeKind" /> to be used when creating DateTime
 /// values.
 /// </param>
 /// <param name="fmtString">
 /// The format string to be used when parsing and formatting DateTime
 /// values.
 /// </param>
 /// <param name="db">
 /// The native handle to be associated with the database connection.
 /// </param>
 /// <param name="fileName">
 /// The fully qualified file name associated with <paramref name="db" />.
 /// </param>
 /// <param name="ownHandle">
 /// Non-zero if the newly created object instance will need to dispose
 /// of <paramref name="db" /> when it is no longer needed.
 /// </param>
 internal SQLite3_UTF16(
     SQLiteDateFormats fmt,
     DateTimeKind kind,
     string fmtString,
     IntPtr db,
     string fileName,
     bool ownHandle
     )
     : base(fmt, kind, fmtString, db, fileName, ownHandle)
 {
 }
Example #7
0
 /// <summary>
 /// Constructs the object used to interact with the SQLite core library
 /// using the UTF-8 text encoding.
 /// </summary>
 /// <param name="fmt">
 /// The DateTime format to be used when converting string values to a
 /// DateTime and binding DateTime parameters.
 /// </param>
 /// <param name="kind">
 /// The <see cref="DateTimeKind" /> to be used when creating DateTime
 /// values.
 /// </param>
 /// <param name="fmtString">
 /// The format string to be used when parsing and formatting DateTime
 /// values.
 /// </param>
 /// <param name="db">
 /// The native handle to be associated with the database connection.
 /// </param>
 /// <param name="fileName">
 /// The fully qualified file name associated with <paramref name="db" />.
 /// </param>
 /// <param name="ownHandle">
 /// Non-zero if the newly created object instance will need to dispose
 /// of <paramref name="db" /> when it is no longer needed.
 /// </param>
 internal SQLite3_UTF16(
     SQLiteDateFormats fmt,
     DateTimeKind kind,
     string fmtString,
     IntPtr db,
     string fileName,
     bool ownHandle
     )
     : base(fmt, kind, fmtString, db, fileName, ownHandle)
 {
 }
        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));
            }
            }
        }
 public static VirtualRadar.Interface.SQLite.SQLiteDateFormats ToSQLiteDateFormats(SQLiteDateFormats value)
 {
     switch(value) {
         case SQLiteDateFormats.Ticks:               return VirtualRadar.Interface.SQLite.SQLiteDateFormats.Ticks;
         case SQLiteDateFormats.ISO8601:             return VirtualRadar.Interface.SQLite.SQLiteDateFormats.ISO8601;
         case SQLiteDateFormats.JulianDay:           return VirtualRadar.Interface.SQLite.SQLiteDateFormats.JulianDay;
         #if DOTNET_BUILD
         case SQLiteDateFormats.UnixEpoch:           return VirtualRadar.Interface.SQLite.SQLiteDateFormats.UnixEpoch;
         case SQLiteDateFormats.InvariantCulture:    return VirtualRadar.Interface.SQLite.SQLiteDateFormats.InvariantCulture;
         case SQLiteDateFormats.CurrentCulture:      return VirtualRadar.Interface.SQLite.SQLiteDateFormats.CurrentCulture;
         #endif
         default:                                    throw new NotImplementedException();
     }
 }
Example #10
0
 /// <summary>
 /// Returns a file-based <c>SQLite</c> connection-string.
 /// </summary>
 public static string GetFileConnectionString(
     FileInfo file,
     bool binaryGuid                   = false,
     DateTimeKind dateTimeKind         = DateTimeKind.Utc,
     SQLiteDateFormats dateTimeFormat  = SQLiteDateFormats.UnixEpoch,
     SQLiteJournalModeEnum journalMode = SQLiteJournalModeEnum.Wal,
     SynchronizationModes syncMode     = SynchronizationModes.Off,
     int pageSize  = 4096,
     int cacheSize = -2000)
 {
     Ensure.NotNull(file, nameof(file));
     return(GetConnectionString(
                file.FullName,
                binaryGuid,
                dateTimeKind,
                dateTimeFormat,
                journalMode,
                syncMode,
                pageSize,
                cacheSize));
 }
Example #11
0
    ///////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Constructs the object used to interact with the SQLite core library
    /// using the UTF-8 text encoding.
    /// </summary>
    /// <param name="fmt">
    /// The DateTime format to be used when converting string values to a
    /// DateTime and binding DateTime parameters.
    /// </param>
    /// <param name="kind">
    /// The <see cref="DateTimeKind" /> to be used when creating DateTime
    /// values.
    /// </param>
    /// <param name="fmtString">
    /// The format string to be used when parsing and formatting DateTime
    /// values.
    /// </param>
    /// <param name="db">
    /// The native handle to be associated with the database connection.
    /// </param>
    /// <param name="fileName">
    /// The fully qualified file name associated with <paramref name="db "/>.
    /// </param>
    /// <param name="ownHandle">
    /// Non-zero if the newly created object instance will need to dispose
    /// of <paramref name="db" /> when it is no longer needed.
    /// </param>
    internal SQLite3(
        SQLiteDateFormats fmt,
        DateTimeKind kind,
        string fmtString,
        IntPtr db,
        string fileName,
        bool ownHandle
        )
      : base(fmt, kind, fmtString)
    {
        if (db != IntPtr.Zero)
        {
            _sql = new SQLiteConnectionHandle(db, ownHandle);
            _fileName = fileName;

            SQLiteConnection.OnChanged(null, new ConnectionEventArgs(
                SQLiteConnectionEventType.NewCriticalHandle, null,
                null, null, null, _sql, fileName, new object[] {
                typeof(SQLite3), fmt, kind, fmtString, db, fileName,
                ownHandle }));
        }
    }
    /////////////////////////////////////////////////////////////////////////

    internal SQLiteBase(SQLiteDateFormats fmt, DateTimeKind kind, string fmtString)
      : base(fmt, kind, fmtString) { }
Example #13
0
        /////////////////////////////////////////////////////////////////////////

        internal SQLiteBase(SQLiteDateFormats fmt, DateTimeKind kind, string fmtString)
            : base(fmt, kind, fmtString)
        {
        }
 /// <summary>
 /// Constructs the provider manifest.
 /// </summary>
 /// <remarks>
 /// We pass the token as a DateTimeFormat enum text, because all the datetime functions
 /// are vastly different depending on how the user is opening the connection
 /// </remarks>
 /// <param name="manifestToken">A token used to infer the capabilities of the store</param>
 public SQLiteProviderManifest(string manifestToken)
   : base(SQLiteProviderManifest.GetProviderManifest())
 {
   _dateFormat = (SQLiteDateFormats)Enum.Parse(typeof(SQLiteDateFormats), manifestToken, true);
 }
Example #15
0
 internal SQLite3(SQLiteDateFormats fmt)
     : base(fmt)
 {
 }
    /// <summary>
    /// Attempts to set the provider manifest options from the specified
    /// connection string parameters.  An exception may be thrown if one
    /// or more of the connection string parameter values do not conform
    /// to the expected type.
    /// </summary>
    /// <param name="opts">
    /// The dictionary containing the connection string parameters.
    /// </param>
    internal void SetFromOptions(
        SortedList<string, string> opts
        )
    {
        _dateTimeFormat = SQLiteConnection.DefaultDateTimeFormat;
        _dateTimeKind = SQLiteConnection.DefaultDateTimeKind;
        _dateTimeFormatString = SQLiteConnection.DefaultDateTimeFormatString;
        _binaryGuid = /* SQLiteConnection.DefaultBinaryGUID; */ false; /* COMPAT: Legacy. */

        if (opts == null)
            return;

#if !PLATFORM_COMPACTFRAMEWORK
        string[] names = Enum.GetNames(typeof(SQLiteDateFormats));
#else
        string[] names = {
            SQLiteDateFormats.Ticks.ToString(),
            SQLiteDateFormats.ISO8601.ToString(),
            SQLiteDateFormats.JulianDay.ToString(),
            SQLiteDateFormats.UnixEpoch.ToString(),
            SQLiteDateFormats.InvariantCulture.ToString(),
            SQLiteDateFormats.CurrentCulture.ToString(),
            "Default"
        };
#endif

        foreach (string name in names)
        {
            if (String.IsNullOrEmpty(name))
                continue;

            object value = SQLiteConnection.FindKey(opts, name, null);

            if (value == null)
                continue;

            _dateTimeFormat = (SQLiteDateFormats)Enum.Parse(
                typeof(SQLiteDateFormats), name, true);
        }

        object enumValue;

        enumValue = SQLiteConnection.TryParseEnum(
            typeof(SQLiteDateFormats), SQLiteConnection.FindKey(
            opts, "DateTimeFormat", null), true);

        if (enumValue is SQLiteDateFormats)
            _dateTimeFormat = (SQLiteDateFormats)enumValue;

        enumValue = SQLiteConnection.TryParseEnum(
            typeof(DateTimeKind), SQLiteConnection.FindKey(
            opts, "DateTimeKind", null), true);

        if (enumValue is DateTimeKind)
            _dateTimeKind = (DateTimeKind)enumValue;

        string stringValue = SQLiteConnection.FindKey(
            opts, "DateTimeFormatString", null);

        if (stringValue != null)
            _dateTimeFormatString = stringValue;

        stringValue = SQLiteConnection.FindKey(
            opts, "BinaryGUID", null);

        if (stringValue != null)
            _binaryGuid = SQLiteConvert.ToBoolean(stringValue);
    }
Example #17
0
 internal SQLite3_UTF16(SQLiteDateFormats fmt, DateTimeKind kind)
     : base(fmt, kind)
 {
 }
Example #18
0
 /// <summary>
 /// Initializes the conversion class
 /// </summary>
 /// <param name="fmt">The default date/time format to use for this instance</param>
 internal SharpHsqlConvert(SQLiteDateFormats fmt)
 {
     _datetimeFormat = fmt;
 }
 internal SQLiteConvert(SQLiteDateFormats fmt, DateTimeKind kind, string fmtString)
 {
     this._datetimeFormat       = fmt;
     this._datetimeKind         = kind;
     this._datetimeFormatString = fmtString;
 }
        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));
            }
            }
        }
Example #21
0
 internal SQLiteBase(SQLiteDateFormats fmt, DateTimeKind kind)
   : base(fmt, kind) { }
 /// <summary>
 /// Constructs the provider manifest.
 /// </summary>
 /// <remarks>
 /// We pass the token as a DateTimeFormat enum text, because all the datetime functions
 /// are vastly different depending on how the user is opening the connection
 /// </remarks>
 /// <param name="manifestToken">A token used to infer the capabilities of the store</param>
 public SQLiteProviderManifest(string manifestToken)
     : base(SQLiteProviderManifest.GetProviderManifest())
 {
     _dateFormat = (SQLiteDateFormats)Enum.Parse(typeof(SQLiteDateFormats), manifestToken, true);
 }
Example #23
0
 /// <summary>
 /// Initializes the conversion class
 /// </summary>
 /// <param name="fmt">The default date/time format to use for this instance</param>
 internal SharpHsqlConvert(SQLiteDateFormats fmt)
 {
     _datetimeFormat = fmt;
 }
 internal SQLite3_UTF16(SQLiteDateFormats fmt)
     : base(fmt)
 {
 }
 /// <summary>
 /// Initializes the conversion class
 /// </summary>
 /// <param name="fmt">The default date/time format to use for this instance</param>
 /// <param name="kind">The DateTimeKind to use.</param>
 internal SQLiteConvert(SQLiteDateFormats fmt, DateTimeKind kind)
 {
     _datetimeFormat = fmt;
     _datetimeKind   = kind;
 }
 /// <summary>
 /// Initializes the conversion class
 /// </summary>
 /// <param name="fmt">The default date/time format to use for this instance</param>
 internal SQLiteConvert(SQLiteDateFormats fmt)
 {
     _datetimeFormat = fmt;
 }
Example #27
0
        public static VirtualRadar.Interface.SQLite.SQLiteDateFormats ToSQLiteDateFormats(SQLiteDateFormats value)
        {
            switch (value)
            {
            case SQLiteDateFormats.Ticks:               return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.Ticks);

            case SQLiteDateFormats.ISO8601:             return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.ISO8601);

            case SQLiteDateFormats.JulianDay:           return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.JulianDay);

                #if DOTNET_BUILD
            case SQLiteDateFormats.UnixEpoch:           return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.UnixEpoch);

            case SQLiteDateFormats.InvariantCulture:    return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.InvariantCulture);

            case SQLiteDateFormats.CurrentCulture:      return(VirtualRadar.Interface.SQLite.SQLiteDateFormats.CurrentCulture);
                #endif
            default:                                    throw new NotImplementedException();
            }
        }
 /// <summary>
 /// Constructs an instance of this class using the specified data-type
 /// conversion parameters.
 /// </summary>
 /// <param name="format">
 /// The DateTime format to be used when converting string values to a
 /// DateTime and binding DateTime parameters.
 /// </param>
 /// <param name="kind">
 /// The <see cref="DateTimeKind" /> to be used when creating DateTime
 /// values.
 /// </param>
 /// <param name="formatString">
 /// The format string to be used when parsing and formatting DateTime
 /// values.
 /// </param>
 /// <param name="utf16">
 /// Non-zero to create a UTF-16 data-type conversion context; otherwise,
 /// a UTF-8 data-type conversion context will be created.
 /// </param>
 protected SQLiteFunction(
     SQLiteDateFormats format,
     DateTimeKind kind,
     string formatString,
     bool utf16
     )
     : this()
 {
     if (utf16)
         _base = new SQLite3_UTF16(format, kind, formatString, IntPtr.Zero, null, false);
     else
         _base = new SQLite3(format, kind, formatString, IntPtr.Zero, null, false);
 }
Example #29
0
 internal SQLite3_UTF16(SQLiteDateFormats fmt)
     : base(fmt)
 {
 }
 /// <summary>
 /// Initializes the conversion class
 /// </summary>
 /// <param name="fmt">The default date/time format to use for this instance</param>
 internal SQLiteConvert(SQLiteDateFormats fmt)
 {
     _datetimeFormat = fmt;
 }
    ///////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Constructs the object used to interact with the SQLite core library
    /// using the UTF-8 text encoding.
    /// </summary>
    /// <param name="fmt">
    /// The DateTime format to be used when converting string values to a
    /// DateTime and binding DateTime parameters.
    /// </param>
    /// <param name="kind">
    /// The <see cref="DateTimeKind" /> to be used when creating DateTime
    /// values.
    /// </param>
    /// <param name="fmtString">
    /// The format string to be used when parsing and formatting DateTime
    /// values.
    /// </param>
    /// <param name="db">
    /// The native handle to be associated with the database connection.
    /// </param>
    /// <param name="fileName">
    /// The fully qualified file name associated with <paramref name="db "/>.
    /// </param>
    /// <param name="ownHandle">
    /// Non-zero if the newly created object instance will need to dispose
    /// of <paramref name="db" /> when it is no longer needed.
    /// </param>
    internal SQLite3(
        SQLiteDateFormats fmt,
        DateTimeKind kind,
        string fmtString,
        IntPtr db,
        string fileName,
        bool ownHandle
        )
      : base(fmt, kind, fmtString)
    {
        if (db != IntPtr.Zero)
        {
            _sql = new SQLiteConnectionHandle(db, ownHandle);
            _fileName = fileName;
        }
    }
Example #32
0
 internal SQLiteBase(SQLiteDateFormats fmt)
     : base(fmt)
 {
 }
        /// <summary>
        /// Attempts to set the provider manifest options from the specified
        /// connection string parameters.  An exception may be thrown if one
        /// or more of the connection string parameter values do not conform
        /// to the expected type.
        /// </summary>
        /// <param name="opts">
        /// The dictionary containing the connection string parameters.
        /// </param>
        internal void SetFromOptions(
            SortedList <string, string> opts
            )
        {
            _dateTimeFormat       = SQLiteConnection.DefaultDateTimeFormat;
            _dateTimeKind         = SQLiteConnection.DefaultDateTimeKind;
            _dateTimeFormatString = SQLiteConnection.DefaultDateTimeFormatString;
            _binaryGuid           = /* SQLiteConnection.DefaultBinaryGUID; */ false; /* COMPAT: Legacy. */

            if (opts == null)
            {
                return;
            }

#if !PLATFORM_COMPACTFRAMEWORK
            string[] names = Enum.GetNames(typeof(SQLiteDateFormats));
#else
            string[] names =
            {
                SQLiteDateFormats.Ticks.ToString(),
                SQLiteDateFormats.ISO8601.ToString(),
                SQLiteDateFormats.JulianDay.ToString(),
                SQLiteDateFormats.UnixEpoch.ToString(),
                SQLiteDateFormats.InvariantCulture.ToString(),
                SQLiteDateFormats.CurrentCulture.ToString(),
                "Default"
            };
#endif

            foreach (string name in names)
            {
                if (String.IsNullOrEmpty(name))
                {
                    continue;
                }

                object value = SQLiteConnection.FindKey(opts, name, null);

                if (value == null)
                {
                    continue;
                }

                _dateTimeFormat = (SQLiteDateFormats)Enum.Parse(
                    typeof(SQLiteDateFormats), name, true);
            }

            object enumValue;

            enumValue = SQLiteConnection.TryParseEnum(
                typeof(SQLiteDateFormats), SQLiteConnection.FindKey(
                    opts, "DateTimeFormat", null), true);

            if (enumValue is SQLiteDateFormats)
            {
                _dateTimeFormat = (SQLiteDateFormats)enumValue;
            }

            enumValue = SQLiteConnection.TryParseEnum(
                typeof(DateTimeKind), SQLiteConnection.FindKey(
                    opts, "DateTimeKind", null), true);

            if (enumValue is DateTimeKind)
            {
                _dateTimeKind = (DateTimeKind)enumValue;
            }

            string stringValue = SQLiteConnection.FindKey(
                opts, "DateTimeFormatString", null);

            if (stringValue != null)
            {
                _dateTimeFormatString = stringValue;
            }

            stringValue = SQLiteConnection.FindKey(
                opts, "BinaryGUID", null);

            if (stringValue != null)
            {
                _binaryGuid = SQLiteConvert.ToBoolean(stringValue);
            }
        }