| 348 | } |
| 349 | |
| 350 | bool RowBuilder::AppendValue(const std::string& val) { |
| 351 | bool ok = false; |
| 352 | const ::fedb::common::ColumnDesc& col = schema_.Get(cnt_); |
| 353 | try { |
| 354 | switch (col.data_type()) { |
| 355 | case fedb::type::kString: |
| 356 | case fedb::type::kVarchar: |
| 357 | ok = AppendString(val.c_str(), val.length()); |
| 358 | break; |
| 359 | case fedb::type::kBool: { |
| 360 | std::string b_val = val; |
| 361 | std::transform(b_val.begin(), b_val.end(), b_val.begin(), |
| 362 | ::tolower); |
| 363 | if (b_val == "true") { |
| 364 | ok = AppendBool(true); |
| 365 | } else if (b_val == "false") { |
| 366 | ok = AppendBool(false); |
| 367 | } else { |
| 368 | ok = false; |
| 369 | } |
| 370 | break; |
| 371 | } |
| 372 | case fedb::type::kSmallInt: |
| 373 | ok = AppendInt16(boost::lexical_cast<int16_t>(val)); |
| 374 | break; |
| 375 | case fedb::type::kInt: |
| 376 | ok = AppendInt32(boost::lexical_cast<int32_t>(val)); |
| 377 | break; |
| 378 | case fedb::type::kBigInt: |
| 379 | ok = AppendInt64(boost::lexical_cast<int64_t>(val)); |
| 380 | break; |
| 381 | case fedb::type::kTimestamp: |
| 382 | ok = AppendTimestamp(boost::lexical_cast<int64_t>(val)); |
| 383 | break; |
| 384 | case fedb::type::kFloat: |
| 385 | ok = AppendFloat(boost::lexical_cast<float>(val)); |
| 386 | break; |
| 387 | case fedb::type::kDouble: |
| 388 | ok = AppendDouble(boost::lexical_cast<double>(val)); |
| 389 | break; |
| 390 | case fedb::type::kDate: { |
| 391 | std::vector<std::string> parts; |
| 392 | ::fedb::base::SplitString(val, "-", parts); |
| 393 | if (parts.size() != 3) { |
| 394 | ok = false; |
| 395 | break; |
| 396 | } |
| 397 | uint32_t year = boost::lexical_cast<uint32_t>(parts[0]); |
| 398 | uint32_t mon = boost::lexical_cast<uint32_t>(parts[1]); |
| 399 | uint32_t day = boost::lexical_cast<uint32_t>(parts[2]); |
| 400 | ok = AppendDate(year, mon, day); |
| 401 | break; |
| 402 | } |
| 403 | default: |
| 404 | ok = false; |
| 405 | } |
| 406 | } catch (std::exception const& e) { |
| 407 | ok = false; |
no test coverage detected