Hey koen,

Thanks for your guidance, I wasn’t thinking about the examples (again), that 
is, I was too immersed in the hands on guide and the examples there. I guess I 
should be better at remembering that the examples provide good leads.

Regards,
Tor


20. mars 2014 kl. 08:38 skrev Koen Deforche <k...@emweb.be>:

> Hey,
> 
> 2014-03-17 12:14 GMT+01:00 Tor Arne Fallingen <fallin...@gmail.com>:
> Hey,
> 
> Ive come to the point where I need to make a db handler class for our 
> project. I have a few things I need to be able to do, and that is either 
> creating a new job (which is only a new id number for a job, the table could 
> be the same, or a new table could be made), then I wish to be able to modify 
> my db data. What I was looking for was some way of initiating a database 
> connection in one method, and then I want to be able to send that 
> connection/session to my methods. Is this possible, or would I have to 
> initiate a connection for each task I want to do, and then close it again 
> after committing my data? I will log gps data, so Id like to make a 
> connection, then repeat my «submit gps data» every time I get a new valid 
> string.
> 
> The way I see it in the tutorial, I see only a connection being set up within 
> the method before doing all tasks the example calls for. Im not sure if this 
> makes sense, and I would go at it trying different angles a whole lot longer, 
> but we are running out of time here, so Im hoping to be able to get some help 
> here. Basically this is how Id wish to be able to do it:
> 
> Session dbSession(){
>       Wt::Dbo::backend::MySQL mysql("db", "root",  «pass", "127.0.0.1", 3306);
>     mysql.setProperty("show-queries", "true");
>     Wt::Dbo::Session session;
>     session.setConnection(mysql);
> 
>     return session;
> 
> }
> 
> The first problem with this is that the 'mysql' object is a local object that 
> is deleted after returning from this method. It needs to survive the session 
> lifetime. So if you change it to a heap-allocated object then this will work. 
> The second problem is the fact that you are returning the session by value, 
> which you cannot do. So this should probably also be a heap-allocated object.
> 
> There certainly is no problem with reorganizing the code to have the session 
> setup separately from the actual usage; this is done in the blog example as 
> well.
> 
> Regards,
> koen 
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech_______________________________________________
> witty-interest mailing list
> witty-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/witty-interest

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to