As explained in the User's Guide page, a sequence is an unbounded array of eXtremeDB-supported scalar data elements. The generated C API classname_fieldname_*()
functions are used by C applications to manage database fields of type sequence. As sequences are effectively vectors of values, they are accessed through iterators. The C type mco_seq_iterator_h
is used in classname_fieldname_*()
for basic sequence operations. A powerful set of Analytics Methods are also provided for performing mathematical and statistical operations on sequences.
Normally sequence data is inserted using the generated C API <classname>_<fieldname>_append(). For example consider the following schema definition:
#define uint4 unsigned<4> class Quote { char<16> symbol; sequence<uint4 asc> day; sequence<float> price; tree<symbol> by_symbol; };With this class definition, the Quote sequence fields
day
andprice
can be populated with code like the following:#define N_ITEMS 4 uint4 days[N_ITEMS] = { 1, 2, 4, 5 }; float prices[N_ITEMS] = { 10, 20, 40 ,50 }; ... Quote q; Quote_new(t, &q); Quote_symbol_put(&q, "IBM", (uint2)(strlen("IBM"))); Quote_day_append(&q, days, N_ITEMS); Quote_price_append(&q, prices, N_ITEMS);It may sometimes be necessary to insert values into an ordered time series. Values can be inserted into an existing sequence using the generated C API <classname>_<fieldname>_insert(). For example, the following code snippet searches for the Quote object with symbol "
IBM
", then insertsday
andprice
values:#define DAY_THREE 3 #define DAY_THREE_PRICE 30 uint4 day_to_insert[1] = { DAY_THREE }; float price_to_insert[1] = { DAY_THREE_PRICE }; ... mco_trans_h t; mco_cursor_t cur; ... mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); rc = Quote_by_symbol_index_cursor(t, &cur); if (MCO_S_OK == rc) { rc = Quote_by_symbol_search(t, &cur, MCO_GE, "IBM", (uint2)(sizeof("IBM"))); if (MCO_S_OK == rc) { //insert here Quote q; Quote_new(t, &q); rc = Quote_from_cursor(t, &cur, &q); rc = Quote_day_iterator(&q, &it); if (MCO_S_OK == rc) { rc = Quote_day_search(&q, &it, DAY_THREE, MCO_SEQ_BOUNDARY_EXCLUSIVE, 0, MCO_SEQ_BOUNDARY_OPEN); mco_seq_no_t pos = it.first_seq_no; rc = Quote_day_insert(&q, pos, day_to_insert, 1); rc = Quote_price_insert(&q, pos, price_to_insert, 1); rc = mco_trans_commit(t); } } }