예제 #1
0
        public static string[][] GetAllItems()
        {
            string[][]       result     = new string[BlacklistManager.GetCount()][];
            SQLiteConnection connection = new SQLiteConnection(setConnection);
            SQLiteCommand    command    = new SQLiteCommand(getAllItems, connection);

            connection.Open();
            SQLiteDataReader reader = null;

            try {
                reader = command.ExecuteReader();
                for (int i = 0; reader.Read(); i++)
                {
                    result[i] = new string[1] {
                        (string)reader["address"]
                    };
                }
                reader.Close();
            }
            catch (SQLiteException) {
                connection.Close();
                BlacklistManager.SetUp();
                //should be empty now, so no loop
            }
            finally {
                connection.Close();
            }
            return(result);
        }
예제 #2
0
        public static bool Contains(string address)
        {
            SQLiteConnection connection = new SQLiteConnection(setConnection);
            SQLiteCommand    command    = new SQLiteCommand(String.Format(getItemByAddress, address), connection);

            connection.Open();
            SQLiteDataReader reader = null;

            try {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    reader.Close();
                    return(true);
                }
                reader.Close();
            }
            catch (SQLiteException) {
                connection.Close();
                BlacklistManager.SetUp();
                //should always be empty here, so no loop
            }
            finally {
                connection.Close();
            }
            return(false);
        }
예제 #3
0
        public static void Delete(string address)
        {
            SQLiteConnection connection = new SQLiteConnection(setConnection);

            connection.Open();
            SQLiteCommand command = new SQLiteCommand(String.Format(removeItem, address), connection);

            try {
                command.ExecuteNonQuery();
                BlacklistManager.OnChange();
            }
            catch (SQLiteException) {
                connection.Close();
                BlacklistManager.SetUp();
            }
            finally {
                connection.Close();
            }
        }
예제 #4
0
        public static long GetCount()
        {
            SQLiteConnection connection = new SQLiteConnection(setConnection);
            SQLiteCommand    command    = new SQLiteCommand(getCount, connection);
            long             result     = 0;

            try {
                connection.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                reader.Read();
                result = (long)reader[0];
                reader.Close();
            }
            catch (SQLiteException) {
                connection.Close();
                BlacklistManager.SetUp();
                return(0);
            }
            finally {
                connection.Close();
            }
            return(result);
        }