Bug 5978 - crash with prepared statements

Make the checking of table type safer.