Protect Identifiers

This function is used extensively by the Query Builder class, and by
a couple functions in this class.
It takes a column or table name (optionally with an alias) and inserts
the table prefix onto it. Some logic is necessary in order to deal with
column names that include the path. Consider a query like this:

SELECT hostname.database.table.column AS c FROM hostname.database.table

Or a query with aliasing:

SELECT m.member_id, m.member_name FROM members AS m

Since the column name can include up to four segments (host, DB, table, column)
or also have an alias prefix, we need to do a bit of work to figure this out and
insert the table prefix (if it exists) in the proper position, and escape only
the correct identifiers.

@param string|array  $item
@param boolean       $prefixSingle
@param boolean       $protectIdentifiers
@param boolean       $fieldExists

@return string|array