mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 10:43:03 +01:00
Misc and try to be consistent to use the padding char.
More to come.
This commit is contained in:
parent
315bd0a8f5
commit
5cdb49cde9
@ -282,7 +282,6 @@ double CVT_get_double(const dsc* desc, FPTR_ERROR err)
|
|||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
double value;
|
double value;
|
||||||
SSHORT scale;
|
|
||||||
|
|
||||||
switch (desc->dsc_dtype) {
|
switch (desc->dsc_dtype) {
|
||||||
case dtype_short:
|
case dtype_short:
|
||||||
@ -336,7 +335,7 @@ double CVT_get_double(const dsc* desc, FPTR_ERROR err)
|
|||||||
&p,
|
&p,
|
||||||
(vary*) buffer, sizeof(buffer), err);
|
(vary*) buffer, sizeof(buffer), err);
|
||||||
value = 0.0;
|
value = 0.0;
|
||||||
scale = 0;
|
int scale = 0;
|
||||||
SSHORT sign = 0;
|
SSHORT sign = 0;
|
||||||
bool digit_seen = false, past_sign = false, fraction = false;
|
bool digit_seen = false, past_sign = false, fraction = false;
|
||||||
const char* const end = p + length;
|
const char* const end = p + length;
|
||||||
@ -451,20 +450,21 @@ double CVT_get_double(const dsc* desc, FPTR_ERROR err)
|
|||||||
|
|
||||||
/* Last, but not least, adjust for scale */
|
/* Last, but not least, adjust for scale */
|
||||||
|
|
||||||
if ((scale = desc->dsc_scale) == 0)
|
const int dscale = desc->dsc_scale;
|
||||||
|
if (dscale == 0)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
/* if the scale is greater than the power of 10 representable
|
/* if the scale is greater than the power of 10 representable
|
||||||
in a double number, then something has gone wrong... let
|
in a double number, then something has gone wrong... let
|
||||||
the user know... */
|
the user know... */
|
||||||
|
|
||||||
if (ABSOLUT(scale) > DBL_MAX_10_EXP)
|
if (ABSOLUT(dscale) > DBL_MAX_10_EXP)
|
||||||
(*err) (isc_arith_except, 0);
|
(*err) (isc_arith_except, 0);
|
||||||
|
|
||||||
if (scale > 0)
|
if (dscale > 0)
|
||||||
value *= power_of_ten(scale);
|
value *= power_of_ten(dscale);
|
||||||
else if (scale < 0)
|
else if (dscale < 0)
|
||||||
value /= power_of_ten(-scale);
|
value /= power_of_ten(-dscale);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -483,7 +483,7 @@ SLONG CVT_get_long(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
* scale.
|
* scale.
|
||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
SLONG value, high, fraction;
|
SLONG value, high;
|
||||||
|
|
||||||
double d, eps;
|
double d, eps;
|
||||||
SINT64 val64;
|
SINT64 val64;
|
||||||
@ -510,10 +510,10 @@ SLONG CVT_get_long(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
|
|
||||||
/* adjust for scale first, *before* range-checking the value. */
|
/* adjust for scale first, *before* range-checking the value. */
|
||||||
if (scale > 0) {
|
if (scale > 0) {
|
||||||
fraction = 0;
|
SLONG fraction = 0;
|
||||||
do {
|
do {
|
||||||
if (scale == 1)
|
if (scale == 1)
|
||||||
fraction = (SLONG) (val64 % 10);
|
fraction = SLONG(val64 % 10);
|
||||||
val64 /= 10;
|
val64 /= 10;
|
||||||
} while (--scale);
|
} while (--scale);
|
||||||
if (fraction > 4)
|
if (fraction > 4)
|
||||||
@ -622,7 +622,7 @@ SLONG CVT_get_long(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
|
|
||||||
if (scale > 0) {
|
if (scale > 0) {
|
||||||
if (DTYPE_IS_EXACT(desc->dsc_dtype)) {
|
if (DTYPE_IS_EXACT(desc->dsc_dtype)) {
|
||||||
fraction = 0;
|
SLONG fraction = 0;
|
||||||
do {
|
do {
|
||||||
if (scale == 1)
|
if (scale == 1)
|
||||||
fraction = value % 10;
|
fraction = value % 10;
|
||||||
@ -787,9 +787,6 @@ SQUAD CVT_get_quad(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
SQUAD value;
|
SQUAD value;
|
||||||
#ifdef NATIVE_QUAD
|
|
||||||
SLONG fraction;
|
|
||||||
#endif
|
|
||||||
double d;
|
double d;
|
||||||
TEXT buffer[50]; /* long enough to represent largest quad in ASCII */
|
TEXT buffer[50]; /* long enough to represent largest quad in ASCII */
|
||||||
|
|
||||||
@ -897,7 +894,7 @@ SQUAD CVT_get_quad(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
if (desc->dsc_dtype == dtype_short ||
|
if (desc->dsc_dtype == dtype_short ||
|
||||||
desc->dsc_dtype == dtype_long || desc->dsc_dtype == dtype_quad)
|
desc->dsc_dtype == dtype_long || desc->dsc_dtype == dtype_quad)
|
||||||
{
|
{
|
||||||
fraction = 0;
|
SLONG fraction = 0;
|
||||||
do {
|
do {
|
||||||
if (scale == 1)
|
if (scale == 1)
|
||||||
fraction = value % 10;
|
fraction = value % 10;
|
||||||
@ -947,7 +944,6 @@ SINT64 CVT_get_int64(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
SINT64 value;
|
SINT64 value;
|
||||||
SLONG fraction;
|
|
||||||
double d, eps;
|
double d, eps;
|
||||||
TEXT buffer[50]; /* long enough to represent largest SINT64 in ASCII */
|
TEXT buffer[50]; /* long enough to represent largest SINT64 in ASCII */
|
||||||
|
|
||||||
@ -1053,7 +1049,7 @@ SINT64 CVT_get_int64(const dsc* desc, SSHORT scale, FPTR_ERROR err)
|
|||||||
if (desc->dsc_dtype == dtype_short ||
|
if (desc->dsc_dtype == dtype_short ||
|
||||||
desc->dsc_dtype == dtype_long || desc->dsc_dtype == dtype_int64)
|
desc->dsc_dtype == dtype_long || desc->dsc_dtype == dtype_int64)
|
||||||
{
|
{
|
||||||
fraction = 0;
|
SLONG fraction = 0;
|
||||||
do {
|
do {
|
||||||
if (scale == 1)
|
if (scale == 1)
|
||||||
fraction = (SLONG) (value % 10);
|
fraction = (SLONG) (value % 10);
|
||||||
@ -1301,15 +1297,7 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
* Move (and possible convert) something to something else.
|
* Move (and possible convert) something to something else.
|
||||||
*
|
*
|
||||||
**************************************/
|
**************************************/
|
||||||
SSHORT fill;
|
|
||||||
SLONG l;
|
SLONG l;
|
||||||
UCHAR *ptr;
|
|
||||||
USHORT strtype;
|
|
||||||
#if !defined(REQUESTER) && !defined(SUPERCLIENT)
|
|
||||||
CHARSET_ID charset1, charset2;
|
|
||||||
#endif
|
|
||||||
UCHAR fill_char;
|
|
||||||
|
|
||||||
SLONG length = from->dsc_length;
|
SLONG length = from->dsc_length;
|
||||||
UCHAR* p = to->dsc_address;
|
UCHAR* p = to->dsc_address;
|
||||||
const UCHAR* q = from->dsc_address;
|
const UCHAR* q = from->dsc_address;
|
||||||
@ -1535,6 +1523,7 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
|
|
||||||
#ifndef REQUESTER
|
#ifndef REQUESTER
|
||||||
#ifndef SUPERCLIENT
|
#ifndef SUPERCLIENT
|
||||||
|
CHARSET_ID charset1, charset2;
|
||||||
if ((INTL_TTYPE(from) == ttype_dynamic) && (err == ERR_post))
|
if ((INTL_TTYPE(from) == ttype_dynamic) && (err == ERR_post))
|
||||||
charset1 = INTL_charset(NULL, INTL_TTYPE(from));
|
charset1 = INTL_charset(NULL, INTL_TTYPE(from));
|
||||||
else
|
else
|
||||||
@ -1569,17 +1558,26 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
length = l =
|
{ // scope
|
||||||
CVT_get_string_ptr(from, &strtype, &ptr, NULL, 0, err);
|
USHORT strtype_unused;
|
||||||
q = ptr;
|
UCHAR *ptr;
|
||||||
|
length = l =
|
||||||
|
CVT_get_string_ptr(from, &strtype_unused, &ptr, NULL, 0, err);
|
||||||
|
q = ptr;
|
||||||
|
} // end scope
|
||||||
|
|
||||||
USHORT to_size = TEXT_LEN(to);
|
USHORT to_size = TEXT_LEN(to);
|
||||||
UCHAR* start = to->dsc_address;
|
UCHAR* start = to->dsc_address;
|
||||||
|
UCHAR fill_char = ASCII_SPACE;
|
||||||
#if !defined(REQUESTER) && !defined(SUPERCLIENT)
|
#if !defined(REQUESTER) && !defined(SUPERCLIENT)
|
||||||
CharSet* toCharSet = (err != ERR_post || charset2 == ttype_dynamic || charset2 == CS_METADATA ?
|
CharSet* toCharSet = (err != ERR_post || charset2 == ttype_dynamic || charset2 == CS_METADATA ?
|
||||||
NULL : INTL_charset_lookup(NULL, charset2));
|
NULL : INTL_charset_lookup(NULL, charset2));
|
||||||
|
if (charset2 == ttype_binary)
|
||||||
|
fill_char = 0x00;
|
||||||
|
|
||||||
USHORT toLength;
|
USHORT toLength;
|
||||||
#endif
|
#endif
|
||||||
|
int fill;
|
||||||
|
|
||||||
switch (to->dsc_dtype) {
|
switch (to->dsc_dtype) {
|
||||||
case dtype_text:
|
case dtype_text:
|
||||||
@ -1593,18 +1591,10 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
l -= length;
|
l -= length;
|
||||||
/* TMN: Here we should really have the following fb_assert */
|
/* TMN: Here we should really have the following fb_assert */
|
||||||
/* fb_assert((to->dsc_length - length) <= MAX_SSHORT); */
|
/* fb_assert((to->dsc_length - length) <= MAX_SSHORT); */
|
||||||
fill = (SSHORT) (to->dsc_length - length);
|
fill = to->dsc_length - length;
|
||||||
|
|
||||||
CVT_COPY_BUFF(q, p, length);
|
CVT_COPY_BUFF(q, p, length);
|
||||||
if (fill > 0) {
|
if (fill > 0) {
|
||||||
#ifndef REQUESTER
|
|
||||||
#ifndef SUPERCLIENT
|
|
||||||
if (charset2 == ttype_binary)
|
|
||||||
fill_char = 0x00;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
fill_char = ASCII_SPACE;
|
|
||||||
do {
|
do {
|
||||||
*p++ = fill_char;
|
*p++ = fill_char;
|
||||||
} while (--fill);
|
} while (--fill);
|
||||||
@ -1666,13 +1656,12 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (l) {
|
if (l) {
|
||||||
/* scan the truncated string to ensure only spaces lost */
|
// Scan the truncated string to ensure only spaces lost
|
||||||
/* Note: it is correct only for narrow and multi-byte
|
// Warning: it is correct only for narrow and multi-byte
|
||||||
character sets which use ASCII for the SPACE
|
// character sets which use ASCII or NULL for the SPACE character
|
||||||
character. */
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (*q++ != ASCII_SPACE)
|
if (*q++ != fill_char)
|
||||||
(*err) (isc_arith_except, 0);
|
(*err) (isc_arith_except, 0);
|
||||||
} while (--l);
|
} while (--l);
|
||||||
}
|
}
|
||||||
@ -1757,8 +1746,7 @@ void CVT_move(const dsc* from, dsc* to, FPTR_ERROR err)
|
|||||||
|
|
||||||
case dtype_real:
|
case dtype_real:
|
||||||
{
|
{
|
||||||
double d_value;
|
double d_value = CVT_get_double(from, err);
|
||||||
d_value = CVT_get_double(from, err);
|
|
||||||
if (ABSOLUT(d_value) > FLOAT_MAX)
|
if (ABSOLUT(d_value) > FLOAT_MAX)
|
||||||
(*err) (isc_arith_except, 0);
|
(*err) (isc_arith_except, 0);
|
||||||
*(float*) p = (float) d_value;
|
*(float*) p = (float) d_value;
|
||||||
@ -1982,7 +1970,8 @@ static SSHORT decompose(const char* string,
|
|||||||
errd.dsc_address = reinterpret_cast<UCHAR*>(const_cast<char*>(string));
|
errd.dsc_address = reinterpret_cast<UCHAR*>(const_cast<char*>(string));
|
||||||
|
|
||||||
SINT64 value = 0;
|
SINT64 value = 0;
|
||||||
SSHORT scale = 0, sign = 0;
|
SSHORT scale = 0;
|
||||||
|
int sign = 0;
|
||||||
bool digit_seen = false, fraction = false;
|
bool digit_seen = false, fraction = false;
|
||||||
const SINT64 lower_limit = (dtype == dtype_long) ? MIN_SLONG : MIN_SINT64;
|
const SINT64 lower_limit = (dtype == dtype_long) ? MIN_SLONG : MIN_SINT64;
|
||||||
const SINT64 upper_limit = (dtype == dtype_long) ? MAX_SLONG : MAX_SINT64;
|
const SINT64 upper_limit = (dtype == dtype_long) ? MAX_SLONG : MAX_SINT64;
|
||||||
@ -2618,7 +2607,7 @@ static void string_to_datetime(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tm times, times2;
|
tm times;
|
||||||
memset(×, 0, sizeof(times));
|
memset(×, 0, sizeof(times));
|
||||||
|
|
||||||
if (expect_type != expect_sql_time) {
|
if (expect_type != expect_sql_time) {
|
||||||
@ -2679,6 +2668,7 @@ static void string_to_datetime(
|
|||||||
times.tm_mday = components[position_day];
|
times.tm_mday = components[position_day];
|
||||||
|
|
||||||
// Fetch current date/time
|
// Fetch current date/time
|
||||||
|
tm times2;
|
||||||
Firebird::TimeStamp().decode(×2);
|
Firebird::TimeStamp().decode(×2);
|
||||||
|
|
||||||
/* Handle defaulting of year */
|
/* Handle defaulting of year */
|
||||||
@ -2724,6 +2714,7 @@ static void string_to_datetime(
|
|||||||
|
|
||||||
isc_encode_timestamp(×, date);
|
isc_encode_timestamp(×, date);
|
||||||
if (expect_type != expect_sql_time) {
|
if (expect_type != expect_sql_time) {
|
||||||
|
tm times2;
|
||||||
isc_decode_timestamp(date, ×2);
|
isc_decode_timestamp(date, ×2);
|
||||||
|
|
||||||
if ((times.tm_year + 1900) < MIN_YEAR
|
if ((times.tm_year + 1900) < MIN_YEAR
|
||||||
|
Loading…
Reference in New Issue
Block a user