Hey again koen, Im using the blog example, looking at the code and how its structured, plus using your library descriptions to try and understand how I would adopt the connection pool to my application. Im a little uncertain about something here and feel like asking you a question. First, let me paste a little part of the code from BlogSession:
BlogSession::BlogSession(dbo::SqlConnectionPool& connectionPool) : connectionPool_(connectionPool), users_(*this) { setConnectionPool(connectionPool_); mapClass<Comment>("comment"); mapClass<Post>("post"); The way I used mapClass before, I preceded it with the session created by the connection, but here is seems like setConnectionPool creates a connection/session for the method, but is it then owned by users_(*this) <-I assume this is the user that logs on his blog and so on. The issue I run into is that I dont have any users defined, the application is not going to allow more than one user to access the db simultaneously (this is defined in the specification of its functionality). And I have a feeling that the binding of users_(*this) is part of defining the connection. Im sorry I dont have more experience with c++, but Im trying hard. When I remove users_(*this), I get errors that both setConnectionPool and mapClass are undeclared identifiers. But Ive used session.mapClass previous in my methods in the same class… How do I do this? I understand that I need to somehow append session to the whole class, dont I? 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
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