コード例 #1
0
/* creates text for trigger's command */
static sds genNRL_Cmd(bt     *btr,
                      d_l_t  *nrlind,
                      aobj   *apk,
                      char   *vals,
                      uint32  cofsts[],
                      void   *rrow,
                      int     tmatch) {
    sds       cmd     = sdsempty();                      /* DESTROY ME 016 */
    list     *nrltoks = nrlind->l1;
    list     *nrlcols = nrlind->l2;
    listIter *li1     = listGetIterator(nrltoks, AL_START_HEAD);
    listIter *li2     = listGetIterator(nrlcols, AL_START_HEAD);
    listNode *ln1     = listNext(li1);
    listNode *ln2     = listNext(li2);
    while (ln1 || ln2) {
        if (ln1) {
            sds token = ln1->value;
            cmd       = sdscatlen(cmd, token, sdslen(token));
            ln1       = listNext(li1);
        }
        int cmatch = -1;
        if (ln2) {
            cmatch = ((int)(long)ln2->value) - 1; /* because (0 != NULL) */
            ln2    = listNext(li2);
        }
        if (cmatch != -1) {
            char *x;
            int   xlen;
            if (vals) { /* from INSERT */
                if (!cmatch) { /* PK not stored in ROW */
                    x    = strFromAobj(apk, &xlen);
                } else {       /* get COL from cofsts */
                    x    = vals + cofsts[cmatch - 1];
                    xlen = cofsts[cmatch] - cofsts[cmatch - 1] - 1;
                }
                cmd = sdscatlen(cmd, x, xlen);
                if (!cmatch) free(x);                    /* FREED 015 */
            } else { /* not from INSERT -> fetch row */
                aobj rcol = getRawCol(btr, rrow, cmatch, apk, tmatch, NULL, 1);
                x         = rcol.s;
                xlen      = rcol.len;
                cmd = sdscatlen(cmd, x, xlen);
                releaseAobj(&rcol);
            }
        }
    }
    listReleaseIterator(li1);
    listReleaseIterator(li2);
    return cmd;
}
コード例 #2
0
/* makes Copy - must be freeD */
static char *getCopyColStr(bt     *btr,
                           void   *rrow,
                           int     cmatch,
                           aobj   *aopk,
                           int     tmatch,
                           uint32 *len) {
    char   *dest;
    aobj    ao  = getRawCol(btr, rrow, cmatch, aopk, tmatch, NULL, 1);
    // force_string(INT) comes from a buffer, must be copied here
    char   *src = ao.s;
    m_strcpy_len(src, ao.len, &dest); /* freeD in freeIndRowEntries */
    *len        = ao.len;
    releaseAobj(&ao);
    return dest;
}