0% found this document useful (0 votes)
107 views

SQLite in Android

SQLite is an embedded, lightweight, relational database included in the Android framework that provides persistent data storage. It uses SQL syntax and provides functions to execute queries, insert, update, and delete records. Queries return a Cursor object that can iterate through result rows and access column values. ContentValues stores a set of column-value pairs to insert into a table.

Uploaded by

Ha Re
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

SQLite in Android

SQLite is an embedded, lightweight, relational database included in the Android framework that provides persistent data storage. It uses SQL syntax and provides functions to execute queries, insert, update, and delete records. Queries return a Cursor object that can iterate through result rows and access column values. ContentValues stores a set of column-value pairs to insert into a table.

Uploaded by

Ha Re
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SQLite in Android

BY BEZAWIT E.
Some database software
• Oracle
• Microsoft
SQLServer(powerful)
Access(simple)
• PostgreSQL
– powerful/complex free open-source database system
• SQLite
– transportable, lightweight free open-source database system
• MySQL
– simple free open-source database system
– many servers run “LAMP” (Linux,Apache,MySQL,andPHP)
–Wikipedia is run on PHP and MySQL
Android includes SQLite
SQLite is a library, runs in the app’s process
SQLite is an embedded, relational database management system (RDBMS).
SQL • Structured Query Language (SQL): a language for searching and updating a database
SQLite is a lightweight, embedded relational database management system
◦ included as part of the Android framework
◦ provides a mechanism for implementing organized persistent data storage for Android applications.

Not a client/server architecture


◦ Accessed via function calls from the application
Cont.
Basic SQL operations
◦ SELECT SELECT <list of columns> FROM <table> WHERE <where clause> [ORDER BY <column> [ASC or
DESC]] [LIMIT <number>];
◦ INSERT INTO <table> (<list of columns>) VALUES (<list of values>);
◦ UPDATE <table> SET <column1> = <value1>, <column2> = <value2>, … <columnn> = <valuen> WHERE
<where clause>;
◦ DELETE FROM <table> WHERE <where clause>;
android.database.sqlite - Classes
SQLiteCloseable - An object created from a SQLiteDatabase that can be closed. 
SQLiteCursor - A Cursor implementation that exposes results from a query on a SQLiteDatabase. 
SQLiteDatabase - Exposes methods to manage a SQLite database. 
SQLiteOpenHelper - A helper class to manage database creation and version management. 
SQLiteProgram -  A base class for compiled SQLite programs. 
SQLiteQuery - A SQLite program that represents a query that reads the resulting rows into a
CursorWindow. 
SQLiteQueryBuilder - a convenience class that helps build SQL queries to be sent to
SQLiteDatabase objects. 
SQLiteStatement - A pre-compiled statement against a SQLiteDatabase that can be reused. 
Cursor
Cursor: result of a query
A class provided specifically to provide access to the results of a database query
Cursor lets you iterate through row results one at a time
provides random read-write access to the result set returned by a database query.
Cursor cursor = db.rawQuery("SELECT * FROM students");
cursor.moveToFirst();
do { int id = cursor.getInt(cursor.getColumnIndex("id"));
String email = cursor.getString(
cursor.getColumnIndex("email")); ... }
while (cursor.moveToNext());
cursor.close();
Cont.
getString(int columnIndex) Returns the value of the requested column as a String.
close() Closes the Cursor, releasing all of its resources and making it completely invalid.
getInt(int columnIndex) Returns the value of the requested column as an int.
getColumnIndex(String columnName) Returns the zero-based index for the given column name,
or -1 if the column doesn't exist.
moveToFirst() Move the cursor to the first row.
moveToLast() Move the cursor to the last row.
moveToNext() Move the cursor to the next row.
Some key methods
close() – Releases all resources used by the cursor and closes it.
getCount() – Returns the number of rows contained within the result set.
moveToFirst() – Moves to the first row within the result set.
moveToLast() – Moves to the last row in the result set.
moveToNext() – Moves to the next row in the result set.
move() – Moves by a specified offset from the current position in the result set.
ContentValues
android.content.ContentValues
• This class is used to store a set of values.

put(String key, Byte value) --- Adds a value to the set.


put(String key, Integer value) ---- Adds a value to the set.
put(String key, String value) ----- Adds a value to the set.
remove(String key) -------- Remove a single value.

You might also like