| 413 | |
| 414 | |
| 415 | void PgWriter::writeTile(const PointViewPtr view) |
| 416 | { |
| 417 | std::vector<char> storage(packedPointSize()); |
| 418 | std::string hexrep; |
| 419 | size_t maxHexrepSize = packedPointSize() * view->size() * 2; |
| 420 | hexrep.reserve(maxHexrepSize); |
| 421 | |
| 422 | m_insert.clear(); |
| 423 | m_insert.reserve(maxHexrepSize + 3000); |
| 424 | |
| 425 | for (PointId idx = 0; idx < view->size(); ++idx) |
| 426 | { |
| 427 | size_t size = readPoint(*view.get(), idx, storage.data()); |
| 428 | |
| 429 | /* We are always getting uncompressed bytes off the block_data */ |
| 430 | /* so we always used compression type 0 (uncompressed) in writing */ |
| 431 | /* our WKB */ |
| 432 | static char syms[] = "0123456789ABCDEF"; |
| 433 | for (size_t i = 0; i != size; i++) |
| 434 | { |
| 435 | hexrep.push_back(syms[((storage[i] >> 4) & 0xf)]); |
| 436 | hexrep.push_back(syms[storage[i] & 0xf]); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | std::string insert_into("INSERT INTO "); |
| 441 | std::string values(" (" + pg_quote_identifier(m_column_name) + |
| 442 | ") VALUES ('"); |
| 443 | |
| 444 | m_insert.append(insert_into); |
| 445 | |
| 446 | if (m_schema_name.size()) |
| 447 | { |
| 448 | m_insert.append(pg_quote_identifier(m_schema_name)); |
| 449 | m_insert.append("."); |
| 450 | } |
| 451 | |
| 452 | m_insert.append(pg_quote_identifier(m_table_name)); |
| 453 | m_insert.append(values); |
| 454 | |
| 455 | std::ostringstream options; |
| 456 | |
| 457 | if (view->size() > (std::numeric_limits<uint32_t>::max)()) |
| 458 | throwError("Too many points for tile."); |
| 459 | uint32_t num_points = htobe32(static_cast<uint32_t>(view->size())); |
| 460 | int32_t pcid = htobe32(m_pcid); |
| 461 | CompressionType compression_v = CompressionType::None; |
| 462 | uint32_t compression = htobe32(static_cast<uint32_t>(compression_v)); |
| 463 | |
| 464 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 465 | options << "01"; |
| 466 | #elif BYTE_ORDER == BIG_ENDIAN |
| 467 | options << "00"; |
| 468 | #endif |
| 469 | |
| 470 | // needs to be 4 bytes |
| 471 | options << std::hex << std::setfill('0') << std::setw(8) << pcid; |
| 472 | // needs to be 4 bytes |
nothing calls this directly
no test coverage detected