/// <summary>
        /// Gets the data from database.
        /// </summary>
        /// <param name="sqlQuery">The SQL query.</param>
        /// <returns></returns>
        internal static IEnumerable <DataModel> GetDataFromDatabase(string sqlQuery)
        {
            IList <DataModel> records = new List <DataModel>();

            using (var sqlConnection = new SQLiteConnection(Constants.ConnectoinString))
            {
                var command = new SQLiteCommand(sqlQuery, sqlConnection);

                sqlConnection.Open();
                SQLiteDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    records.Add(new DataModel
                    {
                        TransId      = Convert.ToString(reader[0], CultureInfo.CurrentCulture),
                        AccountName  = reader.GetString(1),
                        TransCode    = reader.GetString(2),
                        Notes        = reader.IsDBNull(3) ? null : reader.GetString(3),
                        CategName    = reader.IsDBNull(4) ? null : reader.GetString(4),
                        SubCategName = reader.IsDBNull(5) ? null : reader.GetString(5),
                        PayeeName    = reader.IsDBNull(6) ? null : reader.GetString(6),
                        TransAmount  = reader.GetDecimal(7),
                        TransDate    = SQLiteConvert.ToString(reader.GetDateTime(8), SQLiteDateFormats.Default, DateTimeKind.Local, "yyyy/MM/dd")
                    });
                }
            }
            return(records);
        }
Exemple #2
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);
        }
        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);
        }
        static DenverDBFactory()
        {
#if (SQLITE_STANDARD || USE_INTEROP_DLL || PLATFORM_COMPACTFRAMEWORK) && PRELOAD_NATIVE_LIBRARY
            UnsafeNativeMethods.Initialize();
#endif

#if INTEROP_LOG
            if (UnsafeNativeMethods.sqlite3_config_log_interop() == SQLiteErrorCode.Ok)
            {
                UnsafeNativeMethods.sqlite3_log(
                    SQLiteErrorCode.Ok, SQLiteConvert.ToUTF8("logging initialized."));
            }
#endif

            SQLiteLog.Initialize();

            string version =
#if NET_40 || NET_45 || NET_451
                "4.0.0.0";
#else
                "3.5.0.0";
#endif

            _dbProviderServicesType = Type.GetType(String.Format(CultureInfo.InvariantCulture, "System.Data.Common.DbProviderServices, System.Data.Entity, Version={0}, Culture=neutral, PublicKeyToken=b77a5c561934e089", version), false);
        }
        private void Category_OnLoaded(object sender, RoutedEventArgs e)
        {
            var query = Db.Query("SELECT Name, FromFile FROM categories WHERE Path = @Path", new [] { new SQLiteParameter("Path", BookKeeper.GetRelativeBookFilePath(_bookFile)) });

            while (query.Read())
            {
                var category = new CategoryTag
                {
                    Name     = query["Name"].ToString(),
                    FromFile = SQLiteConvert.ToBoolean(query["FromFile"])
                };

                _categoryTagList.Add(category);
            }

            if (_categoryTagList.Count > 0)
            {
                CategoryTagsBorder.Visibility = Visibility.Visible;
            }

            Categories.ItemsSource = _categoryTagList;

            var defaultCategories = Properties.Settings.Default.DefaultCategories.Split(';');
            var hintList          = new List <string>(defaultCategories);

            hintList.AddRange(LibraryStructure.CategoryList());
            hintList.Sort();

            new Whisperer
            {
                TextBox  = (TextBox)sender,
                HintList = hintList
            };
        }
Exemple #6
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);
        }
        public static void Backup(SQLiteConnection source, SQLiteConnection destination)
        {
            IntPtr sourceHandle      = GetConnectionHandle(source);
            IntPtr destinationHandle = GetConnectionHandle(destination);

            IntPtr backupHandle = sqlite3_backup_init(destinationHandle, SQLiteConvert.ToUTF8("main"), sourceHandle, SQLiteConvert.ToUTF8("main"));

            sqlite3_backup_step(backupHandle, -1);
            sqlite3_backup_finish(backupHandle);
        }
