Extended the result set system. Added support for filtering/limits.
[idzebra-moved-to-github.git] / rset / rsisams.c
1 /* $Id: rsisams.c,v 1.22 2005-05-03 09:11:36 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #include <stdio.h>
24 #include <assert.h>
25 #include <idzebra/util.h>
26 #include <rset.h>
27
28 static RSFD r_open (RSET ct, int flag);
29 static void r_close (RSFD rfd);
30 static void r_delete (RSET ct);
31 static int r_read (RSFD rfd, void *buf, TERMID *term);
32 static int r_write (RSFD rfd, const void *buf);
33 static void r_pos (RSFD rfd, double *current, double *total);
34
35 static const struct rset_control control = 
36 {
37     "isams",
38     r_delete,
39     rset_get_one_term,
40     r_open,
41     r_close,
42     rset_default_forward,
43     r_pos,
44     r_read,
45     r_write,
46 };
47
48 struct rfd_private {
49     ISAMS_PP pt;
50 };
51
52 struct rset_private {
53     ISAMS   is;
54     ISAM_P pos;
55 };
56
57
58 RSET rsisams_create(NMEM nmem, struct rset_key_control *kcontrol,
59                     int scope,
60                     ISAMS is, ISAM_P pos, TERMID term)
61 {
62     RSET rnew = rset_create_base(&control, nmem, kcontrol, scope, term);
63     struct rset_private *info;
64     info = (struct rset_private *) nmem_malloc(rnew->nmem,sizeof(*info));
65     rnew->priv = info;
66     info->is = is;
67     info->pos = pos;
68     return rnew;
69 }
70
71 static void r_delete (RSET ct)
72 {
73     yaz_log (YLOG_DEBUG, "rsisams_delete");
74     rset_delete(ct);
75 }
76
77
78 RSFD r_open (RSET ct, int flag)
79 {
80     struct rset_private *info = (struct rset_private *) ct->priv;
81     RSFD rfd;
82     struct rfd_private *ptinfo;
83
84     yaz_log (YLOG_DEBUG, "risams_open");
85     if (flag & RSETF_WRITE)
86     {
87         yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
88         return NULL;
89     }
90     rfd=rfd_create_base(ct);
91     if (rfd->priv)
92         ptinfo=(struct rfd_private *)(rfd->priv);
93     else {
94         ptinfo = (struct rfd_private *) nmem_malloc(ct->nmem,sizeof(*ptinfo));
95         ptinfo->pt = isams_pp_open (info->is, info->pos);
96         rfd->priv=ptinfo;
97     }
98     return rfd;
99 }
100
101 static void r_close (RSFD rfd)
102 {
103     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
104
105     isams_pp_close (ptinfo->pt);
106     rfd_delete_base(rfd);
107 }
108
109
110 static int r_read (RSFD rfd, void *buf, TERMID *term)
111 {
112     struct rfd_private *ptinfo = (struct rfd_private *)(rfd->priv);
113     int rc;
114     rc=isams_pp_read(ptinfo->pt, buf);
115     if (rc && term)
116         *term=rfd->rset->term;
117     return rc;
118 }
119
120 static int r_write (RSFD rfd, const void *buf)
121 {
122     yaz_log (YLOG_FATAL, "ISAMS set type is read-only");
123     return -1;
124 }
125
126 static void r_pos (RSFD rfd, double *current, double *total)
127 {
128     *current=-1;  /* sorry, not implemented yet */
129     *total=-1;
130 }
131
132