1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/*
* xmlsearch.c
*
* $Id$
*
* Search
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2012 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "sqlnode.h"
#include "sqlcomp.h"
#include "xmlnode.h"
#include "arith.h"
int itc_xml_row (it_cursor_t * itc, buffer_desc_t * buf, int pos,
dp_addr_t * leaf_ret);
long
pg_entity_level (db_buf_t first_key)
{
int len;
DB_BUF_TLEN (len, *first_key, first_key);
first_key += len;
first_key++;
return (DV_LONG_INT == *first_key
? LONG_REF (first_key)
: (long) (((signed char *) first_key)[1]));
}
int
itc_xml_row (it_cursor_t * itc, buffer_desc_t * buf, int pos,
dp_addr_t * leaf_ret)
{
O12;
return 0;
}
#ifndef O12
#define TEST_V(sps) \
{ \
search_spec_t * sp = sps[0]; \
spi2 = 1; \
while (sp) \
{ \
DV_COMPARE_SPEC (res, sp, itc); \
if (res != DVC_MATCH) \
return DVC_LESS; \
sp = sps[spi2++]; \
} \
}
db_buf_t
itc_misc_column (it_cursor_t * itc, db_buf_t page, dbe_table_t * tb, oid_t misc_id)
{
oid_t cid;
if (!tb || !tb->tb_misc_id_to_col_id)
return NULL;
cid = (oid_t) gethash ((void *) misc_id, tb->tb_misc_id_to_col_id);
if (!cid)
return NULL;
return (itc_column (itc, page, cid));
}
#endif
#ifndef O12
#define TEST_DEF \
{ \
col_pos = is_rmap ? itc_misc_column (itc, buf->bd_buffer, tb, sps[0]->sp_col_id) : NULL; \
if (!col_pos) \
return DVC_LESS; \
TEST_V (sps); \
}
#define SET_DEF(sp_inx) \
{ \
if (ma->ma_out_slots[out_inx]) \
{ \
col_pos = is_rmap ? itc_misc_column (itc, buf->bd_buffer, tb, ma->ma_ids[out_inx]) : NULL; \
if (!col_pos) \
qst_set_bin_string (qst, ma->ma_out_slots[out_inx], (db_buf_t) "", 0, DV_DB_NULL); \
else \
itc_qst_set_column (itc, page, ma->ma_ids[out_inx], col_pos, qst, ma->ma_out_slots[out_inx]); \
} \
}
#endif
typedef struct misc_upd_s
{
int mu_nth_col;
int mu_misc_pos;
int mu_misc_end;
dk_session_t *mu_out;
int mu_ses_init_fill;
update_node_t *mu_upd;
dbe_table_t *mu_row_tb;
db_buf_t mu_misc_str;
caddr_t *mu_qst;
}
misc_upd_t;
void
mu_write_header (misc_upd_t * mu)
{
dk_session_t *ses = mu->mu_out;
db_buf_t buf = (db_buf_t) ses->dks_out_buffer;
int init = mu->mu_ses_init_fill;
int len = (mu->mu_out->dks_out_fill - init) - 5;
buf[init] = DV_LONG_STRING;
LONG_SET (buf + init + 1, len);
}
oid_t
mu_next_new (misc_upd_t * mu)
{
for (;;)
{
oid_t cid;
mu->mu_nth_col++;
if (mu->mu_nth_col >= upd_n_cols (mu->mu_upd, mu->mu_qst))
return 0;
cid = upd_nth_col (mu->mu_upd, mu->mu_qst, mu->mu_nth_col);
if (IS_MISC_ID (cid)
&& (!mu->mu_row_tb->tb_misc_id_to_col_id
|| !gethash ((void *) (ptrlong) cid, mu->mu_row_tb->tb_misc_id_to_col_id)))
{
return cid;
}
}
}
oid_t
mu_next_old (misc_upd_t * mu)
{
oid_t id;
int len;
int pos = mu->mu_misc_pos;
if (-1 == pos)
pos = 0;
else
{
if (pos >= mu->mu_misc_end)
return 0;
pos += 4;
DB_BUF_TLEN (len, mu->mu_misc_str[pos], mu->mu_misc_str + pos);
pos += len;
}
mu->mu_misc_pos = pos;
if (pos >= mu->mu_misc_end)
return 0;
id = LONG_REF (mu->mu_misc_str + pos);
return id;
}
void
mu_copy_new (misc_upd_t * mu)
{
caddr_t val = upd_nth_value (mu->mu_upd, mu->mu_qst, mu->mu_nth_col);
print_long ((long) upd_nth_col (mu->mu_upd, mu->mu_qst, mu->mu_nth_col), mu->mu_out);
print_object (val, mu->mu_out, NULL, NULL);
}
void
mu_copy_old (misc_upd_t * mu)
{
int pos = mu->mu_misc_pos;
int len;
pos += 4;
DB_BUF_TLEN (len, mu->mu_misc_str[pos], mu->mu_misc_str + pos);
session_buffered_write (mu->mu_out, (char *) (mu->mu_misc_str + pos - 4), len + 4);
}
void
upd_misc_col (update_node_t * upd, caddr_t * qst, dbe_table_t * row_tb, db_buf_t old_val, dk_session_t * ses,
caddr_t * err_ret)
{
oid_t old_id, new_id;
misc_upd_t mu;
long ol, ohl;
db_buf_length (old_val, &ohl, &ol);
memset (&mu, 0, sizeof (misc_upd_t));
mu.mu_nth_col = -1;
mu.mu_misc_pos = ohl;
mu.mu_out = ses;
mu.mu_ses_init_fill = ses->dks_out_fill;
mu.mu_misc_str = old_val;
mu.mu_upd = upd;
mu.mu_misc_end = ohl + ol;
mu.mu_row_tb = row_tb;
mu.mu_qst = qst;
old_id = mu_next_old (&mu);
new_id = mu_next_new (&mu);
session_buffered_write (ses, " ", 5); /* leave space for header */
for (;;)
{
if (!old_id && !new_id)
break;
if (!new_id
|| (old_id && old_id < new_id))
{
mu_copy_old (&mu);
old_id = mu_next_old (&mu);
}
else if (old_id == new_id)
{
mu_copy_new (&mu);
new_id = mu_next_new (&mu);
old_id = mu_next_old (&mu);
}
else
{
mu_copy_new (&mu);
new_id = mu_next_new (&mu);
}
}
mu_write_header (&mu);
}
void
ins_misc_col (dk_session_t * ses,
dbe_table_t * tb, oid_t * col_ids, caddr_t * values)
{
int inx;
misc_upd_t mu;
memset (&mu, 0, sizeof (misc_upd_t));
mu.mu_out = ses;
mu.mu_ses_init_fill = ses->dks_out_fill;
session_buffered_write (ses, " ", 5); /* space for header */
DO_BOX (oid_t, cid, inx, col_ids)
{
if (IS_MISC_ID (cid)
&& (!tb->tb_misc_id_to_col_id
|| !gethash ((void *) (ptrlong) cid, tb->tb_misc_id_to_col_id)))
{
print_long ((long) cid, ses);
print_object (values[inx], ses, NULL, NULL);
}
}
END_DO_BOX;
mu_write_header (&mu);
}
|