QResultHold rholda;
 
        rhold = CC_send_query_append(self, query, qi, flag, stmt, NULL);
-       if (QR_command_maybe_successful(res))
+       if (QR_command_maybe_successful(rhold.first))
        {
            rholda = CC_send_query_append(self, appendq, qi, flag & (~(GO_INTO_TRANSACTION)), stmt, NULL);
            if (QR_command_maybe_successful(rholda.first))
 
                     * If we received fewer rows than requested, there are no
                     * more rows to fetch.
                     */
-                   if (qres->num_cached_rows < qi.row_size)
+                   if (qres && qres->num_cached_rows < qi.row_size) /* check qres != NULL for safety */
                        QR_set_reached_eof(qres);
                }
                first = qres;