On Wed, Jul 8, 2009 at 1:00 AM, M. Frey<[email protected]> wrote:
> I tried to declare a SOCI::Session object as reference-variable in my
> class Recorder.
>
> private:
> SOCI::Session& sqlSession;
>
> Of course I have to initialize this reference in the initialisation list
> of the constructor. I do this as follows:
>
> Recorder::Recorder(std::string pathToDB) :
> sqlSession( SOCI::Session(SOCI::sqlite3, pathToDB))
> {
> //.... constructor body
> }
>
> Now I got the following error:
> /Recorder.cpp: In constructor 'core::Recorder::Recorder(std::string)':
> ../Recorder.cpp:14: error: invalid initialization of non-const reference
> of type 'SOCI::Session&' from a temporary of type 'SOCI::Session'
>
> Is there another way to initialise a SOCI::Session object in a class?
> The =operator is private and I would like to avoid the use of pointer
> variables...
Hi Maurus, thanks for using SOCI!
I understand you want to share one session between multiple instances
of Recorder. A simple solution is to have a global session object and
keep a pointer to it in all recorders. If you want to get fancy you
can use a reference counted smart pointer, like, e.g.,
http://www.boost.org/doc/libs/1_39_0/libs/smart_ptr/shared_ptr.htm
Keep in mind that you can only do it as long as all recorders are used
in the same thread. SOCI::Session is not thread safe which means you
cannot access one session concurrently from multiple threads.
> I'm currently using SOCI V.2. What happen to the sqlite3 support in
> version 3? There is no sqlite back-end included any more. So SOCI
> dropped the sqlite support?
I think it's still in the repository. We haven't included it in the
release because it hasn't been tested much, but you should be able to
check it out from git and use it.
Best regards,
Aleksander
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users