Copilot commented on code in PR #4878:
URL: https://github.com/apache/arrow-adbc/pull/4878#discussion_r4244224458


##########
c/driver/sqlite/statement_reader.c:
##########
@@ -953,27 +953,30 @@ AdbcStatusCode 
InternalSqliteStatementReaderAppendDoubleToBinary(
     struct ArrowBuffer* offsets, struct ArrowBuffer* binary, double value,
     int32_t* offset, struct AdbcError* error) {
   static const size_t kReserve = 64;
-  size_t buffer_size = kReserve;
-  CHECK_NA(INTERNAL, ArrowBufferReserve(binary, buffer_size), error);
+  CHECK_NA(INTERNAL, ArrowBufferReserve(binary, kReserve), error);
   char* output = (char*)(binary->data + binary->size_bytes);
-  int written = 0;
-  while (1) {
-    written = snprintf(output, buffer_size, "%e", value);
-    if (written < 0) {
-      InternalAdbcSetError(error, "Encoding error when upcasting double to 
string");
-      return ADBC_STATUS_INTERNAL;
-    } else if (((size_t)written) >= buffer_size) {
-      // Truncated, resize and try again
-      // Check for overflow - presumably this can never happen...?
-      if (UINT_MAX - buffer_size < buffer_size) {
-        InternalAdbcSetError(error, "Overflow when upcasting double to 
string");
-        return ADBC_STATUS_INTERNAL;
-      }
-      CHECK_NA(INTERNAL, ArrowBufferReserve(binary, buffer_size), error);
-      buffer_size += buffer_size;
-      continue;
+  // Keep enough significant digits to round-trip the binary64 value. SQLite's
+  // printf precision can be capped by the linked SQLite build, so use libc for
+  // finite values and SQLite's formatter for its non-finite spellings.
+  int written;
+  if (isfinite(value)) {
+    written = snprintf(output, (int)kReserve, "%.17g", value);
+    if (written >= 0 && written < (int)kReserve - 2 && strchr(output, '.') == 
NULL) {

Review Comment:
   `snprintf("%.17g")` honors the process's `LC_NUMERIC`. With a decimal-comma 
locale, a value such as `1.5` is written as `1,5`; the following 
`strchr(output, '.')` then inserts `.0`, producing the invalid `1,5.0`. This 
makes query output locale-dependent and breaks round-tripping. Please use a 
locale-independent conversion (or safely normalize the locale decimal separator 
before the `.0` logic) and cover a decimal-comma locale in the regression test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to