This is what to do to fix this kind of problem :
tar cvzf rpmdb-backup.tar.gz /var/lib/rpm
rm /var/lib/rpm/__db.00*
rpm --rebuilddb
rpm -qa | sort
The first line is to backup your database
The second to remove locks
The third to rebuild your database
The fourth to check if all is ok