@@ -3324,32 +3324,63 @@ bool Protocol_text::store_decimal(const my_decimal *d, uint prec, uint dec) {
3324
3324
packet);
3325
3325
}
3326
3326
3327
- bool Protocol_text::store_float (float from, uint32 decimals, uint32 zerofill,
3328
- String *buffer) {
3327
+ /* *
3328
+ Converts a floating-point value to text for the text protocol.
3329
+
3330
+ @param value the floating point value
3331
+ @param decimals the precision of the value
3332
+ @param gcvt_arg_type the type of the floating-point value
3333
+ @param buffer a buffer large enough to hold FLOATING_POINT_BUFFER
3334
+ characters plus a terminating zero character
3335
+ @return the length of the text representation of the value
3336
+ */
3337
+ static size_t floating_point_to_text (double value, uint32 decimals,
3338
+ my_gcvt_arg_type gcvt_arg_type,
3339
+ char *buffer) {
3340
+ if (decimals < DECIMAL_NOT_SPECIFIED)
3341
+ return my_fcvt (value, decimals, buffer, nullptr );
3342
+ return my_gcvt (value, gcvt_arg_type, FLOATING_POINT_BUFFER, buffer, nullptr );
3343
+ }
3344
+
3345
+ /* *
3346
+ Stores a floating-point value in the text protocol.
3347
+
3348
+ @param value the floating point value
3349
+ @param decimals the precision of the value
3350
+ @param zerofill the length up to which the value should be zero-padded,
3351
+ or 0 if no zero-padding should be used
3352
+ @param gcvt_arg_type the type of the floating-point value
3353
+ @param packet the destination buffer
3354
+ @return false on success, true on error
3355
+ */
3356
+ static bool store_floating_point (double value, uint32 decimals, uint32 zerofill,
3357
+ my_gcvt_arg_type gcvt_arg_type,
3358
+ String *packet) {
3359
+ char buffer[FLOATING_POINT_BUFFER + 1 ];
3360
+ size_t length =
3361
+ floating_point_to_text (value, decimals, gcvt_arg_type, buffer);
3362
+ if (zerofill != 0 )
3363
+ return net_store_zero_padded_data (buffer, length, zerofill, packet);
3364
+ return net_store_data (pointer_cast<const uchar *>(buffer), length, packet);
3365
+ }
3366
+
3367
+ bool Protocol_text::store_float (float from, uint32 decimals, uint32 zerofill) {
3329
3368
// field_types check is needed because of the embedded protocol
3330
3369
DBUG_ASSERT (send_metadata || field_types == 0 ||
3331
3370
field_types[field_pos] == MYSQL_TYPE_FLOAT);
3332
3371
field_pos++;
3333
- buffer->set_float (from, decimals, m_thd->charset ());
3334
- if (zerofill != 0 )
3335
- return net_store_zero_padded_data (buffer->ptr (), buffer->length (), zerofill,
3336
- packet);
3337
- return net_store_data (pointer_cast<const uchar *>(buffer->ptr ()),
3338
- buffer->length (), packet);
3372
+ return store_floating_point (from, decimals, zerofill, MY_GCVT_ARG_FLOAT,
3373
+ packet);
3339
3374
}
3340
3375
3341
- bool Protocol_text::store_double (double from, uint32 decimals, uint32 zerofill,
3342
- String *buffer ) {
3376
+ bool Protocol_text::store_double (double from, uint32 decimals,
3377
+ uint32 zerofill ) {
3343
3378
// field_types check is needed because of the embedded protocol
3344
3379
DBUG_ASSERT (send_metadata || field_types == 0 ||
3345
3380
field_types[field_pos] == MYSQL_TYPE_DOUBLE);
3346
3381
field_pos++;
3347
- buffer->set_real (from, decimals, m_thd->charset ());
3348
- if (zerofill != 0 )
3349
- return net_store_zero_padded_data (buffer->ptr (), buffer->length (), zerofill,
3350
- packet);
3351
- return net_store_data (pointer_cast<const uchar *>(buffer->ptr ()),
3352
- buffer->length (), packet);
3382
+ return store_floating_point (from, decimals, zerofill, MY_GCVT_ARG_DOUBLE,
3383
+ packet);
3353
3384
}
3354
3385
3355
3386
/* *
@@ -3589,10 +3620,10 @@ bool Protocol_binary::store_longlong(longlong from, bool unsigned_flag,
3589
3620
return 0 ;
3590
3621
}
3591
3622
3592
- bool Protocol_binary::store_float (float from, uint32 decimals, uint32 zerofill,
3593
- String *buffer ) {
3623
+ bool Protocol_binary::store_float (float from, uint32 decimals,
3624
+ uint32 zerofill ) {
3594
3625
if (send_metadata)
3595
- return Protocol_text::store_float (from, decimals, zerofill, buffer );
3626
+ return Protocol_text::store_float (from, decimals, zerofill);
3596
3627
// field_types check is needed because of the embedded protocol
3597
3628
DBUG_ASSERT (field_types == nullptr ||
3598
3629
field_types[field_pos] == MYSQL_TYPE_FLOAT);
@@ -3604,9 +3635,9 @@ bool Protocol_binary::store_float(float from, uint32 decimals, uint32 zerofill,
3604
3635
}
3605
3636
3606
3637
bool Protocol_binary::store_double (double from, uint32 decimals,
3607
- uint32 zerofill, String *buffer ) {
3638
+ uint32 zerofill) {
3608
3639
if (send_metadata)
3609
- return Protocol_text::store_double (from, decimals, zerofill, buffer );
3640
+ return Protocol_text::store_double (from, decimals, zerofill);
3610
3641
// field_types check is needed because of the embedded protocol
3611
3642
DBUG_ASSERT (field_types == nullptr ||
3612
3643
field_types[field_pos] == MYSQL_TYPE_DOUBLE);
0 commit comments