fixes wrapped query when the sql is for write CDB-1602