Friday, April 26, 2013

Introduction to SQLite

Our Product Development team has started the architecture and design process of an app for Android phones, which uses SQLite as a critical part of the app architecture. Since this was a new technology for both our architect and myself, I decided do some reading on the Web so that I could help him in the detailed architecture and design activities

Basically SQLite is an RDBMS that fits into a small file and exists as an integral part of a client application (unlike other RDMBS that exist as separate "database servers"). At the same time, it supports terabyte-sized databases and gigabyte-sized strings and blobs. The SQLite website calls it "a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine". It also claims that SQLite transactions "are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures"

The website also claims that "SQLite is the most widely deployed SQL database engine in the world". The reason is not hard to see, as "SQLite is popular choice for the database engine in cellphones, PDAs, MP3 players, set-top boxes, and other electronic gadgets". Also, since "it requires no configuration and stores information in ordinary disk files, SQLite is a popular choice as the database to back small to medium-sized websites". SQLite is used by major corporations ranging from Adobe to Mozilla and Airbus to Toshiba

Wikipedia tells me that "D. Richard Hipp designed SQLite in the spring of 2000 while working for General Dynamics on contract with the United States Navy" and also that "SQLite implements most of the SQL-92 standard for SQL but it lacks some features. For example it has partial support for triggers, and it can't write to views". SQLite "is weakly typed in some of the same ways that Perl is: one can insert a string into an integer column (although SQLite will try to convert the string to an integer first, if the column's preferred type is integer)"

Writing PHP code for SQLite is simple, as PHP has the SQLite3 library pre-installed but it has to be enabled by uncommenting two lines in the PHP.ini file:
 extension=php_pdo_sqlite.dll
and
 extension=php_sqlite3.dll

Here are some simple lines of code for manipulating an SQLite database using PHP:
<html>
 <head>
  <title>PHP with SQLite</title>
 </head>
 <body>
  <h2>Testing PHP with SQLite</h2>
<?php
#Create or open SQLite database
$db = new SQLite3('mysqlitedb.db');

#Create table if it doesn't already exist
$db->exec('CREATE TABLE foo (bar STRING PRIMARY KEY)');

#Insert row in table or replace existing row
$db->exec("INSERT OR REPLACE INTO foo (bar) VALUES ('This is a test')");

#Read data from table and display it
$result = $db->query('SELECT bar FROM foo');
while ($row = $result->fetchArray()) {
print ("Value of <i>bar</i> in table <i>foo</i>: " . $row["bar"] . "<br>");
}
?>
  <br>
  <a href="index.php">Back</a>
 </body>
</html>

Wednesday, April 17, 2013

What is Software Architecture?

Today the architect in my team asked for my help in documenting the architecture of a new application. Since my experience of software architecture (or what I understood by that term) was so far restricted to participation in design discussions and creation of functional diagrams (System Overview) and technical diagrams (Database Design), I decided to understand what Software Architecture actually means. So I read some articles and blogs on the Web and noted down some of the interesting things they had to say (links embedded in this post, copyrights hereby acknowledged)

According to an article on MSDN, "Software application architecture is the process of defining a structured solution that meets all of the technical and operational requirements, while optimizing common quality attributes such as performance, security, and manageability. It involves a series of decisions based on a wide range of factors, and each of these decisions can have considerable impact on the quality, performance, maintainability, and overall success of the application."

In this definition of software architecture, Microsoft mentions both technical and operational requirements. But some authors, such as Patrick Kalkman in a Software Architecture Design article on CodeProject, aver that software architecture should focus on the non-functional requirements of the stakeholders, instead of being based on purely technical motives

An article on IBM developerWorks defines software architecture as per the IEEE Standard 1471-2000, the IEEE Recommended Practice for Architectural Description of Software-Intensive Systems, commonly  referred to as IEEE 1471. Thus "Architecture is the fundamental organization of a system embodied in its components, their relationships to each other, and to the environment, and the principles guiding its design and evolution." [IEEE 1471]

As per the IBM article, the standard also defines the following terms related to this definition:
  • A system is a collection of components organized to accomplish a specific function or set of functions. The term system encompasses individual applications, systems in the traditional sense, subsystems, systems of systems, product lines, product families, whole enterprises, and other aggregations of interest. A system exists to fulfill one or more missions in its environment. [IEEE 1471]
  • The environment, or context, determines the setting and circumstances of developmental, operational, political, and other influences upon that system. [IEEE 1471]
  • A mission is a use or operation for which a system is intended by one or more stakeholders to meet some set of objectives. [IEEE 1471]
  • A stakeholder is an individual, team, or organization (or classes thereof) with interests in, or concerns relative to, a system. [IEEE 1471]

The IBM article further lists the core characteristics of software architecture as follows:
  • An architecture defines structure
  • An architecture defines behavior
  • An architecture focuses on significant elements
  • An architecture balances stakeholder needs
  • An architecture embodies decisions based on rationale
  • An architecture may conform to an architectural style
  • An architecture is influenced by its environment
  • An architecture influences team structure
  • An architecture is present in every system
  • An architecture has a particular scope

Finally, going back to the first line of this post, you may want to ask if the "architect" in my team is really one, or just a senior software developer who is more involved than other team members in the design process. An article by Simon Brown offers the answer to this question.