Up till now, I’ve spent months of quality time with Wt and gotten quite familiar with it. It has taken care a lot of dirty things for me in the background and at the same time, taught me a lot more about programming in C++.

Compromises

The application I’m working on is far from being stable and optimized. There are compromises which was necessary in the mean time. For example, the Facebook oauth authentication which I will probably fix when I have the time. More importantly, is the dual entry point of the WApplication. This is due to the Google Drive service which uses an oauth authentication. I will probably need to implement something similar to Facebook/Google Service in the near future to fix this extra entryPoint. FYI, an application should remain in a single session. Switching between entryPoint will destroy the previous session. As a result, a browser back button might cause the application to crash. handlePathChange() does not work between sessions as well.

In my application, I had to bring the user session from my first entryPoint to the second entryPoint. This is done by creating a method to return the session from the entryPoint 1 and initializing it in entryPoint 2.

Bye bye JSON, Hello Dbo

During my internship, I worked with JSON for some time. I’ve even played with boost::property_tree to create or modify JSON objects. Now, it’s time to flush them down the drain. I am now using DBO as a method of storing information, which … is so much easier! (Setting up the user session was a pain in the head though)

The things I found useful with Wt::Dbo are as follows:-

  1. Getting the user dbo pointer.

Most apps will definitely have a user table. After correctly setting up the session, we can obtain the pointer to the user by
dbo::ptr user = sessiontest->user();
The pointer will allow reading/edit of the user column data.

user->_name; //returns the _name of the 'user'

user.modify()->_name = "John Doe"; //modifies the name to John Doe
2. Iterating through dbo queries
typedef Wt::Dbo::collection<Wt::Dbo::ptr Projects;
Projects projects_ = sessiontest->find("where user_id = ? order by last_modified desc").bind(user.id());

for(Projects::const_iterator i=projects_.begin(); i!=projects_.end();i++){
std::string title, fileID;
title=(i)->_title;
fileID=(
i)->_fileID;
}

where user_id = ?”  is to select the user_id with the binded parameter (in this case it’s user.id())
order by last_modified desc” actually sorts the collection with its last_modified data in descending order

With the use of Dbo, my code has gotten much simpler and readable. In conclusion, it is great knowing Wt::Dbo and SQL database.

 


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.