fix database bugs ,add function