Exemple #8
0
        public static bool Backup(SQLiteConnection source, SQLiteConnection destination)
        {
            lock (Injection.Kernel.Get <IDatabase>().DbBackupLock)
            {
                try
                {
                    IntPtr sourceHandle      = GetConnectionHandle(source);
                    IntPtr destinationHandle = GetConnectionHandle(destination);

                    IntPtr backupHandle = sqlite3_backup_init(destinationHandle, SQLiteConvert.ToUTF8("main"), sourceHandle, SQLiteConvert.ToUTF8("main"));
                    if (backupHandle != IntPtr.Zero)
                    {
                        sqlite3_backup_step(backupHandle, -1);
                        sqlite3_backup_finish(backupHandle);

                        string[] tablesToDelete = { "User", "Session", "Server" };

                        foreach (string tableName in tablesToDelete)
                        {
                            try
                            {
                                IDbCommand q = GetDbCommand("DROP TABLE IF EXISTS " + tableName, destination);
                                q.Prepare();
                                q.ExecuteNonQuery();
                            }
                            catch (Exception e)
                            {
                                logger.Error("Error deleting user table in backup: " + e);
                            }
                        }

                        return(true);
                    }

                    return(false);
                }
                catch (Exception e)
                {
                    logger.Error("Error backup up database: " + e);
                }
                finally
                {
                    Close(source, null);
                    Close(destination, null);
                }
                return(false);
            }
        }
Exemple #9
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));
 }
Exemple #10
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;
            }
        }
Exemple #11
0
        public static bool QueryExists(string sql, SQLiteParameter[] parameters = null)
        {
            bool exists;

            using (var command = new SQLiteCommand(sql, Connection))
            {
                if (parameters != null)
                {
                    command.Parameters.AddRange(parameters);
                }

                exists = SQLiteConvert.ToBoolean(command.ExecuteScalar());

                Connection.Close();
                Connection.Dispose();
            }

            return(exists);
        }
Exemple #12
0
        /// <summary>
        /// Turn a datatable into a table in the temporary database for the connection
        /// </summary>
        /// <param name="cnn">The connection to make the temporary table in</param>
        /// <param name="table">The table to write out</param>
        /// <param name="dest">The temporary table name to write to</param>
        private void DataTableToTable(SQLiteConnection cnn, DataTable table, string dest)
        {
            StringBuilder        sql     = new StringBuilder();
            SQLiteCommandBuilder builder = new SQLiteCommandBuilder();

            using (SQLiteCommand cmd = cnn.CreateCommand())
                using (DataTable source = new DataTable())
                {
                    sql.AppendFormat(CultureInfo.InvariantCulture, "CREATE TEMP TABLE {0} (", builder.QuoteIdentifier(dest));
                    string separator            = String.Empty;
                    SQLiteConnectionFlags flags = cnn.Flags;
                    foreach (DataColumn dc in table.Columns)
                    {
                        DbType dbtypeName = SQLiteConvert.TypeToDbType(dc.DataType);
                        string typeName   = SQLiteConvert.DbTypeToTypeName(cnn, dbtypeName, flags);

                        sql.AppendFormat(CultureInfo.InvariantCulture, "{2}{0} {1} COLLATE NOCASE", builder.QuoteIdentifier(dc.ColumnName), typeName, separator);
                        separator = ", ";
                    }
                    sql.Append(")");

                    cmd.CommandText = sql.ToString();
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = String.Format("SELECT * FROM TEMP.{0} WHERE 1=2", builder.QuoteIdentifier(dest));
                    using (SQLiteDataAdapter adp = new SQLiteDataAdapter(cmd))
                    {
                        builder.DataAdapter = adp;

                        adp.Fill(source);

                        foreach (DataRow row in table.Rows)
                        {
                            object[] arr = row.ItemArray;

                            source.Rows.Add(arr);
                        }
                        adp.Update(source);
                    }
                }
        }
Exemple #13
0
 private int xCreate(int argc, ref IntPtr argv, ref IntPtr ppTokenizer)
 {
     try
     {
         sqlite3_tokenizer pTokenizer = new sqlite3_tokenizer();
         this.ppTokenizer = this.MarshalStruct(pTokenizer);
         ppTokenizer      = this.ppTokenizer;
         string tokenizerArgument = null;
         if (argc > 0)
         {
             tokenizerArgument = SQLiteConvert.UTF8ToString(argv, -1);
         }
         owner.OnCreate(tokenizerArgument);
         return(SQLITE_OK);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return(SQLITE_ERROR);
     }
 }
Exemple #14
0
            private int xNext(ref sqlite3_tokenizer_cursor pCursor,
                              ref IntPtr ppToken, ref int pnBytes, ref int piStartOffset, ref int piEndOffset, ref int piPosition)
            {
                if (this.lastStringPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(this.lastStringPtr);
                    this.lastStringPtr = IntPtr.Zero;
                }

                if (owner.MoveNext())
                {
                    byte[] bytes = SQLiteConvert.ToUTF8(owner.Token);
                    pnBytes = bytes.Length;

                    this.lastStringPtr = Marshal.AllocHGlobal(pnBytes);
                    Marshal.Copy(bytes, 0, this.lastStringPtr, pnBytes);
                    ppToken = this.lastStringPtr;
                    pnBytes--;

                    string prevString = owner.InputString.Substring(0, owner.TokenIndexOfString);
                    piStartOffset = Encoding.UTF8.GetByteCount(prevString);
                    if (owner.NextIndexOfString < 0) // default
                    {
                        piEndOffset = piStartOffset + pnBytes;
                    }
                    else
                    {
                        prevString  = owner.InputString.Substring(0, owner.NextIndexOfString);
                        piEndOffset = Encoding.UTF8.GetByteCount(prevString);
                    }
                    owner.tokenNumber++;
                    piPosition = owner.tokenNumber;

                    return(SQLITE_OK);
                }
                else
                {
                    return(SQLITE_DONE);
                }
            }
