It probably shouldn't be a "singleton" but in any case you should use a
class member variable, and also have a class member variable to manage its
database connection
The role of the class is make a particular call to the database multiple
times. Of course you have to handle thread contention issues etc.
This is becoming a discussion though in good programming design and not
SOCI itself. You should use a member variable which should be private.
Preferably users of your class will be calling a function not caring how it
is implemented at all, so will have no idea that there is SOCI involved and
possibly not even know it is writing to a database.
Incidentally you might wish to measure the performance before you try to
optmise because rebinding a parameter is unlikely to be expensive in
reality, it is just assigning a value to some local memory and will be
trivial in the overall scheme of things.
The overhead of making the call is going to be the main expense and if it
is called a lot and you don't need the results written instantly you could
buffer a few values up then use the vector method of executing.
On Tue, May 8, 2012 at 9:54 PM, Vadim Zeitlin <[email protected]> wrote:
> On Mon, 7 May 2012 20:27:58 +0100 Neil Morgenstern <
> [email protected]> wrote:
>
> NM> They wouldn't be static variables they would be class member
> variables, so
> NM> in your case members of MyClass.
>
> It's true but in my case MyClass is a singleton so there is no essential
> difference between using static/global or member variables. The main
> problem is that I still need to keep all these extra variables and write
> code copying data to/from them instead of using the real data directly.
>
> It would be really much better if I could keep a prepared statement but
> just rebind the variables used in it. I know that it's not impossible to
> implement this as (SOCI-inspired, AFAICS) cppdb library does allow it, see
> the last example at http://cppcms.com/sql/cppdb/stat.html, but I don't see
> how to do it with SOCI yet... I wonder if I'm really the first person to be
> trying to do this? If so, why? Am I perhaps missing something and it's
> simply not worth trying to cache the prepared statements (e.g. because
> database keeps such cache internally anyhow)?
>
> NM> If you really are doing this a lot and want to optimise, consider
> using the
> NM> vector option.
>
> I can't do this, the values are read one by one and more or less
> unpredictably. I was just trying to save on the statement preparation here
> but, again, perhaps it's not really even worth doing it. I still find it
> strange if it's really not supported, I was hoping that I was just missing
> the right way to do it.
>
> 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