Thursday, February 12, 2015

Library Management System: Database Project - Part V - Finalize Database

  Library Management System for Imaginary University
  2nd year Database Project

In order to maximize the use of system resources to perform work as efficiently and rapidly as possible the views and indices to be used were confirmed and some of the views were decided to materialize.

In the application a user can search a book based on its authors, title and subject as well as ISBN number. Therefore by creating indices on tilte, authors and subjects the database can access relevant entries more efficiently. Since the table book_details is not updated frequently this will not cause for any low performance of the database.

create index book_title on book_details(title);
create index book_publisher on book_details(publisher);
create index book_category on book_details(category);

create index cd_title on cd_details(title);
create index cd_publisher on cd_details(publisher);
create index cd_category on cd_details(category);

create index member_index on borrows(member_index);

According to the design of our database it was required to join several tables in order to fulfill search requests. For example when finding a book by its ISBN number we happened to join book_details table with authors table to get details of the book. In addition, to find the availability of that book it was necessary to join item table and book table with previous tables making total number of tables to be joined is four. Searching a book is one of main functionalities and that is done frequently, joining tables at each search is highly expensive execution. Therefore it was more convenient to make a view joining necessary tables as follows and materialize the view since it is not updated very frequently.

CREATE VIEW bookSearch AS SELECT, bd.ISBN, bd.title, bd.edition, bd.publisher, bd.category, authors.author_name_1, authors.author_name_2, authors.author_name_3, items.borrowed
FROM items, books, authors, book_details AS bd
WHERE = books.item_id
AND books.ISBN = bd.ISBN
AND authors.ISBN = bd.ISBN;

Similarly a view to read data in joined tables, item, cd and cd_details was created

CREATE VIEW cdSearch AS SELECT, cd.ISSN, cd.title, cd.edition, cd.publisher, cd.category,items.borrowed
FROM items, cds,cd_details AS cd
WHERE = cds.item_id
AND cds.ISSN = cd.ISSN ;

Following views were created to search member details efficiently

CREATE VIEW memberSearch AS SELECT s.student_index, m.first_name, m.last_name,,
PASSWORD , s.batch, m.department, s.registered_date, m.number_of_books_allowed, s.total_fine
FROM students AS s, members AS m
WHERE s.student_index = m.member_index;

CREATE VIEW staffSearch AS SELECT s.staff_index, m.first_name, m.last_name,,
PASSWORD ,s.position, m.department, s.year_of_appoinment, m.number_of_books_allowed
FROM staff AS s, members AS m
WHERE s.staff_index = m.member_index;

To ensure the persistence and security of data backup capabilities were added to the software.

Book Search Window

Wednesday, February 11, 2015

Library Management System: Database Project - Part IV - Database Implementation

  Library Management System for Imaginary University
  2nd year Database Project

Data Definition Language (DDL) of the database.

create table items
     id                  INT PRIMARY KEY,
     borrowed            boolean,
     received_as         varchar(50)    
create table book_details
     ISBN                varchar(15) PRIMARY KEY,
     title               varchar(50) not null,
     edition             varchar(15),
     publisher           varchar(50),
     category            varchar(50),
     price               float(7,2)
create table books
     item_id         int PRIMARY KEY,
     ISBN            varchar(15) ,   
     foreign key (item_id) references items(id),
     foreign key (ISBN) references book_details(ISBN)

create table cd_details
     ISSN                 varchar(15) PRIMARY KEY,
     title                varchar(50) not null,
     edition              varchar(15),
     publisher            varchar(50),
     category             varchar(50),
     price                float(7,2)

create table cds
     item_id           int PRIMARY KEY,
     ISSN              varchar(15) ,
     foreign key (item_id) references items(id),
     foreign key (ISSN) references cd_details(ISSN)

create table members
     member_index       varchar(10)  PRIMARY KEY,
     first_name         varchar(50) not null,
     last_name          varchar(50) not null,
     department         varchar(20) not null,
     password           varchar(15) not null,
     email              varchar(50),
     number_of_books_allowed int

create table students
     student_index      varchar(10)  PRIMARY KEY,
     batch              varchar(5) not null,
     total_fine         int,
     registered_date   date,
     foreign key (student_index) references members(member_index)
create table staff
     staff_index           varchar(10)  PRIMARY KEY,
     year_of_appoinment    DATE,
     position              varchar(20) not null,
     foreign key (staff_index) references members(member_index)
create table authors
    ISBN                  varchar(15)  PRIMARY KEY,
    author_name_1         varchar(20) not null,
    author_name_2         varchar(20),
    author_name_3         varchar(20),
    author_name_4         varchar(20),
    foreign key (ISBN)    references book_details(ISBN)

create table borrows
     member_index         varchar(10),
     item_id              int,
     borrowed_date        DATE not null,
     fine                 float(7,2),
     remarks              varchar(50),
     foreign key (member_index) references members(member_index),
     foreign key (item_id) references items(id),
     primary key (member_index,item_id)
create table locations
     id                INT PRIMARY KEY,
     shelve_ID         varchar(6),
     row_number        int,
     section           varchar(15) not null
create table item_is_at
     ISBN             varchar(15) PRIMARY KEY,
     location_id      int,   
     foreign key (location_id) references locations(id),
     foreign key (ISBN) references book_details(ISBN)
