// db_map iterators are quite heavy (opens BDB cursors and stuff) and // to simplify the iteratros coping and assignments we use lazy initilization // It means actual db operation is postponed until the first iterator access. void check_open_cursor() const { if (m_CursorFile == 0) { _ASSERT(m_ParentFile); m_CursorFile = new map_file_type(m_ParentFile->GetDupKeysMode()); _ASSERT(m_Cur == 0); if (m_SearchFlag) { open_cursor(m_OpenMode, CBDB_FileCursor::eGE, m_pair.first); } else { if (m_IStatus == eEnd) { open_cursor(m_OpenMode, CBDB_FileCursor::eLast); m_Cur->ReverseFetchDirection(); } else { open_cursor(m_OpenMode, CBDB_FileCursor::eFirst); } } if (m_Cur->Fetch() == eBDB_Ok) { m_SearchFlag = true; m_pair.first = m_CursorFile->key; m_pair.second= m_CursorFile->value; if (m_IStatus == eEnd) { } else { m_IStatus = eInFile; } } else { // No data... // go to the end open_cursor(m_OpenMode, CBDB_FileCursor::eLast); m_IStatus = eEnd; } } }
void open_cursor(CBDB_RawFile::EOpenMode open_mode, CBDB_FileCursor::ECondition cursor_condition, const K& key) const { open_cursor(open_mode, cursor_condition); m_Cur->From << key; }
extern CAMLprim value kc_cursor_open(value caml_db) { CAMLparam1(caml_db); KCDB* db = get_db(caml_db); KCCUR* cur = open_cursor(db); value caml_cursor = alloc_small(1, Abstract_tag); KCCUR_val(caml_cursor) = cur; CAMLreturn(caml_cursor); }
int main (int argc, char *argv[]) { struct queryopt opt; struct ofields *fields; struct select_doc *s_doc; struct query_doc *qu_doc; struct db_connect *db_conn; struct output *out; struct db_cursor *db_c; struct results *res; opt.e_skip = 0; // standard opt.e_ret = 0; // standard opt.bsever = 0; opt.blevel = 0; opt.bdate = 0; opt.bdateu = 0; opt.bdatef = 0; opt.bmsg = 0; opt.bskip = 0; opt.bsys = 0; getoptions(argc, argv, &opt); qu_doc = create_query(&opt); // crate query s_doc = create_select(); db_conn = create_conn(); // create connection out = launch_query(&opt, s_doc, qu_doc, db_conn); // launch the query db_c = open_cursor(db_conn, out); // open cursor while (cursor_next(db_c)) { res = read_data(db_c); fields = get_data(res); formater(fields); // formate output free(fields); free(res); } free_cursor(db_c); close_conn(db_conn); free(out); free(s_doc); free(qu_doc); return (0); }
void go_end() { if (m_IStatus == eEnd) return; // if it's "end()" iterartor, no need to open any files here if (m_CursorFile == 0) { m_IStatus = eEnd; return; } open_cursor(m_OpenMode, CBDB_FileCursor::eLast); m_Cur->ReverseFetchDirection(); if (m_Cur->Fetch() == eBDB_Ok) { m_pair.first = (K)m_CursorFile->key; m_pair.second= (T)m_CursorFile->value; } m_IStatus = eEnd; }