[odb-users] SQLite and std::wstring

philly.dilly at gmail.com philly.dilly at gmail.com
Sun Jun 10 21:54:21 EDT 2012


Hi Boris,
I was indeed planning on using utf8 in database since utf8 is rarely bigger  
than utf16 but often smaller. Considering database are often IO bound  
rather than cpu bound, it seems like the conversion is a small price to pay  
for potentially better throughput. I played around a little bit trying to  
implement specialization of class odb::sqlite::value_traits<std::wstring,  
id_text> however it seems like the odb compiler doesn't like that I include  
<codecvt>. Furthermore, this step seems superfluous since sqlite natively  
supports utf16. When I have some more time, I might play around with adding  
the value text16 to enum odb::sqlite::bind::buffer_type which will use the  
native sqlite utf16 api since it seems to me like the logical way to add  
utf16 support. That being said, I clearly don't fully understand odb yet so  
I may be going in the completely wrong direction :D

Cheers,
Phil

On , Boris Kolpackov <boris at codesynthesis.com> wrote:
> Hi Phil,



> philly.dilly at gmail.com philly.dilly at gmail.com> writes:



> > Although utf8 is generally a more compact encoding, in my case I will be

> > using wstring since my application deals with a lot of non latin

> > languages and processing utf16 is a lot easier.



> Yes, I understand that you want to use wstring/UTF-16 in the application.

> What I was curious about is which encoding you were planning to use in

> the database (you have a choice of UTF-8 or UTF-16, and it seems UTF-8 is

> generally recommended since it results in a more compact database and thus

> better performance).





> > I tried mapping std::wstring to TEXT with pragmas but then I got some

> > compilation errors about wrong number of arguments or something.



> Yes, since there is not built-in support for std::wstring (yet), you will

> need to implement a value_traits specialization for it which will need to

> convert to/from UTF-8, since that's the only "image" currently supported

> by ODB for SQLite TEXT. The 'mapping' example has more information on how

> to do this.



> Boris




More information about the odb-users mailing list