Tuesday, October 29, 2013

Integrate SQLite with Visual C++

MySQL, SQL Server and Oracle are the generally used database systems. But with the arrival of embedded and mobile devices, SQLite has become very useful. When you are doing a project using C or C++, SQLite will be the most suitable option according to the scale of your project. SQLite is a light weight database system. When I tried to integrate SQLite into my Visual C++ project, I realize that there is no proper documentation that make the developer's life easier. So I am going to explain my experience.

First download SQLite from the developer's web site. You have to download 
  • sqlite-shell-win32-x86-3080100.zip  
  • sqlite-dll-win32-x86-3080100.zip from the Precompiled Binaries for Windows section. 
  • And sqlite-amalgamation-3080100.zip file from the same site.


Then extract all the zip files to one folder. Lets assume that folder is "C:\SQLite". 

Now add the path of that folder into the PATH variable of your computer.(Same procedure as you do it in Java jdk.)

Now open the Visual Studio Command Prompt which I mentioned in this post. Then type below command and press enter. This will create sqlite3 library file.
lib /DEF:"C:\SQLite\sqlite3.def" /OUT:"C:\SQLite\sqlite3.lib"

Now after that open your Visual C++ project using Visual Studio IDE. Then write click your project and goto Properties.

Then following window will appear.


Now go to the C/C++ section from the left tab. When selecting that, the right tab will change. Now add the path of your SQLite folder into the "Additional Include Directories".

Then go to the General section of the Linker from the left tab.(Linker -> General). Now again add the same path to the "Additional Library Directories".

Finally go to the Input sub section of the Linker (Linker -> Input) and add "sqlite3.lib" in to the Additional Dependencies. Then press OK.

Now you are done and you can do your coding.

First include the sqlite3.h header file using #include <sqlite3.h> code.

Then do your coding. Below code is extracted from this tutorial. It just opens and connects to a new database.

#include <stdio.h>
#include <sqlite3.h>

int main(int args, char* argv[]){
    sqlite *db;
    char *zErrMsg = 0;
    int rc;  
    rc = sqlite3_open("database_1.db", &db);
    if(rc){
      printf("Can't open databse: %s\n", sqlite3_errmsg(db));
      exit(0);
    }else{
      printf("Opened database successfully\n");
    }
    sqlite3_close(db);
}

Happy Coding! :)

Monday, October 28, 2013

How to read Research Papers efficiently

Reading a Research paper is a really painful thing for most of the people. Sometimes we have to read few research papers within few hours/days. But some people take a whole day to read a single research paper. So lets see if there is any method do read a research paper quickly.


Most research papers contains two columns. Because that column width is comfortable to the human eye. Majority of the people read paper by reading words one by one. That is the most time consuming thing. So try to read a chunk of three words at once. This will be difficult at your first run. So keep practice. Later you'll save a lot of time when reading research paper.

The second method is avoiding the movement of your eye. You can concentrate your eye on the center of a line. Any avoid the leftmost and rightmost words. Read only middle words. That won't affect the meaning of the sentence. You can get the meaning of that sentence without reading the leftmost and rightmost words and it will save some time.

So aggregating these two methods, I have posted a photo below. You can understand using it.

    
You will have to practice this methods to get the advantage of it. With this method you will not grab the 100% of the contents of the research paper. But this method will give you a clear idea of the research paper and its relatedness to your research quickly. Good luck with your readings.!

Thursday, October 24, 2013

Build your solution using Visual Studio Command Prompt

There are some solutions which generated automatically but with a large content. Also there are some buggy Visual Studio versions which are lagging and becomes non-responding while opening and building a comparatively larger solutions.

When I was building OpenCV and QT for my University Final year project, I faced same situation. (I will post a separate article about this OpenCV building process.) My Visual Studio version seems buggy and I didn't have enough time to re-install it. When I tried to open the OpenCV solution using Visual Studio IDE, it becomes non-responding. So I tried the Visual Studio Command Prompt.

Visual Studio Command Prompt

You can open Visual Studio Command Prompt using Visual Studio Tools in the Visual Studio in Start Menu. Then you have to execute just one command. It is simple.

