| 2196 | |
| 2197 | |
| 2198 | void CVT_conversion_error(const dsc* desc, ErrorFunction err, const Exception* original) |
| 2199 | { |
| 2200 | /************************************** |
| 2201 | * |
| 2202 | * c o n v e r s i o n _ e r r o r |
| 2203 | * |
| 2204 | ************************************** |
| 2205 | * |
| 2206 | * Functional description |
| 2207 | * A data conversion error occurred. Complain. |
| 2208 | * |
| 2209 | **************************************/ |
| 2210 | string message; |
| 2211 | |
| 2212 | if (desc->dsc_dtype >= DTYPE_TYPE_MAX) |
| 2213 | { |
| 2214 | fb_assert(false); |
| 2215 | err(Arg::Gds(isc_badblk)); |
| 2216 | } |
| 2217 | |
| 2218 | if (desc->dsc_dtype == dtype_blob) |
| 2219 | message = "BLOB"; |
| 2220 | else if (desc->dsc_dtype == dtype_array) |
| 2221 | message = "ARRAY"; |
| 2222 | else if (desc->dsc_dtype == dtype_boolean) |
| 2223 | message = "BOOLEAN"; |
| 2224 | else if (desc->dsc_dtype == dtype_dbkey) |
| 2225 | message = "DBKEY"; |
| 2226 | else |
| 2227 | { |
| 2228 | // CVC: I don't have access here to JRD_get_thread_data())->tdbb_status_vector |
| 2229 | // to be able to clear it (I don't want errors appended, but replacing |
| 2230 | // the existing, misleading one). Since localError doesn't fill the thread's |
| 2231 | // status vector as ERR_post would do, our new error is the first and only one. |
| 2232 | // We discard errors from CVT_make_string because we are interested in reporting |
| 2233 | // isc_convert_error, not isc_arith_exception if CVT_make_string fails. |
| 2234 | // If someone finds a better way, these hacks can be deleted. |
| 2235 | // Initially I was trapping here status_exception and testing |
| 2236 | // e.value()[1] == isc_arith_except. |
| 2237 | |
| 2238 | try |
| 2239 | { |
| 2240 | const char* p; |
| 2241 | VaryStr<TEMP_STR_LENGTH> s; |
| 2242 | const USHORT length = |
| 2243 | CVT_make_string(desc, ttype_ascii, &p, &s, sizeof(s), 0, localError); |
| 2244 | message.assign(p, length); |
| 2245 | |
| 2246 | // Convert to \xDD surely non-printable characters |
| 2247 | for (FB_SIZE_T n = 0; n < message.getCount(); ++n) |
| 2248 | { |
| 2249 | if (message[n] < ' ') |
| 2250 | { |
| 2251 | string hex; |
| 2252 | hex.printf("#x%02x", UCHAR(message[n])); |
| 2253 | message.replace(n, 1, hex); |
| 2254 | n += (hex.length() - 1); |
| 2255 | } |
no test coverage detected