Warning, /sdk/codevis/thirdparty/soci/docs/lobs.md is written in an unsupported language. File is not indexed.

0001 # Large Objects (LOBs)
0002 
0003 ## Binary (BLOBs)
0004 
0005 The SOCI library provides also an interface for basic operations on large objects (BLOBs - Binary Large OBjects).
0006 
0007     blob b(sql); // sql is a session object
0008     sql << "select mp3 from mymusic where id = 123", into(b);
0009 
0010 The following functions are provided in the `blob` interface, mimicking the file-like operations:
0011 
0012 * `std::size_t get_len();`
0013 * `std::size_t read_from_start(char * buf, std::size_t toRead, std::size_t offset = 0);`
0014 * `std::size_t write_from_start(const char * buf, std::size_t toWrite, std::size_t offset = 0);`
0015 * `std::size_t append(char const *buf, std::size_t toWrite);`
0016 * `void trim(std::size_t newLen);`
0017 
0018 The `offset` parameter is always counted from the beginning of the BLOB's data.
0019 
0020 ### Portability notes
0021 
0022 * The way to define BLOB table columns and create or destroy BLOB objects in the database varies between different database engines.
0023   Please see the SQL documentation relevant for the given server to learn how this is actually done. The test programs provided with the SOCI library can be also a simple source of full working examples.
0024 * The `trim` function is not currently available for the PostgreSQL backend.
0025 
0026 ## Long strings and XML
0027 
0028 The SOCI library recognizes the fact that long string values are not handled portably and in some databases long string values need to be stored as a different data type.
0029 Similar concerns relate to the use of XML values, which are essentially strings at the application level, but can be stored in special database-level field types.
0030 
0031 In order to facilitate handling of long strings and XML values the following wrapper types are defined:
0032 
0033     struct xml_type
0034     {
0035         std::string value;
0036     };
0037 
0038     struct long_string
0039     {
0040         std::string value;
0041     };
0042 
0043 Values of these wrapper types can be used with `into` and `use` elements with the database target type that is specifically intended to handle XML and long strings data types.
0044 
0045 For Oracle, these database-side types are, respectively:
0046 
0047 * `XMLType`,
0048 * `CLOB`
0049 
0050 For PostgreSQL, these types are:
0051 
0052 * `XML`
0053 * `text`
0054 
0055 For Firebird, there is no special XML support, but `BLOB SUB_TYPE TEXT` can be
0056 used for storing it, as well as long strings.
0057 
0058 For ODBC backend, these types depend on the type of the database connected to.
0059 In particularly important special case of Microsoft SQL Server, these types
0060 are:
0061 
0062 * `xml`
0063 * `text`
0064 
0065 When using ODBC backend to connect to a PostgreSQL database, please be aware
0066 that by default PostgreSQL ODBC driver truncates all "unknown" types, such as
0067 XML, to maximal varchar type size which is just 256 bytes and so is often
0068 insufficient for XML values in practice. It is advised to set the
0069 `UnknownsAsLongVarchar` connection option to 1 to avoid truncating XML strings
0070 or use PostgreSQL ODBC driver 9.6.300 or later, which allows the backend to set
0071 this option to 1 automatically on connection.