static oid column_find_row(sql_trans *tr, sql_column *c, const void *value, ...) { va_list va; BAT *b = NULL, *s = NULL, *r = NULL; oid rid = oid_nil; sql_column *n = NULL; va_start(va, value); s = delta_cands(tr, c->t); if (!s) goto return_nil; b = full_column(tr, c); if (!b) { bat_destroy(s); goto return_nil; } r = BATselect(b, s, value, NULL, true, false, false); bat_destroy(s); full_destroy(c, b); if (!r) goto return_nil; s = r; while ((n = va_arg(va, sql_column *)) != NULL) { value = va_arg(va, void *); c = n; b = full_column(tr, c); if (!b) { bat_destroy(s); goto return_nil; } r = BATselect(b, s, value, NULL, true, false, false); bat_destroy(s); full_destroy(c, b); if (!r) goto return_nil; s = r; } va_end(va); if (BATcount(s) == 1) { rid = BUNtoid(s, 0); } bat_destroy(s); return rid; return_nil: va_end(va); return oid_nil; }
static void * column_find_value(sql_trans *tr, sql_column *c, oid rid) { BUN q = BUN_NONE; BAT *b; void *res = NULL; b = full_column(tr, c); if (b) { if (rid < b->hseqbase || rid >= b->hseqbase + BATcount(b)) q = BUN_NONE; else q = rid - b->hseqbase; } if (q != BUN_NONE) { BATiter bi = bat_iterator(b); const void *r; size_t sz; r = BUNtail(bi, q); sz = ATOMlen(b->ttype, r); res = GDKmalloc(sz); if (res) memcpy(res, r, sz); } full_destroy(c, b); return res; }
/* returns table rids, for the given select ranges */ static rids * rids_select( sql_trans *tr, sql_column *key, void *key_value_low, void *key_value_high, ...) { va_list va; BAT *b = NULL, *s = NULL, *d = NULL; sql_column *nc; void *nvl, *nvh; rids *rs = ZNEW(rids); sql_dbat *bat = key->t->data; /* special case, key_value_low and high NULL, ie return all */ if (bat->dbid) d = store_funcs.bind_del(tr, key->t, RDONLY); if (key_value_low || key_value_high) { va_start(va, key_value_high); while ((nc = va_arg(va, sql_column *)) != NULL) { nvl = va_arg(va, void *); nvh = va_arg(va, void *); b = full_column(key, d, s); if (s) bat_destroy(s); if (!key_value_low) key_value_low = ATOMnilptr(b->ttype); if (!key_value_high) key_value_high = ATOMnilptr(b->ttype); s = BATselect(b, key_value_low, key_value_high); bat_destroy(b); key = nc; key_value_low = nvl; key_value_high = nvh; } va_end(va); }
static void * column_find_value(sql_trans *tr, sql_column *c, oid rid) { BUN q; BAT *b, *d = NULL; void *res = NULL; sql_dbat *bat = c->t->data; if (bat->dbid) d = store_funcs.bind_del(tr, c->t, RDONLY); b = full_column(c, d, NULL); if (d) bat_destroy(d); q = BUNfnd(b, (ptr) &rid); if (q != BUN_NONE) { BATiter bi = bat_iterator(b); void *r; int sz; res = BUNtail(bi, q); sz = ATOMlen(b->ttype, res); r = GDKzalloc(sz); memcpy(r,res,sz); res = r; } bat_destroy(b); return res; }
static oid column_find_row(sql_trans *tr, sql_column *c, void *value, ...) { va_list va; BUN q; BAT *b = NULL, *s = NULL, *r = NULL, *d = NULL; oid rid = oid_nil; sql_column *nc; void *nv; sql_dbat *bat = c->t->data; if (bat->dbid) d = store_funcs.bind_del(tr, c->t, RDONLY); va_start(va, value); while ((nc = va_arg(va, sql_column *)) != NULL) { nv = va_arg(va, void *); b = full_column(c, d, s); if (s) bat_destroy(s); s = BATselect(b, value, value); bat_destroy(b); c = nc; value = nv; } va_end(va); b = full_column(c, d, s); if (s) bat_destroy(s); if (d) bat_destroy(d); r = BATmirror(b); q = BUNfnd(r, value); if (q != BUN_NONE) { BATiter ri = bat_iterator(r); rid = *(oid *) BUNtail(ri, q); } bat_destroy(b); return rid; }
/* returns table rids, for the given select ranges */ static rids * rids_select( sql_trans *tr, sql_column *key, const void *key_value_low, const void *key_value_high, ...) { va_list va; BAT *b = NULL, *r = NULL, *s = NULL; rids *rs = ZNEW(rids); const void *kvl = key_value_low, *kvh = key_value_high; /* if pointers are equal, make it an inclusive select */ bool hi = key_value_low == key_value_high; if(!rs) return NULL; s = delta_cands(tr, key->t); if (s == NULL) { GDKfree(rs); return NULL; } b = full_column(tr, key); if (b == NULL) { bat_destroy(s); GDKfree(rs); return NULL; } if (!kvl) kvl = ATOMnilptr(b->ttype); if (!kvh && kvl != ATOMnilptr(b->ttype)) kvh = ATOMnilptr(b->ttype); if (key_value_low) { BAThash(b); r = BATselect(b, s, kvl, kvh, true, hi, false); bat_destroy(s); s = r; } full_destroy(key, b); if (s == NULL) { GDKfree(rs); return NULL; } if (key_value_low || key_value_high) { va_start(va, key_value_high); while ((key = va_arg(va, sql_column *)) != NULL) { kvl = va_arg(va, void *); kvh = va_arg(va, void *); b = full_column(tr, key); if (!kvl) kvl = ATOMnilptr(b->ttype); if (!kvh && kvl != ATOMnilptr(b->ttype)) kvh = ATOMnilptr(b->ttype); assert(kvh); r = BATselect(b, s, kvl, kvh, true, hi, false); bat_destroy(s); s = r; full_destroy(key, b); if (s == NULL) { GDKfree(rs); va_end(va); return NULL; } } va_end(va); }
b = full_column(key, d, s); if (s) bat_destroy(s); if (!key_value_low) key_value_low = ATOMnilptr(b->ttype); if (!key_value_high) key_value_high = ATOMnilptr(b->ttype); s = BATselect(b, key_value_low, key_value_high); bat_destroy(b); key = nc; key_value_low = nvl; key_value_high = nvh; } va_end(va); } b = full_column(key, d, s); if (s) bat_destroy(s); if (d) bat_destroy(d); if (key_value_low || key_value_high) { if (!key_value_low) key_value_low = ATOMnilptr(b->ttype); if (!key_value_high) key_value_high = ATOMnilptr(b->ttype); rs->data = BATselect(b, key_value_low, key_value_high); bat_destroy(b); } else { rs->data = b; } rs->cur = 0;