1 // $Header: /home/cvsroot/yaz++/zoom/zrs.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $
3 // Z39.50 Result Set class
9 resultSet::resultSet(connection &c, const query &q) : owner(c) {
10 ZOOM_connection yazc = c._getYazConnection();
11 rs = ZOOM_connection_search(yazc, q._getYazQuery());
13 const char *errmsg; // unused: carries same info as `errcode'
16 if ((errcode = ZOOM_connection_error(yazc, &errmsg, &addinfo)) != 0) {
17 throw bib1Error(errcode, addinfo);
21 resultSet::~resultSet() {
22 ZOOM_resultset_destroy(rs);
25 const char *resultSet::option(const char *key) const {
26 return ZOOM_resultset_option_get(rs, key);
29 const char *resultSet::option(const char *key, const char *val) {
30 // ### There may be memory-management issues here.
31 const char *old = ZOOM_resultset_option_get(rs, key);
32 ZOOM_resultset_option_set(rs, key, val);
36 size_t resultSet::size() const {
37 return ZOOM_resultset_size(rs);
40 const record *resultSet::getRecord(size_t i) const {
42 if ((rec = ZOOM_resultset_record(rs, i)) == 0) {
43 const char *errmsg; // unused: carries same info as `errcode'
45 int errcode = ZOOM_connection_error(owner._getYazConnection(),
47 throw bib1Error(errcode, addinfo);
50 // Memory management is odd here. The ZOOM-C record we've
51 // just fetched (`rec') is owned by the ZOOM-C result-set we
52 // fetched it from (`rs'), so all we need to allocate is a
53 // ZOOM-C++ wrapper for it, which is destroyed at the
54 // appropriate time -- but the underlying (ZOOM-C) record is
55 // _not_ destroyed at that time, because it's done when the
56 // underlying result-set is deleted.
57 return new record(this, rec);