Exemple #15
0
        /// <summary>
        /// Helper function for retrieving values from the connectionstring
        /// </summary>
        /// <param name="keyword">The keyword to retrieve settings for</param>
        /// <param name="value">The resulting parameter value</param>
        /// <returns>Returns true if the value was found and returned</returns>
        public override bool TryGetValue(string keyword, out object value)
        {
            bool b = base.TryGetValue(keyword, out value);

            if (!_properties.ContainsKey(keyword))
            {
                return(b);
            }

            PropertyDescriptor pd = _properties[keyword] as PropertyDescriptor;

            if (pd == null)
            {
                return(b);
            }

            // Attempt to coerce the value into something more solid
            if (b)
            {
                if (pd.PropertyType == typeof(Boolean))
                {
                    value = SQLiteConvert.ToBoolean(value);
                }
                else if (pd.PropertyType != typeof(byte[]))
                {
                    value = TypeDescriptor.GetConverter(pd.PropertyType).ConvertFrom(value);
                }
            }
            else
            {
                DefaultValueAttribute att = pd.Attributes[typeof(DefaultValueAttribute)] as DefaultValueAttribute;
                if (att != null)
                {
                    value = att.Value;
                    b     = true;
                }
            }
            return(b);
        }
Exemple #16
0
            private int xOpen(ref sqlite3_tokenizer pTokenizer,
                              IntPtr pInput,
                              int nBytes,
                              ref IntPtr ppCursor)
            {
                try
                {
                    sqlite3_tokenizer_cursor pCursor = new sqlite3_tokenizer_cursor();
                    pCursor.pTokenizer = this.ppTokenizer;
                    this.ppCursor      = this.MarshalStruct(pCursor);
                    ppCursor           = this.ppCursor;

                    owner.inputString = SQLiteConvert.UTF8ToString(pInput, nBytes);
                    owner.tokenNumber = -1;

                    owner.PrepareToStart();
                    return(SQLITE_OK);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return(SQLITE_ERROR);
                }
            }
        public static bool SaveToDatabase(string nummer, int snelheid, int zone)
        {
            // Bouw de insert-query op met de gegeven informatie

            DateTimeOffset dto       = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
            int            timestamp = Convert.ToInt32(dto);
            var            naam      = SQLiteConvert.ToUTF8(nummer);

            Database.Query = "INSERT INTO RFIDS (Timestamp, nummer,snelheid) values (" + timestamp + ", " + naam
                             + ", " + snelheid + "," + zone + ")";

            Database.OpenConnection();

            bool success = false;

            try
            {
                // ExecuteNonQuery wordt gebruikt als we geen gegevens verwachten van de query
                Database.Command.ExecuteNonQuery();
                success = true;
            }
            catch (SQLiteException e)
            {
                // Code 19 geeft aan dat een veld wat uniek moet zijn in de database, dit door
                // deze insert niet meer zou zijn. Het is dus niet toegevoegd. Aangezien in deze
                // applicatie deze constraint alleen op het Kunstnummer staat, kunnen we de
                // foutmelding heel specifiek weergeven.
                if (e.ErrorCode == 19)
                {
                    return(success);
                }
            }

            Database.CloseConnection();
            return(success);
        }
Exemple #18
0
        public override object ReadBoolean(DbDataReader reader, int index)
        {
            var value = reader.GetDecimal(index);

            return(SQLiteConvert.ToBoolean(value));
        }
        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));
            }
        }
        /// <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);
            }
        }
Exemple #21
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);
        }
Exemple #22
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);
        }
        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));
        }
