You could use vector<unsigned char> as an alternative but essentially you
would be using this to handle the memory management. SQLBindParameter can
take &buf[0] or you could just have a raw pointer that points to &buf[0]
but would save using new[] and delete[] which is harder to maintain.

You can store a string in it, of course. You need to ensure that the length
of the vector is one more than the length of the string to store the null
terminator. vector will automatically initialise your bytes to 0 as well so
you don't have to actually copy that in and you can use std::string::copy
function to copy into the buffer, or vector's copy.

Of course you need to ensure that if you resize the vector upward and you
haven't reserved, you rebind your parameter as the buffer may have been
reallocated.

Incidentally SOCI is using a very poor implementation of auto_ptr. If
auto_ptr is bad enough, SOCI doesn't even get that right.

SOCI doesn't use shared_ptr because it doesn't force you to be using it.
There are some features of boost you can optionally use. shared_ptr is
standard in C++11 but we are not C++11 compliant yet.

On Thu, May 24, 2012 at 10:46 PM, Vadim Zeitlin <[email protected]>wrote:

> On Thu, 24 May 2012 22:31:29 +0100 Neil Morgenstern <
> [email protected]> wrote:
>
> NM> Let's fix this properly. Get rid of these raw pointers and use
> NM> vector<char>. Ensure it is bound properly too.
>
>  I don't think the code is really going to be simpler with vector<char>.
> And there is no better way to ensure that it's bound properly, as you don't
> really store strings in this vector (but also e.g. TIMESTAMP_STRUCT), you'd
> need to use memcpy() or reinterpret_cast<> anyhow. SQLBindParameter() is
> inherently type-unsafe and this code reflects it.
>
>  I'd consider using some smart pointer class automatically deleting the
> buffer but I don't see SOCI using any smart pointers right now and it's not
> worth to add another dependency just for this code.
>
>  Regards,
> VZ
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Soci-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/soci-users
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to