MSBuild D:\Project\YourSolution.sln /p:Configuration=Release 

Replace the "D:\Project\YourSolution.sln" with the location of your solution. Execution will take some time according to the scale of your project. After building using above command, replace "Release" with "Debug" if you want to build your solution for the debug also.

Hope my post will helpful! :)

Thursday, October 17, 2013

Bypass read only permission in ubuntu recovery mode



While I was doing some experiments, I changed the "fstab" file in "etc" folder in ubuntu file system. That file is normally read only and it is related to the mounting process of partitions of the disks. I changed the read only status of a partition to read+write permission status. Consider that when you change that file DON'T restart computer without re-changing that file. But unfortunately I forgot the thing that I changed that file and after some other work, I restarted my computer.:(

So I couldn't boot my Ubuntu because of the misbehavior of the permissions of the partitions. So the simplest solution which comes in to my mind is to change the fstab file again to its original status. So I tried the recover mode. But later I figured that I can't change that file even in the root user because of the read only status of that file. Previously I changed that permission with some GUI method. So I couldn't use it with the terminal.

So I worked around with the recovery mode and found that we can edit the GRUB commands. For that you have to press "e" at the grub menu. Then it will display the grub commands. At that command list you'll be able to find "ro" in lower command. Change that to "rw". Then press F10 to boot using this changes. Then it will load the recover terminal. Now you can edit any read only file using vi editor. If you are not familiar with vi command refer some online tutorials.:)


Friday, October 4, 2013

Build a Network Packet Capture Software

When I doing Computer Security module in the 3rd year of my degree, I had to develop a Network security module. For that I had to capture some network data packets and analyse them. I was in a rush and I needed to use a library to capture data packets. So I spent some time on google to find a suitable library.

Then I found JPCap library. It is a network packet capture library.

Its website describes its usage with this..

The jpcap distribution includes both
  • A tool for real-time network traffic capture and analysis
  • An API for developing packet capture applications in JavaThe jpcap distribution includes both
    • A tool for real-time network traffic capture and analysis
    • An API for developing packet capture applications in Java


JPCap will be useful for you too someday. You can find more details on JPCap web site. "http://jpcap.sourceforge.net/"

Thanks!

Using Facade Design Pattern

When I doing my internship I came across a project which used Facade Design Pattern. So now I'm going to explain my experience with Facade Design pattern. This post will explain how to use Facade design pattern in simple terms.

Facade design pattern is not a harder pattern. If you are familiar with abstraction and information hiding you can understand it easily. First lets discuss what the meaning of information hiding. Encapsulation is a basic principle of OOP. When we using encapsulation we hide internal properties of an object. Simply we make the attributes of the object private and allow users to get and set their values through getter and setter methods. So the attribute is hidden from you. You can't directly refer that attribute by calling object.attribute (ex: human,name). You have to use human.getName() method to get name of that human object and human.setName("his name") method to set the name of that human object. That is the basic idea of information hiding. Abstraction is also bit similar to information hiding. We use abstraction to hide implementation details. As an example if we call the method car.drive(), that car will drive. But the user does not how the driving process happened. He only know that he called the drive method of that car object, and now the car is driving.

Facade design pattern is the next step to information hiding and abstraction. If you need a combination of few objects to get some work done, you can use Facade pattern to hide that combination information from the user. Think the user gives a command like build a car object. ClientHandler class is the one which handles user request. Building a car is a very complex thing. You need combination of several objects to get that car built. There are several departments in a car factory. Like Building engine and stuff, Building chassis of the car, building tires, assembling department and painting department. So at the ClientHandler class, if you call all these department objects and do the car building, that will be a mess. And that will expose the internal implementation details to the user.
So we introduce a facade class just after the ClientHandler class. In that facade class we can write a method called buildCar() and that will arrange all the department objects and build the car. So the ClientHandler only needs to call buildCar() method of the Facade class. So all the combination and implementation details are hidden from the ClientHandler class.




Hope you got an idea on the Facade Design Pattern and how to use the Facade Design Pattern. What I want with this blog to help my readers to describe complex thing in simple term. There are lots of articles on these topics. But there are not much easier to learn to a beginner. So I want to share my experience with this blog.