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
|
/*
* box2any.c
*
* $Id$
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2018 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
*
*/
caddr_t
name (caddr_t data, caddr_t * err_ret, MP_T * ap, int ser_flags)
{
caddr_t box;
int init, len;
dtp_t key_image[PAGE_DATA_SZ];
dk_session_t sesn, *ses = &sesn;
scheduler_io_data_t io;
dtp_t dtp = DV_TYPE_OF (data);
switch (dtp)
{
case DV_IRI_ID:
{
iri_id_t id = unbox_iri_id (data);
if (id < 0xffffffff)
{
box = ALLOC (6, DV_STRING);
box[0] = DV_IRI_ID;
LONG_SET_NA (box + 1, id);
box[5] = 0;
return box;
}
else
{
box = ALLOC (10, DV_STRING);
box[0] = DV_IRI_ID_8;
INT64_SET_NA (box + 1, id);
box[9] = 0;
return box;
}
}
case DV_LONG_INT:
{
boxint n = unbox (data);
if ((n > -128) && (n < 128))
{
box = ALLOC (3, DV_STRING);
box[0] = DV_SHORT_INT;
box[1] = n;
box[2] = 0;
}
else if (n >= (int64) INT32_MIN && n <= (int64) INT32_MAX)
{
int32 ni = n;
box = ALLOC (6, DV_STRING);
box[0] = DV_LONG_INT;
LONG_SET_NA (box + 1, ni);
box[5] = 0;
}
else
{
box = ALLOC (10, DV_STRING);
box[0] = DV_INT64;
INT64_SET_NA (box + 1, n);
box[9] = 0;
}
return box;}
case DV_SINGLE_FLOAT:
{
float f = unbox_float (data);
box = ALLOC (6, DV_STRING);
box[0] = DV_SINGLE_FLOAT;
FLOAT_TO_EXT (box + 1, &f);
box[5] = 0;
return box;
}
case DV_DOUBLE_FLOAT:
{
double f = unbox_double (data);
box = ALLOC (10, DV_STRING);
box[0] = DV_DOUBLE_FLOAT;
DOUBLE_TO_EXT (box + 1, &f);
box[9] = 0;
return box;
}
case DV_STRING:
{
int len = box_length (data);
if (box_flags (data))
goto general;
if (len > 256)
break;
box = ALLOC (len + 2, DV_STRING);
box[0] = DV_SHORT_STRING_SERIAL;
box[1] = len - 1;
memcpy (box + 2, data, len);
return box;
}
general:
default:;
}
ROW_OUT_SES (sesn, key_image);
SESSION_SCH_DATA (ses) = &io;
memset (SESSION_SCH_DATA (ses), 0, sizeof (scheduler_io_data_t));
sesn.dks_cluster_flags = ser_flags;
init = sesn.dks_out_fill;
CATCH_WRITE_FAIL (ses)
{
print_object (data, &sesn, NULL, NULL);
}
FAILED
{
if (DKS_TO_DC & ser_flags)
return box_to_any_long (data, err_ret, ser_flags);
*err_ret = srv_make_new_error ("22026", "SR477", "Error serializing the value into an ANY column");
return NULL;
}
END_WRITE_FAIL (ses);
if (sesn.dks_out_fill > PAGE_DATA_SZ - 10)
{
if (DKS_TO_DC & ser_flags)
return box_to_any_long (data, err_ret, ser_flags);
box2anyerr ();
*err_ret = srv_make_new_error ("22026", "SR478", "Value of ANY type column too long");
return NULL;
}
len = sesn.dks_out_fill - init;
box = ALLOC (len + 1, DV_STRING);
memcpy (box, &sesn.dks_out_buffer[init], len);
box[len] = 0;
return box;
}
#undef name
#undef MP_T
#undef ALLOC
|