In the forum I transferred, the xengallery was once installed, so I had to change the following, because the table xfgallery no longer existed.
def get_xf_sql(type, id)
case type
when :gallery
return "SELECT NULL WHERE 1=0;"
when :attachment
<<-SQL
SELECT a.attachment_id, a.data_id, d.filename, d.file_hash, d.user_id
FROM #{TABLE_PREFIX}attachment AS a
INNER JOIN #{TABLE_PREFIX}attachment_data d ON a.data_id = d.data_id
WHERE attachment_id = #{id}
AND content_type = 'post'
SQL
end
end