Open bold84 opened 3 months ago
Converting from UTF-16 to UTF-8 is no problem when retrieving data, because the column data type is known. When inserting/updating though, it is not so straightforward, as we don't have programmatic knowledge of the column data type in advance.
I'm thinking of adding another argument to "soci::use()" that lets the developer override the data type that's used for the underlying ODBC call.
Another issue is the currently non-existing N'' enclosure for unicode strings for MSSQL in case of soci::use().
Another issue is the stream interface. Currently std::wstring isn't supported and as far as I understand, supporting it would require widening the query to UTF-16 before sending it to the DB.
Please note that I updated the FreeBSD Image for Cirrus from 13.2 to 13.3.
I'm adding better UTF conversion first.
This pull request adds comprehensive support for wide strings (
wchar_t
,std::wstring
) to the SOCI database library, significantly improving its support for Unicode string types such as SQL Server'sNVARCHAR
andNTEXT
. This enhancement is crucial for applications that require robust handling of international and multi-language data.Key Changes:
Introduced
exchange_type_traits
andexchange_traits
Specializations:Updated ODBC Backend:
wchar_t
andstd::wstring
.Enhanced Buffer Management:
Improved Unicode Support:
Extended Test Coverage:
Notes:
This update significantly bolsters SOCI's capabilities in handling Unicode data, making it a more versatile and powerful tool for database interactions in multi-language applications.
Example usage
Here are a few examples showing how the new wide string features can be used with the ODBC backend.
Example 1: Handling
std::wstring
in SQL QueriesInserting and Selecting
std::wstring
DataExample 2: Working with
wchar_t
VectorsInserting and Selecting Wide Characters
Example 3: Using
std::wstring
with thesql
Stream OperatorInserting and Selecting
std::wstring
Data with Stream OperatorIn this example:
soci::session
object is created to connect to the database.NVARCHAR
column.std::wstring
is defined for insertion.sql
stream operator is used to insert thestd::wstring
into the database. Note the use ofN'
to indicate a Unicode string in SQL Server.std::wstring
is retrieved from the database using thesql
stream operator and thesoci::into
function.std::wcout
.These examples demonstrate how to insert and retrieve wide strings and wide characters using SOCI's newly added features for handling wide strings (
wchar_t
,std::wstring
).Disclaimer: This text is AI generated.