Project

General

Profile

Questions related to Dbo tutorial

Added by IW M about 10 years ago

/*

* Setup a session, would typically be done once at application startup.

*/

dbo::backend::Sqlite3 sqlite3("blog.db");

dbo::Session session;

session.setConnection(sqlite3);

With the above connection, what constitutes application startup? wthttpd start? user accessing application through webpage?

Also, for the example, I added my own main() where I call run() (per the example). Now if the database connection should run at startup, I decided to move it into main() where it seems more logical. I received out of scope error for session, which I don't understand. Either in run() or in main(), it is still in the same scope. I tried dbo::session, but that doesn't work either. I'm thinking session doesn't work that way, but I can't figure it out.

I also gave the connection it's own simple function, but I don't know what type to return session as from the function. I've tried every data type, but all return an error that it can't change session to the data type. I suppose it really doesn't matter, but I'd like to call the connection in a seperate function or container. Maybe a class, but I can't figure out how a class would work.


Replies (6)

RE: Questions related to Dbo tutorial - Added by IW M about 10 years ago

Also, in the following line:

dbo::ptr userPtr = session.add(user);

userPtr is never referenced again. Why is it even there? Why not just:

dbo::ptr = session.add(user);

RE: Questions related to Dbo tutorial - Added by IW M about 10 years ago

I think some of this is way more complicated than it needs to be, with all these pointers pointing to pointers. Holy whatever batman...

RE: Questions related to Dbo tutorial - Added by Marco M about 10 years ago

Hi,

With the above connection, what constitutes application startup?

wthttpd start? user accessing application through webpage?

The Dbo library is independent from Wt. So, "application startup" has different meanings depending on the context.

If not using Wt, it might mean "once inside main()". If using Wt, it means once per WApplication. This is clearly shown in the many examples that use Dbo and Wt. Did you look at them?

RE: Questions related to Dbo tutorial - Added by IW M about 10 years ago

I've been going through the Dbo tutorial. I haven't found any other Dbo related material aside from the reference docs.

I'll keep looking though; sorry to get ahead of documentation I might be missing.

Thanks!

RE: Questions related to Dbo tutorial - Added by Wim Dumon about 10 years ago

IW M wrote:

Also, in the following line:

dbo::ptr userPtr = session.add(user);

userPtr is never referenced again. Why is it even there? Why not just:

dbo::ptr = session.add(user);

What this says is that if you want to convert a normal C object to a persisted object, you use session.add(), which will return a dbo::ptr to the persisted object that was just added. If you don't need to do anything with the persisted object, simply write session.add(user); and ignore the return value (like you would for other function calls too in nearly all programming languages).

BR,

Wim.

RE: Questions related to Dbo tutorial - Added by IW M about 10 years ago

Thank you for your reply on this Wim. This template resource in C has me looking at everything with confusion; I've never used templates before, let alone pointers to the degree they are used in Wt. Let me throw in one more thing that should reveal the origin of some of my questions: PHP...

But I am clear now. the template nomenclature was clouding everything until I figured out what the <> was for.

Thank you for taking the time; I appreciate it.

    (1-6/6)