fix bug for db class.

forked by mackyliu.