Professional Documents
Culture Documents
SQ Lite
SQ Lite
Table of contents
SNO Name Of Content
3 Features Of SQLite
4 Disadvantages Of SQLite
5 Architecture Of SQLite
6 Examples To Do
History
• SQlite is an open source embedded database. The original
implementation was designed by D. Richard Hipp.
The SQL Command Processor will read the SQL Commands from
Interface and it will forward that SQL Query Strings to the
Tokenizer of SQL Compiler
This Virtual Machine will read the code what ever the code generated by the code
generator of the SQL Compiler
Architecture of Sqlite
When a string containing SQL statements is to be executed, the
interface passes that string to the tokenizer. The job of the
tokenizer is to break the original string up into tokens and pass
those tokens one by one to the parser. The tokenizer is hand-
coded in C in the file tokenize.c.
the code generator to produce virtual machine code that will do the work that the SQL
statements request. Ex: vacuum.c and where.c in which where.c handles code generation
for WHERE clauses on SELECT, UPDATE and DELETE statements
Architecture of Sqlite
An SQLite database is maintained on disk using a B-tree
implementation found in the btree.c source file. A separate B-tree
is used for each table and index in the database. All B-trees are
stored in the same disk file. Details of the file format are recorded
in a large comment at the beginning of btree.c.
In order to provide portability between POSIX (Portable Operating System Interface (for
Unix))and Win32 operating systems, SQLite uses an abstraction layer to interface with the
operating system. The interface to the OS abstraction layer is defined in os.h.
Architecture of Sqlite
Memory allocation and ceaseless string comparison routines are
located in util.c
If you count regression test scripts, more than half the total code
base of SQLite is devoted to testing. There are many assert()
statements in the main code files
Examples To Do
Let us do some coding
EX:mydb=openOrCreateDatabase("DatabaseName5",
MODE_PRIVATE,null);
//mydb is sqlite object name .
//DatabaseName5 is nothing but database name
//MODE_PRIVATE is permissions of a table accessing
Examples To Do
Let us do some coding
Create:
mydb.execSQL("CREATE TABLE IF NOT EXISTS “
+TableName+" (ColumnName DataType);");
Alter:
ALTER TABLE TableName RENAME TO new-table-name
Drop:
DROP TABLE TableName
(View Source)
Examples To Do
Let us do some coding
Select:
Cursor c=mydb.rawQuery("SELECT * FROM "+TableName+"
where Name='"+city+"'",null);
Insert:
mydb.execSQL("INSERT INTO "+TableName+“ (Name, Area)“ +
"VALUES ('RedFort','40.8 acres‘);");
Delete:
mydb.execSQL(“Delete"+TableName);
(View Source)
SQLite OpenHelper
• SQLite OpenHelper is a class to manage database creation
and version management.
• This class take care of opening the database if it exists,
creating it if it does not, and upgrading it as necessary.
• This is for creating db “onCreate(SQLiteDataBase)”.
• when the database needs to be upgraded
“onUpgrade (SQLiteDataBase db, int oldVersion, int
newVersion)”.
• when the database has been opened
“onOpen (SQLiteDataBase db)”.
Examples To Do
The below are few kind of applications that we can develop using Sqlite in Android.