Exemplo n.º 1
0
mdb_row_t *mdb_index_get_row(mdb_table_t *tbl, int idxlen, void *idxval)
{
    mdb_index_t *ix;

    MDB_CHECKARG(tbl && idxlen >= 0 && idxval, NULL);

    ix = &tbl->index;

    return mdb_hash_get_data(ix->hash, idxlen, idxval);
}
Exemplo n.º 2
0
Arquivo: mqi.c Projeto: 01org/murphy
mqi_handle_t mqi_get_table_handle(char *table_name)
{
    void *data;

    MDB_CHECKARG(table_name, MQI_HANDLE_INVALID);
    MDB_PREREQUISITE(dbs && ndb > 0, MQI_HANDLE_INVALID);

    data = mdb_hash_get_data(table_name_hash, 0,table_name);

    if (data != NULL)
        return data - NULL;
    else
        return MQI_HANDLE_INVALID;
}
Exemplo n.º 3
0
int mdb_index_create(mdb_table_t *tbl, char **index_columns)
{
    mdb_index_t     *ix;
    mdb_column_t    *col;
    mqi_data_type_t  type;
    int              beg, end;
    int             *idxcols;
    int              i,j, idx;

    MDB_CHECKARG(tbl && index_columns && index_columns[0], -1);

    ix = &tbl->index;

    beg = end = 0;
    type = mqi_unknown;
    idxcols = NULL;

    for (i = 0;    index_columns[i];    i++) {
        if (!(idx = mdb_hash_get_data(tbl->chash,0,index_columns[i]) - NULL)) {
            errno = ENOENT;
            return -1;
        }

        col = tbl->columns + --idx;
        col->flags |= MQI_COLUMN_KEY;

        if (i == 0) {
            type = col->type;
            beg  = col->offset;
            end  = beg + col->length;
        }
        else {
            type = mqi_blob;

            if (col->offset == end)
                end += col->length;
            else if (col->offset == beg - col->length)
                beg = col->offset;
            else {
                type = mqi_unknown;
                break; /* not an adjacent column */
            }
        }

        if (!(idxcols = realloc(idxcols, sizeof(int) * (i+1)))) {
            errno = ENOMEM;
            return -1;
        }

        for (j = 0;  j < i;  j++) {
            if (idx == idxcols[j])
                break;

            if (idx < idxcols[j]) {
                memmove(idxcols + j+1, idxcols + j, sizeof(*idxcols) * (i-j));
                break;
            }
        }

        idxcols[j] = idx;
    }

    if (type == mqi_unknown || beg < 0 || end <= beg ||
        end - beg > MDB_INDEX_LENGTH_MAX)
    {
        free(idxcols);
        errno = EIO;
        return -1;
    }

    ix->type    = type;
    ix->length  = end - beg;
    ix->offset  = beg;
    ix->ncolumn = i;
    ix->columns = idxcols;

    switch (type) {
    case mqi_varchar:
        ix->hash = INDEX_HASH_CREATE(varchar);
        ix->sequence = INDEX_SEQUENCE_CREATE(varchar);
        break;
    case mqi_integer:
        ix->hash = INDEX_HASH_CREATE(integer);
        ix->sequence = INDEX_SEQUENCE_CREATE(integer);
        break;
    case mqi_unsignd:
        ix->hash = INDEX_HASH_CREATE(unsignd);
        ix->sequence = INDEX_SEQUENCE_CREATE(unsignd);
        break;
    case mqi_blob:
        ix->hash = INDEX_HASH_CREATE(blob);
        ix->sequence = INDEX_SEQUENCE_CREATE(blob);
        break;
    default:
        free(idxcols);
        memset(ix, 0, sizeof(*ix));
        break;
    }

    return 0;
}