SMWSql3SmwIds::getDatabaseIdAndSort raise exception for when smw_object_ids is inaccessible

- Use SMW\MediaWiki\Database instead of $db = wfGetDB( DB_SLAVE );
- Use tableExistsCache to avoid that on each request $this->query( "SELECT 1 FROM $table ... ) is called