create table operator
    (id               varchar(10) PRIMARY KEY,
     username         varchar(50) not null,
     password         varchar(15) not null,
     email            Varchar(128) not null,
     position         varchar(64)    

Library Management System: Database Project - Part III - Database Design

  Library Management System for Imaginary University
  2nd year Database Project

There are Four main entities

Item : a book or as CD which can be borrow from the library
Member : a registered member of the library who will be a student or a staff member
Location : the physical location where an item is stored in the library
Operator : a library staff member who will interact with members of the library. That is they will add/update data about members, transactions and items in the library

Entity Relationship Diagram (ER Diagram)

ER diagram

There can be many copies of the same item (Book or CD). However since we need to identify each item separately so that each of them are given a unique id which is the 'item_id'.
Storing common details of the same copies of items make redundancy, the details of items are decomposed into separate tables named 'book_details' and 'CD_details'.

A member can borrow four books (or CDs) at a time and an item can be borrowed by only one member at a time. Therefore the relation between items and members is many to one.

The relationship, borrows, will record details of a transaction and stored as the history of each transaction. The attribute, returned date of the relationship borrows will be null until the item is returned.

Books and CD’s are stored physically in the place designated by the location. A location can be uniquely identified by the location_id which includes shelf number, row number and section number. Therefore the combination of those three attributes will be the primary key for the entity, location_id. However since there can be about 10-20 books in a section of a shelf the relationship, item_location is many to one from item to location.

Operator entity is used in authenticating operators when using the system, which is essential to confirm security of the system. That does not have any relationship with other entities.

All the entities are checked and confirmed to be normalized in the first and third normal forms.

Database Schema

Database schema

Library Management System: Database Project - Part II - Functional & Non Functional Requirements

  Library Management System for Imaginary University
  2nd year Database Project

Functional Requirements

  • Add/delete/update details of a member for the library staff.
  • Add/remove/change privileges of library staff to access the system
  • All functionalities of an operator ( mentioned below )
  • Add/delete/update book details (location)
  • Issue/accept lent books
  • Issue fine receipts
  • Search books (for location, availability, other related books, etc.)
  • Check user history
  •  only allowed to view data about resources available in the library

Non Functional Requirements

Data validation
Data validation is having valid data for a given type of variable. Data must be validated to ensure the consistency of data.

The security to the data base from unauthorized access is prevented by proper authentication giving access privileges for users. In addition security from SQL injection is prevented at the implementation using HTML methods and php (eg: using php function like mysql_real_escape_string(trim($variable) )

Both the throughput and low response time is achieved by making proper views and indices. They are explained later in the report.

User friendly interfaces are provided. Also in order to prevent mistakes from users proper warnings and alerts are implemented.

Library Management System: Database Project - Part I - Introduction

  Library Management System for Imaginary University
  2nd year Database Project

Database management is a wide area of computer science which is essential in most of the applications in order to store and handle data proper and efficient way. Library management system is one of a most frequently used application of database management systems where there is a chunk of information to store and record daily.


University of ABC is a imaginary university of about 12000 students and 1000 of staff. The library system of the university facilitates all students, academic and non academic staff by providing access to the library. Anyone of the university can read books or other documents at the library, but in order to borrow them one should register and get the membership. The membership is valid only for a year and that should be updated afterwards. After getting the membership, a member can borrow 4 books at a time and maximum burrowed period is 2 weeks. Users must return books on or before due date, otherwise they are fined. The fine is rs.5.00 per book for the first week and rs.10.00 per day for further delays. In order to facilitate its users to the fullest University of ABC has decided to keep a database and automate the library system.


Main purpose of managing a database system is to facilitate the users of the library in an efficient way. There are three main requirements of the University for the library system.
  • Store information about books and users
  • Search books
  • Reporting member profiles

Monday, February 9, 2015

Powering my home by Solar Energy

I am interesting in renewable energy area from my childhood. Sri Lankan government introduced grid solar power system for residential few years ago. I was able to install grid solar power system at my home in 2014  with my uncle's help who has great knowledge about electric systems.

Mainly there are two types of Solar Systems i.e off grid and grid tied.

DC off grid system

rarely use [most electric components are capable only for Alternative Current (AC)]


AC off grid system

Inverter converts Direct Current (DC) to Alternative Current (AC). You can use a generator if you want to get power when battery bank is dead.

grid system with batteries

With a Battery bank you can have current to your home when distribution line power cut. you cant do that without a battery bank. because extra power should be store somewhere (in a battery bank).

grid system with batteries

I am using this system (without a battery bank). At Day time we are using the solar power and rest sends to the distribution line (export). If the solar power is low then get the current from normal distribution line (import).  

Lets say you have exported 300 units at the end of month and imported 400 units, so you have to only pay for 100 units. Otherwise (export = 400 , import = 300) then you have extra 100 units in your hand and you can use that extra units at other circumstances (some months have rainy season so import units can be higher)

There are 24 solar panels at my house's roof, each panel produces 185W to power up my home by solar energy. setup is not much difficult. It is similar to normal battery setup. Lets say you have two packs of 12 batteries. 12 batteries of each pack is connected series. 2 Packs gives powers separately.

grid solar system circuit diagram at my home

Be carefull
There are two types of solar panels in market i.e. monocrystalline and polycrystalline. Make sure to buy monocrystalline solar panels though it has high initial cost.

Currently I am getting 20 units average (20 kwh) for a good sunny day. For a rainy day its reduced to 10 units.

In my home roof is faced to East and West. For this kind of scenario best way is to have two sides are separately to produce power. Morning to 12'o clock Right hand side produce much energy than left also 12'o clock noon to Evening left produce much than right. If we put all sets as one it will drop the production.


Lets say Morning to 12'o clock Right hand side produce average of 1900 W and left is 1000 W, total production is 2900 W (1900+1000).

if we set both side as one, total production will be reduced to the minimum side

production = minimum {Left , Right} * 2 = 1000 W * 2= 2000 W