Skip to content

Commit eb419cb

Browse files
committed
use fmtlib instead
1 parent f667321 commit eb419cb

4 files changed

Lines changed: 10 additions & 17 deletions

File tree

c/driver/framework/base_driver.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <arrow-adbc/adbc.h>
3232

33+
#include "fmt/core.h"
34+
3335
#include "driver/framework/status.h"
3436

3537
/// \file base.h ADBC Driver Framework
@@ -170,19 +172,16 @@ class Option {
170172
using T = std::decay_t<decltype(value)>;
171173
if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, int64_t> ||
172174
std::is_same_v<T, double>) {
173-
char formatted[24]; // Enough room for double/int64_t
174175
std::string_view string_value;
175-
if constexpr (std::is_same_v<T, std::string>) {
176-
string_value = value;
176+
std::string allocated_value;
177+
if constexpr (std::is_same_v<T, int64_t>) {
178+
allocated_value = fmt::format("{}", value);
179+
string_value = allocated_value;
180+
} else if constexpr (std::is_same_v<T, double>) {
181+
allocated_value = fmt::format("{}", value);
182+
string_value = allocated_value;
177183
} else {
178-
auto result =
179-
std::to_chars(formatted, formatted + sizeof(formatted), value);
180-
if (result.ec != std::errc()) {
181-
return status::Internal("Could not format numeric option value")
182-
.ToAdbc(error);
183-
}
184-
string_value = std::string_view(
185-
formatted, static_cast<size_t>(result.ptr - formatted));
184+
string_value = value;
186185
}
187186
size_t value_size_with_terminator = string_value.size() + 1;
188187
if (*length >= value_size_with_terminator) {

c/driver/framework/status.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
#include <variant>
2727
#include <vector>
2828

29-
#if defined(ADBC_FRAMEWORK_USE_FMT)
3029
#include <fmt/core.h>
3130
#include <fmt/format.h>
32-
#endif
3331

3432
#include <arrow-adbc/adbc.h>
3533

@@ -326,7 +324,6 @@ STATUS_CTOR(Unknown, UNKNOWN)
326324

327325
} // namespace adbc::driver::status
328326

329-
#if defined(ADBC_FRAMEWORK_USE_FMT)
330327
namespace adbc::driver::status::fmt {
331328

332329
#define STATUS_CTOR(NAME, CODE) \
@@ -348,7 +345,6 @@ STATUS_CTOR(Unknown, UNKNOWN)
348345
#undef STATUS_CTOR
349346

350347
} // namespace adbc::driver::status::fmt
351-
#endif
352348

353349
#define UNWRAP_ERRNO_IMPL(NAME, CODE, RHS) \
354350
do { \

c/driver/postgresql/result_helper.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <string>
2828
#include <vector>
2929

30-
#define ADBC_FRAMEWORK_USE_FMT
3130
#include "driver/framework/status.h"
3231
#include "error.h"
3332

c/driver/sqlite/sqlite.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <sqlite3.h>
2727
#include <nanoarrow/nanoarrow.hpp>
2828

29-
#define ADBC_FRAMEWORK_USE_FMT
3029
#include "driver/framework/base_driver.h"
3130
#include "driver/framework/connection.h"
3231
#include "driver/framework/database.h"

0 commit comments

Comments
 (0)