GSoC 2020 with KDE
The coding period began on June 1st. As listed in the previous post, the plan for the first phase is to complete the following tasks:
- A script that generates the SQLite DB using blz datafile downloaded from the Deutsche Bundesbank
- Modifications in the CMake build system to call this script at build time.
- Replacing the part of code that uses the text datafile with the code that reads from this database.
- Updating tests, documentations and benchmark to work with the new database.
- Modifying the command-line tool to enable support for user-supplied database.
The ticked tasks have been completed till now.
This week, my main aim was to link the SQLite library to use it in the code and start replacing some of the code that does reading from the text file.
Since, I did not have any previous experience with CMake
build system, the linking part was a bit of a work. I carefully studied the existing build system to
figure out how to achieve this. I looked up some of the examples on the internet and tried to fill in the
gaps from my intuition.
Finally, victory! The CMake command ran successfully and the test source file executed the SQLite APIs.
With that done, now I was ready to write some C++.
For this, I established the following flow. When the constructor is called, it checks the bankdata_dir path to see if the database is present. If it is, it calls the method
with the filename. This method establishes the connection with the database and executes a SELECT query using sqlite3_exec().
Now, there was a problem here.
The sqlite3_exec() calls a static function at every row of the result obtained from the query passed. But, I needed to use the results to insert new Record in the std::map data, which will be used for all the checking and finding of bank accounts. But since, these are members of the class, they cannot be accessed through a static function.
After spending a bit of time searching for a solution, I stumbled upon a way that was helpful. The trick was to pass the pointer to the current object into the static callback function which will cast it into the class pointer and call the required non-static method. So, the callback function looks like this:
The method AccountNumberCheck::readFile() used to read from the text file; I modified it to read from the database.
Here, the isEntryValidToday() method is used to compare the value of valid_upto field with today’s date.
The SELECT query that I passed, extracts the date in the format YYYY-MM-DD so to compare it with today, I formatted today’s date in the same format, after which they could be compared simply using strcmp().
After a few more additions and changes, the code was successfully reading from the database and working well with the tests. However, the CTest benchmark fails due to incompatibility with the new code. So, next week’s plan is to fix this and make changes to the command-line tool to enable support for user-supplied database.
See you in the next post.