database query functions