Exemplo n.º 1
0
        private long GetCounterId(string path)
        {
            long id;

            if (!CounterIds.TryGetValue(path, out id))
            {
                SQLiteCommand cmd = new SQLiteCommand("SELECT id FROM counter WHERE path = @path", Database);
                cmd.Parameters.AddWithValue("@path", path);
                object result = cmd.ExecuteScalar();

                if (result == null)
                {
                    cmd = new SQLiteCommand("INSERT INTO counter (path) VALUES (@path)", Database);
                    cmd.Parameters.AddWithValue("@path", path);
                    cmd.ExecuteNonQuery();
                    cmd    = new SQLiteCommand("SELECT last_insert_rowid()", Database);
                    result = cmd.ExecuteScalar();
                }

                id = (long)result;
                CounterIds.Add(path, id);
            }

            return(id);
        }