Exemple #24
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;
            }
            }
        }
        /// <summary>
        /// Perform the bind operation for an individual parameter
        /// </summary>
        /// <param name="index">The index of the parameter to bind</param>
        /// <param name="param">The parameter we're binding</param>
        private void BindParameter(int index, SQLiteParameter param)
        {
            if (param == null)
            {
                throw new SQLiteException("Insufficient parameters supplied to the command");
            }

            object obj     = param.Value;
            DbType objType = param.DbType;

            if ((obj != null) && (objType == DbType.Object))
            {
                objType = SQLiteConvert.TypeToDbType(obj.GetType());
            }

            if ((_flags & SQLiteConnectionFlags.LogPreBind) == SQLiteConnectionFlags.LogPreBind)
            {
                IntPtr handle = _sqlite_stmt;

                SQLiteLog.LogMessage(String.Format(
                                         "Binding statement {0} paramter #{1} with database type {2} and raw value {{{3}}}...",
                                         handle, index, objType, obj));
            }

            if ((obj == null) || Convert.IsDBNull(obj))
            {
                _sql.Bind_Null(this, _flags, index);
                return;
            }

            CultureInfo invariantCultureInfo = CultureInfo.InvariantCulture;
            bool        invariantText        = ((_flags & SQLiteConnectionFlags.BindInvariantText)
                                                == SQLiteConnectionFlags.BindInvariantText);

            if ((_flags & SQLiteConnectionFlags.BindAllAsText) == SQLiteConnectionFlags.BindAllAsText)
            {
                if (obj is DateTime)
                {
                    _sql.Bind_DateTime(this, _flags, index, (DateTime)obj);
                }
                else
                {
                    _sql.Bind_Text(this, _flags, index, invariantText ?
                                   SQLiteConvert.ToStringWithProvider(obj, invariantCultureInfo) :
                                   obj.ToString());
                }

                return;
            }

            CultureInfo cultureInfo = CultureInfo.CurrentCulture;

            if ((_flags & SQLiteConnectionFlags.ConvertInvariantText) == SQLiteConnectionFlags.ConvertInvariantText)
            {
                cultureInfo = invariantCultureInfo;
            }

            switch (objType)
            {
            case DbType.Date:
            case DbType.Time:
            case DbType.DateTime:
                //
                // NOTE: The old method (commented below) does not honor the selected date format
                //       for the connection.
                // _sql.Bind_DateTime(this, index, Convert.ToDateTime(obj, cultureInfo));
                _sql.Bind_DateTime(this, _flags, index, (obj is string) ?
                                   _sql.ToDateTime((string)obj) : Convert.ToDateTime(obj, cultureInfo));
                break;

            case DbType.Boolean:
                _sql.Bind_Int32(this, _flags, index, SQLiteConvert.ToBoolean(obj, cultureInfo, true) ? 1 : 0);
                break;

            case DbType.SByte:
                _sql.Bind_Int32(this, _flags, index, Convert.ToSByte(obj, cultureInfo));
                break;

            case DbType.Int16:
                _sql.Bind_Int32(this, _flags, index, Convert.ToInt16(obj, cultureInfo));
                break;

            case DbType.Int32:
                _sql.Bind_Int32(this, _flags, index, Convert.ToInt32(obj, cultureInfo));
                break;

            case DbType.Int64:
                _sql.Bind_Int64(this, _flags, index, Convert.ToInt64(obj, cultureInfo));
                break;

            case DbType.Byte:
                _sql.Bind_UInt32(this, _flags, index, Convert.ToByte(obj, cultureInfo));
                break;

            case DbType.UInt16:
                _sql.Bind_UInt32(this, _flags, index, Convert.ToUInt16(obj, cultureInfo));
                break;

            case DbType.UInt32:
                _sql.Bind_UInt32(this, _flags, index, Convert.ToUInt32(obj, cultureInfo));
                break;

            case DbType.UInt64:
                _sql.Bind_UInt64(this, _flags, index, Convert.ToUInt64(obj, cultureInfo));
                break;

            case DbType.Single:
            case DbType.Double:
            case DbType.Currency:
                //case DbType.Decimal: // Dont store decimal as double ... loses precision
                _sql.Bind_Double(this, _flags, index, Convert.ToDouble(obj, cultureInfo));
                break;

            case DbType.Binary:
                _sql.Bind_Blob(this, _flags, index, (byte[])obj);
                break;

            case DbType.Guid:
                if (_command.Connection._binaryGuid == true)
                {
                    _sql.Bind_Blob(this, _flags, index, ((Guid)obj).ToByteArray());
                }
                else
                {
                    _sql.Bind_Text(this, _flags, index, invariantText ?
                                   SQLiteConvert.ToStringWithProvider(obj, invariantCultureInfo) :
                                   obj.ToString());
                }
                break;

            case DbType.Decimal: // Dont store decimal as double ... loses precision
                _sql.Bind_Text(this, _flags, index, Convert.ToDecimal(obj, cultureInfo).ToString(invariantCultureInfo));
                break;

            default:
                _sql.Bind_Text(this, _flags, index, invariantText ?
                               SQLiteConvert.ToStringWithProvider(obj, invariantCultureInfo) :
                               obj.ToString());
                break;
            }
        }