I'm not really sure what you are trying to do with all that XOG "log" stuff - the XOG (upto line 25 above) should be doing the update to the application.
You still have not said what you are "stuck" with though? - There is no way I am going to debug all that code for you though from here - what I would suggest is doing the development of this bit-by-bit, get one bit working and then move onto the next bit, if you are then "stuck" you are stuck with a more specific problem that someone might have an answer for.
--
Generally direct SQL update in GEL is regarded as "bad" (there is nothing to stop you from doing it though yet - I have heard the odd comment that it might stop working in later versions of the application though) ; its "bad" because CA will not support you doing it (not let you do it in SAAS, not work to any SLA with any errors that might happen because of it) - but if the update is to a custom-field then there is normally little danger in doing it, but "good practice" would say that always doing updates through XOG is the right way to do it.