Remove CXXCOMSTR and LINKCOMSTR, its better to see what's going on.
Make escape function inline and add a last_insert_id function to get the last inserted record id from the sequence.