added database query functions for device attribute events count and devices