Cursor.messages support

Added support for cursor.messages property (optional dbapi interface extension)

Exception creation refactored, code extracted into separate function