Are there any STL containers that seem to be well-suited for using as BLOBs for database software? I would think a vector<char>
, but is there something better? Maybe a std::string
? Or some non-STL container?
相关问题
- Views base64 encoded blob in HTML with PHP
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
The
BLOB
type of databases allows storage of binary data, so you need an ordered collection of bytes. The easiest choice would be avector<>
and you could choseunsigned char
to represent a byte on most platformsWe have used
stream
s in one of our projects to represent BLOB/CLOB values stored in the database. I think this is most of the time the best approach, as BLOB/CLOBs could be really large to fit in memory by definition.Write a
stream
implementation of your own and use it just like any otherstream
.I'm currently using
std::string
to store blobs, since I'm using Google's Protocol Buffers library for object serialization, and that's what they use (e.g., MessageLite::SerializeToString). It works well for my purposes since inserting the resulting string as a blob into an SQLite database is very straightforward:(
data
is astd::string
being bound as the third argument to_insert_statement
.)