I searched on the subscription site Roots Ireland and was not able to locate a John Ahearn marriage to a Margaret Brien in the North Cork parishes.
The only Margaret Brien baptismal record in the Aghada records was in 1804 (April 30th) parents John Brien and Catherine Barry. You mention 1806 for Margaret in Aghada, do you have a copy of the record?
The earliest baptismal record for a John Ahearn was a John Hearn who was baptized June 15 1808 in Aghada father Hugh Hearn mother Mary Murphy. I assume this record is not for your John. Likely your John was baptized in a parish that no longer has records back to 1798.
Let me know if you have questions.